diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000000..206158be64 --- /dev/null +++ b/.github/workflows/sync.yml @@ -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 diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 18142f55b3..71f0df3446 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -29,6 +29,24 @@ If any tests do not pass, or relevant tests are not included, the patch will not 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. +### Cherry-picking between branches + +You must first install the `gh` cli (`brew install gh`), then set your GitHub username: + +```bash +git config --global github.user +``` + +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 + +```bash +bash etc/cherry-picker.sh +``` + +The cherry-picker script is configured to use `v1` as the base branch and `master` as the target branch. +It will create a new checkout in a temp dir, create a new branch, perform the cherry-pick, and then +prompt before creating a PR to the target branch. + ## Testing / Development 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. diff --git a/etc/cherry-picker.sh b/etc/cherry-picker.sh new file mode 100755 index 0000000000..6d690594a4 --- /dev/null +++ b/etc/cherry-picker.sh @@ -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 " + 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