From 58944804db3d4e7b4801c52e6d4bb0b28c44c58c Mon Sep 17 00:00:00 2001 From: tomjohnburton <39559415+tomjohnburton@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:00:23 +0100 Subject: [PATCH] feat: auto pick non-breaking changes (#4498) * chore: auto pick * fix: correct env * change (#4499) * change (#4501) * [pick] * [pick] * [pick] * [pick] * [pick] * [pick] * [pick] * [pick] * fix: correct namespace * chore: add notification * chore: use PR and labels * fix: revert to pr closed * fix: do with ref * fake (#4522) * fake (#4524) * chore: add commit sha * chore: remove pla-14432 * chore: improve readme * fix: remove comment * fix: set base commit as main --- .github/pull_request_template.md | 5 ++ .github/workflows/ci-cherry-pick.yml | 68 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/ci-cherry-pick.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 462c291677..b267a84ff9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -12,3 +12,8 @@ Please conduct a thorough self-review before opening the PR. ## Summary *Please include a succinct description of the purpose and content of the PR. What problem does it solve, and how? Link issues, discussions, other PRs, and anything else that will help the reviewer.* + + +#### Non-Breaking changes + +If this PR includes non-breaking changes, select the `non-breaking` label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch. \ No newline at end of file diff --git a/.github/workflows/ci-cherry-pick.yml b/.github/workflows/ci-cherry-pick.yml new file mode 100644 index 0000000000..b9ee1f88ab --- /dev/null +++ b/.github/workflows/ci-cherry-pick.yml @@ -0,0 +1,68 @@ +name: Cherry-Pick to Release Branch + +on: + pull_request: + branches: + - main + types: + - closed + +run-name: Cherry pick `${{ github.event.pull_request.title }}` to release branch + +jobs: + cherry-pick: + if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'non-breaking')) }} + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v3 + with: + ref: main + + - name: Configure Git + run: | + git config --global user.name 'GitHub Action' + git config --global user.email 'action@github.com' + + - name: Cherry-pick commit + run: | + set -x + git fetch --all + COMMIT_SHA=$(git rev-parse HEAD) + echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV + + RELEASE_BRANCH="release/$(git branch -r | grep 'origin/release/[0-9]\+\.[0-9]' | sed 's/.*release\///' | sort -V | tail -n1)" + echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV + + BRANCH=pick/non-breaking-$(date +%s) + echo "BRANCH=$BRANCH" >> $GITHUB_ENV + + git checkout $RELEASE_BRANCH + git checkout -b $BRANCH + git cherry-pick -x $COMMIT_SHA + + - name: Push to Remote + run: | + git push origin ${{ env.BRANCH }} + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.CF_BACKEND_GITHUB_TOKEN }} + commit-message: Cherry-picked from ${{ env.COMMIT_SHA }} + title: "Cherry-Pick ${{ env.COMMIT_SHA }} to ${{ env.RELEASE_BRANCH }}" + branch: ${{ env.BRANCH }} + base: '${{ env.RELEASE_BRANCH }}' + reviewers: 'martin-chainflip' + labels: cherry-pick + + - name: Notify on failed cherry-pick + if: failure() || cancelled() + env: + DISCORD_USERNAME: "Release Picker" + DISCORD_WEBHOOK: ${{ secrets.CF_DISCORD_ALERTS_CRITICAL }} + uses: Ilshidur/action-discord@0.3.2 + with: + args: | + 🍒⚠️ Sorry **${{ github.actor }}**, The attempt to cherry-pick `${{ env.COMMIT_SHA }}` on to `${{ env.RELEASE_BRANCH }}` was unsuccessful + Please check the [GitHub job](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) to see what went wrong.