Skip to content

Commit 8d10a9e

Browse files
authored
GODRIVER-2978 Automate syncing code between Go driver v1 and v2 (#1391)
1 parent 1e41b58 commit 8d10a9e

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

.github/workflows/sync.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Sync
2+
on:
3+
push:
4+
branches:
5+
- v1
6+
7+
jobs:
8+
sync-branches:
9+
runs-on: ubuntu-latest
10+
name: Syncing branches
11+
permissions:
12+
pull-requests: write
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Create a sync PR
17+
run: |
18+
git config --global github.user $GITHUB_ACTOR
19+
git config user.email [email protected]
20+
git config user.name $GITHUB_ACTOR
21+
export AUTH_TOKEN=${{secrets.GITHUB_TOKEN}}
22+
sha=$(git rev-parse HEAD)
23+
bash ./etc/cherry-picker.sh $sha

docs/CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ If any tests do not pass, or relevant tests are not included, the patch will not
2929

3030
If you are working on a bug or feature listed in Jira, please include the ticket number prefixed with GODRIVER in the commit message and GitHub pull request title, (e.g. GODRIVER-123). For the patch commit message itself, please follow the [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/) guide.
3131

32+
### Cherry-picking between branches
33+
34+
You must first install the `gh` cli (`brew install gh`), then set your GitHub username:
35+
36+
```bash
37+
git config --global github.user <github_handle>
38+
```
39+
40+
If a Pull Request needs to be cherry-picked to a new branch, get the sha of the commit in the base branch, and then run
41+
42+
```bash
43+
bash etc/cherry-picker.sh <sha>
44+
```
45+
46+
The cherry-picker script is configured to use `v1` as the base branch and `master` as the target branch.
47+
It will create a new checkout in a temp dir, create a new branch, perform the cherry-pick, and then
48+
prompt before creating a PR to the target branch.
49+
3250
## Testing / Development
3351

3452
The driver tests can be run against several database configurations. The most simple configuration is a standalone mongod with no auth, no ssl, and no compression. To run these basic driver tests, make sure a standalone MongoDB server instance is running at localhost:27017. To run the tests, you can run `make` (on Windows, run `nmake`). This will run coverage, run go-lint, run go-vet, and build the examples.

etc/cherry-picker.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
set -e
3+
4+
sha=$1
5+
base=v1
6+
target=master
7+
dirname=$(mktemp -d)
8+
user=$(git config github.user)
9+
10+
if [ -z "$user" ]; then
11+
echo "Please set GitHub User"
12+
echo "git config --global github.user <github_handle>"
13+
exit 1
14+
fi
15+
16+
mkdir -p $dirname
17+
if [ -z $AUTH_TOKEN ]; then
18+
git clone [email protected]:mongodb/mongo-go-driver.git $dirname
19+
else
20+
echo "$AUTH_TOKEN" > mytoken.txt
21+
gh auth login --with-token < mytoken.txt
22+
git clone https://github.com/mongodb/mongo-go-driver.git $dirname
23+
fi
24+
25+
cd $dirname
26+
if [ -z $AUTH_TOKEN ]; then
27+
git remote add $user [email protected]:$user/mongo-go-driver.git
28+
else
29+
git remote add $user https://$user:${AUTH_TOKEN}@github.com/$user/mongo-go-driver.git
30+
fi
31+
32+
gh repo set-default mongodb/mongo-go-driver
33+
branch="cherry-pick-$sha"
34+
head="$user:$branch"
35+
git fetch origin $base
36+
git fetch origin $target
37+
git checkout -b $branch origin/$target
38+
git cherry-pick -x $sha
39+
40+
old_title=$(git --no-pager log -1 --pretty=%B | head -n 1)
41+
ticket=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+).*/\1/')
42+
text=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+) (.*) \(#[0-9]*\)/\2/')
43+
pr_number=$(echo $old_title| sed -r 's/.*(#[0-9]*)\)/\1/')
44+
45+
title="$ticket [$target] $text"
46+
body="Cherry-pick of $pr_number from $base to $target"
47+
48+
echo
49+
echo "Creating PR..."
50+
echo "Title: $title"
51+
echo "Body: $body"
52+
echo "Base: $target"
53+
echo "Head: $head"
54+
echo
55+
56+
if [ -n $GITHUB_ACTOR ]; then
57+
choice=Y
58+
else
59+
read -p 'Push changes? (Y/n) ' choice
60+
fi
61+
62+
if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then
63+
if [ -n $user ]; then
64+
git push $user
65+
fi
66+
gh pr create --title "$title" --base $target --head $head --body "$body"
67+
fi

0 commit comments

Comments
 (0)