From c24fb67826837eb48a071e06816138d2cc37123a Mon Sep 17 00:00:00 2001 From: Prakash Surya Date: Wed, 22 Apr 2020 11:40:26 -0700 Subject: [PATCH] Sync "6.0/stage" with "master" via GitHub Actions --- .github/scripts/install-hub.sh | 3 ++ .github/scripts/sync-with-master.sh | 39 ++++++++++++++++++++++++++ .github/workflows/sync-with-master.yml | 21 ++++++++++++++ 3 files changed, 63 insertions(+) create mode 100755 .github/scripts/install-hub.sh create mode 100755 .github/scripts/sync-with-master.sh create mode 100644 .github/workflows/sync-with-master.yml diff --git a/.github/scripts/install-hub.sh b/.github/scripts/install-hub.sh new file mode 100755 index 00000000..5caf70f4 --- /dev/null +++ b/.github/scripts/install-hub.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eux + +curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s v2.14.2 diff --git a/.github/scripts/sync-with-master.sh b/.github/scripts/sync-with-master.sh new file mode 100755 index 00000000..d8e48786 --- /dev/null +++ b/.github/scripts/sync-with-master.sh @@ -0,0 +1,39 @@ +#!/bin/bash -eux + +# +# This variable must be passed into this script. +# +[[ -n "${BRANCH}" ]] || exit 1 + +# +# We need these config parameters set in order to do the git-merge. +# +git config user.name "${GITHUB_ACTOR}" +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + +# +# We need the full git repository history in order to do the git-merge. +# +git fetch --unshallow + +# +# In order to open a pull request, we need to push to a remote branch. +# To avoid conflicting with existing remote branches, we use branches +# within the "sync-with-master" namespace. +# +git checkout -b "sync-with-master/${BRANCH}" "origin/${BRANCH}" +git merge -Xtheirs origin/master +git push -f origin "sync-with-master/${BRANCH}" + +# +# Opening a pull request may fail if there already exists a pull request +# for the branch; e.g. if a previous pull request was previously made, +# but not yet merged by the time we run this "sync" script again. Thus, +# rather than causing the automation to report a failure in this case, +# we swallow the error and report success. +# +# Additionally, as along as the git branch was properly updated (via the +# "git push" above), the existing PR will have been updated as well, so +# the "hub" command is unnecessary (hence ignoring the error). +# +git log -1 --format=%B | hub pull-request -F - -b "${BRANCH}" || true diff --git a/.github/workflows/sync-with-master.yml b/.github/workflows/sync-with-master.yml new file mode 100644 index 00000000..5d98d1d1 --- /dev/null +++ b/.github/workflows/sync-with-master.yml @@ -0,0 +1,21 @@ +on: + push: + branches: + - master + schedule: + - cron: '0 0 * * *' + +jobs: + sync: + strategy: + matrix: + branch: + - 6.0/stage + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - run: ./.github/scripts/install-hub.sh + - run: ./.github/scripts/sync-with-master.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: ${{ matrix.branch }}