-
由 Will Chen 提交于
#skip-bb ## Summary This PR adds a new GitHub Actions workflow that automatically cancels in-progress and queued CI workflow runs when a pull request is merged. This helps reduce unnecessary CI resource consumption and prevents stale workflow runs from completing after their changes have already been integrated. ## Changes - Added `.github/workflows/cancel-ci-after-merge.yml` workflow that: - Triggers when a pull request is closed (merged) - Finds the CI workflow in the repository - Queries for all in-progress and queued CI runs on the merged PR's branch - Cancels each identified workflow run with error handling and logging - Includes comprehensive console logging for debugging and monitoring ## Implementation Details - The workflow uses `actions/github-script@v7` to interact with the GitHub Actions API - It specifically targets the "CI" workflow by name - Handles both "in_progress" and "queued" statuses to catch all active runs - Includes try-catch error handling to gracefully handle cancellation failures - Requires `actions: write` permission to cancel workflow runs - Only executes when `github.event.pull_request.merged == true` to avoid running on rejected PRs <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Automatically cancel active CI runs for the merged PR’s head commit. Frees up runners and prevents stale builds from finishing. - **New Features** - Adds .github/workflows/cancel-ci-after-merge.yml triggered on PR closed, gated to merged PRs. - Targets the CI workflow via file path ci.yml and lists runs for the PR head SHA. - Cancels active runs (in_progress, queued, pending, waiting) with try/catch error handling and de-duplicates by run ID. - Supports fork and non-fork PRs; uses actions/github-script@v7 with actions: write permissions and clear console logs. <sup>Written for commit 4d631b3ccb9d127c4781b185b9d6eac90d2fd710. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by:Claude <noreply@anthropic.com>