Unverified Commit 6642e3a2 authored by Lianmin Zheng's avatar Lianmin Zheng Committed by GitHub
Browse files

[Fix] Add a workflow to cancel all pending CI runs (#8988)

parent 67a7d1f6
name: Cancel All Pending PR Test Runs name: Cancel All Pending PR Test Runs
on: on:
workflow_dispatch: # Manual trigger workflow_dispatch:
permissions:
actions: write # Needed to cancel runs
contents: read # Needed to read repo info
jobs: jobs:
cancel-pending: cancel-pending:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Install GitHub CLI - name: Install GitHub CLI
run: apt-get install -y gh jq run: sudo apt-get install -y gh jq
- name: Authenticate GitHub CLI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh auth login --with-token <<< "$GH_TOKEN"
- name: Cancel all pending/waiting pr-test.yml runs - name: Cancel all pending/waiting pr-test.yml runs
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: | run: |
# Get all pending or waiting runs of pr-test.yml across all branches
gh run list \ gh run list \
--repo "$REPO" \
--workflow pr-test.yml \ --workflow pr-test.yml \
--json databaseId,status,conclusion \ --json databaseId,status \
--limit 1000 \ --limit 1000 \
| jq -r '.[] | select(.status=="queued" or .status=="in_progress") | .databaseId' \ | jq -r '.[] | select(.status=="queued" or .status=="in_progress") | .databaseId' \
| while read run_id; do | while read run_id; do
echo "Cancelling run ID: $run_id" echo "Cancelling run ID: $run_id"
gh run cancel "$run_id" gh run cancel "$run_id" --repo "$REPO"
done done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment