cf-reeve-platform-pr-merged #142
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close platform PR after merge | |
| on: | |
| repository_dispatch: | |
| types: | |
| - cf-reeve-platform-pr-merged | |
| jobs: | |
| close-pr: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SOURCE_BRANCH: "${{ github.event.client_payload.TRIGGERING_PAYLOAD.SOURCE_BRANCH }}" | |
| steps: | |
| - name: Validate source branch | |
| run: | | |
| if [[ -z "$SOURCE_BRANCH" ]]; then | |
| echo "SOURCE_BRANCH is empty or missing – aborting" | |
| exit 1 | |
| fi | |
| - name: Skip protected branches | |
| id: check_branch | |
| run: | | |
| if [[ "$SOURCE_BRANCH" == "main" || "$SOURCE_BRANCH" == "release/"* ]]; then | |
| echo "Protected branch $SOURCE_BRANCH – skipping" | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check if PR exists | |
| if: steps.check_branch.outputs.skip != 'true' | |
| run: | | |
| if ! gh pr view "$SOURCE_BRANCH" --repo ${{ github.repository }} >/dev/null 2>&1; then | |
| echo "No open PR found for branch $SOURCE_BRANCH – nothing to close" | |
| exit 0 | |
| fi | |
| - name: Close PR | |
| if: steps.check_branch.outputs.skip != 'true' | |
| run: | | |
| echo "Closing PR for branch $SOURCE_BRANCH" | |
| gh pr close $SOURCE_BRANCH \ | |
| --repo ${{ github.repository }} \ | |
| --comment "Closed automatically because the platform PR was merged." |