diff --git a/.github/actions/get-latest-pr-number/action.yml b/.github/actions/get-latest-pr-number/action.yml index 15bbcdac2..95f59c8ae 100644 --- a/.github/actions/get-latest-pr-number/action.yml +++ b/.github/actions/get-latest-pr-number/action.yml @@ -8,6 +8,9 @@ inputs: token: description: Specify token (GH or PAT), instead of inheriting one from the calling workflow default: ${{ github.token }} + release_branch: + description: Specify the release branch to get the latest PR number from, like `release/myrelease`. Outside of PRs you need to manually provide this otherwise it will be an empty string. + default: ${{ github.pull_request.head.ref }} outputs: pr: @@ -22,8 +25,13 @@ runs: run: | git fetch origin - release_branch="${{ github.event.pull_request.head.ref }}" - echo "Detected release branch: $release_branch" + release_branch="${{ inputs.release_branch }}" + echo "Configured release branch as: $release_branch" + + if ! git show-ref --verify --quiet refs/remotes/origin/$release_branch; then + echo "Release branch $release_branch does not exist in the repository." + exit 1 + fi latest_pr=$(git log origin/$release_branch --pretty=format:'%s' | grep -oP '(?<=#)\d+' | head -n 1) diff --git a/.github/workflows/merge-main.yml b/.github/workflows/release-main.yml similarity index 85% rename from .github/workflows/merge-main.yml rename to .github/workflows/release-main.yml index 9ec85b1bc..52289a0c8 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/release-main.yml @@ -1,18 +1,10 @@ -name: Merge +name: Release To Production on: - push: - branches: [main] - paths-ignore: - - "*.md" - - ".github/**" - - ".github/graphics/**" - - "!.github/workflows/**" workflow_dispatch: inputs: - pr_no: - description: "PR-numbered container set to deploy" - type: number + release_branch: + description: "Specify the release branch to get the latest PR number from, like `release/myrelease`" required: true concurrency: @@ -28,10 +20,17 @@ jobs: runs-on: ubuntu-22.04 timeout-minutes: 1 steps: + - name: Verify Is Main Branch + if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main' + run: | + echo "This workflow should not be triggered with workflow_dispatch on a branch other than main" + exit 1 - uses: actions/checkout@v4 - name: Get Latest PR Number in release branch id: latest-pr uses: ./.github/actions/get-latest-pr-number + with: + release_branch: ${{ github.event.inputs.release_branch }} - name: Set PR Output run: echo "pr=${{ steps.latest-pr.outputs.pr }}" >> $GITHUB_OUTPUT