diff --git a/.github/workflows/auto-pr-for-branch-syncing.yml b/.github/workflows/auto-pr-for-branch-syncing.yml new file mode 100644 index 000000000..a6e5e9b8a --- /dev/null +++ b/.github/workflows/auto-pr-for-branch-syncing.yml @@ -0,0 +1,26 @@ +name: Auto PR for syncing master to master-private + +on: + push: + branches: [master] + +jobs: + auto-pr-for-branch-syncing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Create Pull Request + if: github.repository == 'omisego/plasma-contracts-private' + run: | + set -o xtrace + + readonly FROM_BRANCH="master" + readonly TO_BRANCH="master-private" + readonly TITLE="sync: auto syncing from ${FROM_BRANCH} to ${TO_BRANCH}" + readonly BODY="There is new update in \`${FROM_BRANCH}\`! Time to sync to \`${TO_BRANCH}\`!!" + + curl -X POST "https://api.github.com/repos/omisego/plasma-contracts-private/pulls" \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${{ secrets.HOUSE_KEEPER_BOT_TOKEN }}" \ + --data "{\"title\": \"${TITLE}\", \"head\": \"${FROM_BRANCH}\", \"base\": \"${TO_BRANCH}\", \"body\": \"${BODY}\"}" + diff --git a/.github/workflows/dispatch-sync-to-private.yml b/.github/workflows/dispatch-sync-to-private.yml new file mode 100644 index 000000000..a84ffa06d --- /dev/null +++ b/.github/workflows/dispatch-sync-to-private.yml @@ -0,0 +1,18 @@ +name: Dispatch sync event to plasma-contracts-private + +on: + push: + branches: [master] + +jobs: + dispatch-sync-event: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Repository Dispatch + if: github.repository == 'omisego/plasma-contracts' + run: | + curl -X POST https://api.github.com/repos/omisego/plasma-contracts-private/dispatches \ + -H 'Accept: application/vnd.github.v3+json' \ + -H 'authorization: token '${{ secrets.HOUSE_KEEPER_BOT_TOKEN }}'' \ + --data '{"event_type": "sync-from-public", "client_payload": { "sha": "'"${{ github.sha }}"'" }}' diff --git a/.github/workflows/sync-from-public-to-private.yml b/.github/workflows/sync-from-public-to-private.yml new file mode 100644 index 000000000..6980f4bcf --- /dev/null +++ b/.github/workflows/sync-from-public-to-private.yml @@ -0,0 +1,41 @@ +name: Sync with plasma-contracts + +on: + repository_dispatch: + types: [sync-from-public] + +jobs: + sync-public-repo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # use personal token to continue GH action workflows + # by default GH would not trigger another workflow if it is from GH action token + # see: https://github.com/ad-m/github-push-action/issues/32 + token: ${{ secrets.HOUSE_KEEPER_BOT_TOKEN }} + - name: Event Information + run: | + echo "Syncing with sha '${{ github.event.client_payload.sha }}'" + - name: Sync master branch in between public and private repos + if: github.repository == 'omisego/plasma-contracts-private' + run: | + set -e + set -o xtrace + + # Credit repo-sync/github-sync for the script used in here + # https://github.com/repo-sync/github-sync/blob/520596e97177727db1f2a1de14f4ded905624066/github-sync.sh#L23-L33 + + readonly SOURCE_REPO="omisego/plasma-contracts" + readonly SOURCE_BRANCH="master" + readonly DESTINATION_BRANCH="master" + + echo "Syncing ${DESTINATION_BRANCH} from branch ${SOURCE_BRANCH} of ${SOURCE_REPO}..." + + git remote set-url origin "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" + git remote add tmp_upstream "https://github.com/${SOURCE_REPO}.git" + git fetch tmp_upstream + git remote --verbose + git push origin "refs/remotes/tmp_upstream/${SOURCE_BRANCH}:refs/heads/${DESTINATION_BRANCH}" --force + git remote rm tmp_upstream + git remote --verbose