From 07c40cf1500375d6768eeded70ecca31cef1dbb8 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Wed, 31 Jan 2024 18:02:44 -0500 Subject: [PATCH] Add GitHub Action to open PRs against staging with main's latest changes --- .../keep-staging-up-to-date-with-main.yml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/keep-staging-up-to-date-with-main.yml diff --git a/.github/workflows/keep-staging-up-to-date-with-main.yml b/.github/workflows/keep-staging-up-to-date-with-main.yml new file mode 100644 index 00000000..e16fa423 --- /dev/null +++ b/.github/workflows/keep-staging-up-to-date-with-main.yml @@ -0,0 +1,47 @@ +# This workflow keeps the staging branch up to date with the main branch +# by creating a pull request against staging with the latest changes from main +# whenever there was a merge to main that didn't go through staging, such as +# small feature branches, new blog posts, etc. +# name: Update Staging with Main branch changes +on: + push: + branches: + - main + +jobs: + update-staging: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Get information about the last merge commit + - name: Get Last Merge Commit + id: last_merge_commit + run: | + merge_commit_sha=$(git log -1 --format=format:%H --merges) + echo "Merge Commit SHA: $merge_commit_sha" + merge_commit_message=$(git log -1 --format=format:%B --merges) + echo "::set-output name=sha::$merge_commit_sha" + echo "::set-output name=message::$merge_commit_message" + + # Optional: Check for a keyword in merge commit message to decide + - name: Check if Merge is from Staging + id: check_merge + run: | + if [[ "${{ steps.last_merge_commit.outputs.message }}" == +*"Merge pull request #"*"from user/staging"* ]]; then + echo "Merge is from staging branch. Skip PR creation." + echo "::set-output name=skip::true" + else + echo "Merge is NOT from staging branch." + echo "::set-output name=skip::false" + fi + + - name: Create pull request + if: steps.check_merge.outputs.skip != 'true' + uses: repo-sync/pull-request@v2 + with: + destination_branch: "staging" + source_branch: "main" + github_token: ${{ secrets.GITHUB_TOKEN }}