Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 759ead6c9c ci: cancel a pull request's remaining runs when it is closed or merged
Runs of merged PRs kept holding runners while other PRs' checks sat queued
for hours. The workflow uses pull_request_target so it also covers forks; it
never checks out PR code, it only cancels the PR branch's unfinished
pull_request / pull_request_target runs.

Closes #4362
2026-11-19 08:25:55 +08:00
+42
Переглянути файл
@@ -0,0 +1,42 @@
name: Cancel runs of closed PRs
on:
# pull_request_target so it also runs for PRs from forks. It never checks out or
# runs PR code: it only lists and cancels workflow runs of the closed PR's branch.
pull_request_target:
types: [closed]
permissions:
actions: write
jobs:
cancel:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v8
with:
script: |
// A merged or closed PR's remaining CI only holds runners other PRs wait for.
const pr = context.payload.pull_request;
const { owner, repo } = context.repo;
const headRepo = pr.head.repo?.full_name;
let cancelled = 0;
for (const status of ['queued', 'in_progress', 'waiting', 'pending', 'requested']) {
const runs = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
owner,
repo,
branch: pr.head.ref,
status,
per_page: 100,
});
for (const run of runs) {
if (run.id === context.runId || run.head_repository?.full_name !== headRepo) continue;
if (!['pull_request', 'pull_request_target'].includes(run.event)) continue;
try {
await github.rest.actions.cancelWorkflowRun({ owner, repo, run_id: run.id });
cancelled++;
} catch (e) {
core.warning(`run ${run.id}: ${e.message}`);
}
}
}
core.info(`Cancelled ${cancelled} run(s) of #${pr.number}`);