From 8a355df273c5059aafe4ea23081713881e2da556 Mon Sep 17 00:00:00 2001 From: barrfalk Date: Wed, 23 Oct 2024 10:10:41 -0700 Subject: [PATCH 1/2] Get the latest PR number merged into the release branch When migrating to production, we shouldn't be rebuilding the release, since this could introduce a change that wasn't tested in the test environment. Instead, we should be grabbing the latest PR that was merged into the release branch, and use that to deploy that image to production. --- .../actions/get-latest-pr-number/action.yml | 39 +++++++++++++++++++ .github/workflows/merge-main.yml | 11 +++--- 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 .github/actions/get-latest-pr-number/action.yml diff --git a/.github/actions/get-latest-pr-number/action.yml b/.github/actions/get-latest-pr-number/action.yml new file mode 100644 index 000000000..8df7249b0 --- /dev/null +++ b/.github/actions/get-latest-pr-number/action.yml @@ -0,0 +1,39 @@ +name: Get Latest Merged PR Number +description: Get the latest merged PR number from the release branch, this is the production candidate +branding: + icon: git-pull-request + color: blue + +inputs: + token: + description: Specify token (GH or PAT), instead of inheriting one from the calling workflow + default: ${{ github.token }} + +outputs: + pr: + description: "Latest merged pull request number" + value: ${{ steps.vars.outputs.pr }} + +runs: + using: composite + steps: + - id: vars + shell: bash + run: | + git fetch origin + + release_branch="${{ github.event.pull_request.head.ref }}" + echo "Detected release branch: $release_branch" + + latest_pr=$(git log origin/$release_branch --merges --pretty=format:'%s' | grep -oP '(?<=#)\d+' | head -n 1) + + if [ -z "$latest_pr" ]; then + echo "No merged PR found on $release_branch" + exit 1 + elif [[ ! "$latest_pr" =~ ^[0-9]+$ ]]; then + echo "PR number format incorrect: $latest_pr" + exit 1 + fi + + echo "Latest PR number from $release_branch: $latest_pr" + echo "pr=$latest_pr" >> $GITHUB_OUTPUT diff --git a/.github/workflows/merge-main.yml b/.github/workflows/merge-main.yml index 2bacb333d..d19e962c9 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/merge-main.yml @@ -24,17 +24,16 @@ jobs: vars: name: Set Variables outputs: - pr: ${{ steps.pr.outputs.pr }} + pr: ${{ steps.latest-pr.outputs.pr }} runs-on: ubuntu-22.04 timeout-minutes: 1 steps: - uses: actions/checkout@v4 - # Get PR number for squash merges to release - - name: PR Number - id: pr - uses: ./.github/actions/get-pr-number + - name: Get Latest PR Number in release branch + id: latest-pr + uses: ./.github/actions/get-latest-pr-number - name: Set PR Output - run: echo "pr=${{ steps.pr.outputs.pr }}" >> $GITHUB_OUTPUT + run: echo "pr=${{ steps.latest-pr.outputs.pr }}" >> $GITHUB_OUTPUT create_release: name: Create GitHub Release (Keep Version) From 78b7bb33e12f0876ec20deca5563d5f1b1d2f7fe Mon Sep 17 00:00:00 2001 From: barrfalk Date: Mon, 28 Oct 2024 14:25:28 -0700 Subject: [PATCH 2/2] Update action.yml --- .github/actions/get-latest-pr-number/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/get-latest-pr-number/action.yml b/.github/actions/get-latest-pr-number/action.yml index 8df7249b0..15bbcdac2 100644 --- a/.github/actions/get-latest-pr-number/action.yml +++ b/.github/actions/get-latest-pr-number/action.yml @@ -25,7 +25,7 @@ runs: release_branch="${{ github.event.pull_request.head.ref }}" echo "Detected release branch: $release_branch" - latest_pr=$(git log origin/$release_branch --merges --pretty=format:'%s' | grep -oP '(?<=#)\d+' | head -n 1) + latest_pr=$(git log origin/$release_branch --pretty=format:'%s' | grep -oP '(?<=#)\d+' | head -n 1) if [ -z "$latest_pr" ]; then echo "No merged PR found on $release_branch"