Test/v1 #7
Workflow file for this run
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 updated PRs | |
| on: | |
| pull_request_target: | |
| types: | |
| - synchronize | |
| permissions: | |
| actions: write | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| close-updated-pr: | |
| name: Close updated PR | |
| if: ${{ github.event.pull_request.draft == false }} | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| REPOSITORY: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| AFTER: ${{ github.event.after }} | |
| steps: | |
| - name: Close updated PR | |
| run: | | |
| set -euo pipefail | |
| body=$(cat <<'EOF' | |
| Closing this pull request: its branch was updated after the pull | |
| request was opened. | |
| Per our workflow, a new pull request is required when changes are made | |
| to an existing one. Please open a new pull request with the updated | |
| changes. | |
| If you wish to create an in progress pull request that you can push to, | |
| please draft a draft pull request. | |
| Please see [GitHub Pull Request Workflow](https://docs.suricata.io/en/latest/devguide/contributing/github-pr-workflow.html). | |
| EOF | |
| ) | |
| gh api \ | |
| --method POST \ | |
| "/repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ | |
| -f body="${body}" \ | |
| --silent | |
| gh api \ | |
| --method PATCH \ | |
| "/repos/${REPOSITORY}/pulls/${PR_NUMBER}" \ | |
| -f state=closed \ | |
| --silent | |
| # Run last: cancelling the runs for this push also cancels this run, so | |
| # this must come after the PR has already been closed. | |
| - name: Cancel running workflows for this push | |
| run: | | |
| set -euo pipefail | |
| for status in queued in_progress; do | |
| gh api --paginate \ | |
| "/repos/${REPOSITORY}/actions/runs?head_sha=${AFTER}&status=${status}" \ | |
| --jq '.workflow_runs[].id' | while read -r run_id; do | |
| gh api \ | |
| --method POST \ | |
| "/repos/${REPOSITORY}/actions/runs/${run_id}/cancel" \ | |
| --silent || true | |
| done | |
| done |