Skip to content

Commit

Permalink
Added github action
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Sep 20, 2023
1 parent fc10249 commit 596522b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/sync.yml
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
26 changes: 22 additions & 4 deletions etc/cherry-picker.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash
set -e

sha=$1
base=v1
target=master
dirname="/tmp/go-driver-$(openssl rand -hex 12)"
dirname=$(mktemp -d)
user=$(git config github.user)

if [ -z "$user" ]; then
Expand All @@ -13,9 +14,21 @@ if [ -z "$user" ]; then
fi

mkdir -p $dirname
git clone git@github.com:mongodb/mongo-go-driver.git $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
git remote add $user git@github.com:$user/mongo-go-driver.git
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"
Expand All @@ -40,7 +53,12 @@ echo "Base: $target"
echo "Head: $head"
echo

read -p 'Push changes? (Y/n) ' choice
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
Expand Down

0 comments on commit 596522b

Please sign in to comment.