Cancel All Pending PR Test Runs #5
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: Cancel All Pending PR Test Runs | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| actions: write # Needed to cancel runs | |
| contents: read # Needed to read repo info | |
| jobs: | |
| cancel-pending: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Install GitHub CLI | |
| run: sudo apt-get install -y gh jq | |
| - name: Cancel all pending/waiting pr-test.yml runs (except this one) | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| CURRENT_RUN_ID: ${{ github.run_id }} | |
| run: | | |
| gh run list \ | |
| --repo "$REPO" \ | |
| --workflow pr-test.yml \ | |
| --json databaseId,status \ | |
| --limit 1000 \ | |
| | jq -r --arg cur "$CURRENT_RUN_ID" '.[] | select(.databaseId|tostring != $cur) | select(.status=="queued" or .status=="in_progress") | .databaseId' \ | |
| | while read run_id; do | |
| echo "Cancelling run ID: $run_id" | |
| gh run cancel "$run_id" --repo "$REPO" | |
| done |