Skip to content

Commit

Permalink
feat: auto syncing between public and private repo (#615)
Browse files Browse the repository at this point in the history
* chore: Github action to sync

* chore: auto PR Github action to sync between branch

* fix: use personal token to continue trigger workflow

* fix: fix wording

* fix: switch back to omisego instead of boolafish for testing

* refactor: call api directly instead of market place dep

test: tmp change branch

cleanup: remove tmp comment codes

* refactor: remove dep and use GH api in auto-pr

* refactor: use command line instead of market place dep in sync-public-private

* fix: event trigger and step restriction of repo

* fix: auto PR from master instead of testing branch
  • Loading branch information
boolafish authored Apr 15, 2020
1 parent 0a25fcb commit 3c5487c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/auto-pr-for-branch-syncing.yml
Original file line number Diff line number Diff line change
@@ -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}\"}"
18 changes: 18 additions & 0 deletions .github/workflows/dispatch-sync-to-private.yml
Original file line number Diff line number Diff line change
@@ -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 }}"'" }}'
41 changes: 41 additions & 0 deletions .github/workflows/sync-from-public-to-private.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3c5487c

Please sign in to comment.