From 7db0f736fb7a5f5503ef6bae293c3d1db30ac845 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Mon, 8 Apr 2024 19:20:12 -0500 Subject: [PATCH] Create backport PRs automatically (#3558) ## Motivation and Context Automatically opens backport PRs merging `smithy-rs-release-1.x.y-release` to `main`. ## Description A workflow `backport-pull-request.yml` can be called in two ways: - called automatically when a prod release runs - called manually when a patch fix has been made to `smithy-rs-release-1.x.y-release` and needs to be back-ported ## Testing - Triggered the workflow manually and confirmed [this (dummy) PR](https://github.com/smithy-lang/smithy-rs/pull/3556) got created - Triggered the workflow automatically and confirmed [this (dummy) PR](https://github.com/smithy-lang/smithy-rs/pull/3557) got created ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- .github/workflows/backport-pull-request.yml | 55 +++++++++++++++++++++ .github/workflows/release.yml | 10 ++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/backport-pull-request.yml diff --git a/.github/workflows/backport-pull-request.yml b/.github/workflows/backport-pull-request.yml new file mode 100644 index 000000000..e0b6c49bb --- /dev/null +++ b/.github/workflows/backport-pull-request.yml @@ -0,0 +1,55 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: Open a backport PR to merge the release branch into main + +on: + # automatically called by release.yml + workflow_dispatch: + # can also be manually triggered when a patch fix is merged into the release branch and needs to be back-ported + workflow_call: + secrets: + RELEASE_AUTOMATION_BOT_PAT: + required: true + +env: + release_branch: smithy-rs-release-1.x.y + +jobs: + create-backport-pull-request: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} + + - name: Prepare backport branch + id: backport-branch + run: | + # This step assumes the merge runs cleanly without conflicts, which should be the case when + # this workflow is called by the release workflow right after a release tag has been created. + git config --local user.name "AWS SDK Rust Bot" + git config --local user.email "aws-sdk-rust-primary@amazon.com" + + git fetch + git checkout origin/main + backport_branch="merge-${{ env.release_branch }}-to-main-$(date +%s)" + git checkout -b "${backport_branch}" + + git merge "origin/${{ env.release_branch }}" -m 'Merge remote-tracking branch "origin/${{ env.release_branch }}" into "merge-${{ env.release_branch }}-to-main"' + git push origin HEAD + + echo "branch_name=${backport_branch}" > $GITHUB_OUTPUT + + - name: Create pull request + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} + run: | + gh pr create \ + --title "Merge ${{ env.release_branch }} into main" \ + --body "Merge it with \`gh pr merge --admin --merge\` or manually merge it with the merge commit (not squash merge)." \ + --base main \ + --head ${{ steps.backport-branch.outputs.branch_name }} \ + --label "needs-sdk-review" \ + --draft diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c84ec8af..65934b422 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -268,3 +268,13 @@ jobs: # a manual PR to edit the current CHANGELOG.next.toml file and remove the released entries. git -c 'user.name=AWS SDK Rust Bot' -c 'user.email=aws-sdk-rust-primary@amazon.com' commit CHANGELOG.next.toml --message "Remove released entries from \`CHANGELOG.next.toml\`" git push origin main + + open-backport-pull-request: + name: Open backport pull request to merge the release branch back to main + needs: + - trim-changelog-next-on-main + # See https://github.com/actions/runner/issues/2205#issuecomment-1381988186 for details on the workaround + if: inputs.dry_run == false && always() && needs.trim-changelog-next-on-main.result == 'success' + uses: ./.github/workflows/backport-pull-request.yml + secrets: + RELEASE_AUTOMATION_BOT_PAT: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} -- GitLab