-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GODRIVER-2978 Automate syncing code between Go driver v1 and v2 (#1391)
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Sync | ||
on: | ||
push: | ||
branches: | ||
- v1 | ||
|
||
jobs: | ||
sync-branches: | ||
runs-on: ubuntu-latest | ||
name: Syncing branches | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Create a sync PR | ||
run: | | ||
git config --global github.user $GITHUB_ACTOR | ||
git config user.email $GITHUB_ACTOR@users.noreply.github.com | ||
git config user.name $GITHUB_ACTOR | ||
export AUTH_TOKEN=${{secrets.GITHUB_TOKEN}} | ||
sha=$(git rev-parse HEAD) | ||
bash ./etc/cherry-picker.sh $sha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
sha=$1 | ||
base=v1 | ||
target=master | ||
dirname=$(mktemp -d) | ||
user=$(git config github.user) | ||
|
||
if [ -z "$user" ]; then | ||
echo "Please set GitHub User" | ||
echo "git config --global github.user <github_handle>" | ||
exit 1 | ||
fi | ||
|
||
mkdir -p $dirname | ||
if [ -z $AUTH_TOKEN ]; then | ||
git clone git@github.com:mongodb/mongo-go-driver.git $dirname | ||
else | ||
echo "$AUTH_TOKEN" > mytoken.txt | ||
gh auth login --with-token < mytoken.txt | ||
git clone https://github.com/mongodb/mongo-go-driver.git $dirname | ||
fi | ||
|
||
cd $dirname | ||
if [ -z $AUTH_TOKEN ]; then | ||
git remote add $user git@github.com:$user/mongo-go-driver.git | ||
else | ||
git remote add $user https://$user:${AUTH_TOKEN}@github.com/$user/mongo-go-driver.git | ||
fi | ||
|
||
gh repo set-default mongodb/mongo-go-driver | ||
branch="cherry-pick-$sha" | ||
head="$user:$branch" | ||
git fetch origin $base | ||
git fetch origin $target | ||
git checkout -b $branch origin/$target | ||
git cherry-pick -x $sha | ||
|
||
old_title=$(git --no-pager log -1 --pretty=%B | head -n 1) | ||
ticket=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+).*/\1/') | ||
text=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+) (.*) \(#[0-9]*\)/\2/') | ||
pr_number=$(echo $old_title| sed -r 's/.*(#[0-9]*)\)/\1/') | ||
|
||
title="$ticket [$target] $text" | ||
body="Cherry-pick of $pr_number from $base to $target" | ||
|
||
echo | ||
echo "Creating PR..." | ||
echo "Title: $title" | ||
echo "Body: $body" | ||
echo "Base: $target" | ||
echo "Head: $head" | ||
echo | ||
|
||
if [ -n $GITHUB_ACTOR ]; then | ||
choice=Y | ||
else | ||
read -p 'Push changes? (Y/n) ' choice | ||
fi | ||
|
||
if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then | ||
if [ -n $user ]; then | ||
git push $user | ||
fi | ||
gh pr create --title "$title" --base $target --head $head --body "$body" | ||
fi |