Skip to content

CI: Fix cancellation workflow API flags, permissions, and filters#7228

Open
arpittkhandelwal wants to merge 1 commit intoTheHPXProject:masterfrom
arpittkhandelwal:ci/cancel-workflow-fixes
Open

CI: Fix cancellation workflow API flags, permissions, and filters#7228
arpittkhandelwal wants to merge 1 commit intoTheHPXProject:masterfrom
arpittkhandelwal:ci/cancel-workflow-fixes

Conversation

@arpittkhandelwal
Copy link
Copy Markdown
Contributor

@arpittkhandelwal arpittkhandelwal commented Apr 27, 2026

Background

This PR contains follow-up fixes for the manual workflow cancellation tool introduced in #7205. While the cancel-ci label and /cancel-ci comment triggers are in place, the script encountered a few GitHub CLI and API limitations in production that caused it to fail.

Errors Fixed

This PR addresses the following issues to make the script fully operational and robust:

  1. Precise PR Filtering: Switched from branch-based filtering to a direct GitHub API query (gh api). This ensures that only runs specifically tied to the PR number are cancelled, avoiding any issues with common branch names (e.g., patch-1) or forks.
  2. "Resource not accessible" Error: Added issues: write permissions so that gh pr edit can successfully remove the cancel-ci label.
  3. Safety & Self-Cancellation: Added set -euo pipefail for strict shell execution and used tonumber in the jq filter to reliably exclude the current run from being cancelled.
  4. Pagination Limit: Added --per_page=100 to the API call to ensure all active runs are captured on busy PRs.

Key Code Updates

The core logic now uses the GitHub API for precise targeting:

# Fetch recent runs and filter by the specific PR number
RUN_IDS=$(gh api "/repos/${{ github.repository }}/actions/runs?per_page=100" \
  --jq ".workflow_runs[] | select(.status != \"completed\" and .id != (env.CURRENT_RUN_ID | tonumber) and any(.pull_requests[]; .number == ($PR_NUMBER | tonumber))) | .id")

Copilot AI review requested due to automatic review settings April 27, 2026 17:58
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 27, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Follow-up fixes to the manual CI workflow cancellation automation (introduced in #7205) to address GitHub CLI/API limitations encountered in production and make the cancellation tool reliably operational.

Changes:

  • Replace unsupported gh run list --pr usage by first resolving the PR head branch and filtering runs via --branch.
  • Expand workflow permissions to allow label removal (issues: write) and fix self-exclusion in jq by casting CURRENT_RUN_ID to a number.
  • Increase gh run list pagination limit to capture more active runs (--limit 200).

Comment thread .github/workflows/cancel-workflows.yml Outdated
Comment thread .github/workflows/cancel-workflows.yml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants