Skip to content

Commit 74cad8f

Browse files
Fix duplicate Code Owners checks on PRs
When both pull_request_target and pull_request_review triggers are in the same workflow, GitHub creates separate check contexts for each event type. This causes two 'Code Owners' checks to appear on PRs — one from the initial PR event (often stale/failing) and one from the review event (current/passing). Split the workflow into two files: - codeowners.yml: keeps only the pull_request_target trigger and runs the actual codeowners-plus evaluation - rerun_codeowners.yml: triggered by pull_request_review, re-runs the existing check job via the GitHub API instead of creating a new one This ensures only a single Code Owners check appears on each PR. Also skip codeowners-plus evaluation for Version Packages PRs (changeset-release/main) which only need wrangler team approval and are already protected by native GitHub CODEOWNERS.
1 parent 00a4356 commit 74cad8f

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

.github/workflows/codeowners.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: "Code Owners"
22

3-
# Re-evaluate when PRs are opened/updated, and when reviews are submitted/dismissed.
3+
# Re-evaluate when PRs are opened/updated.
4+
# When reviews are submitted/dismissed, the separate rerun_codeowners.yml workflow
5+
# re-runs this check (rather than creating a second check context).
46
# Using pull_request_target (not pull_request) so the workflow has access to secrets
57
# for fork PRs. This is safe because:
68
# - The checkout is the BASE branch (ownership rules come from the protected branch)
@@ -9,8 +11,6 @@ name: "Code Owners"
911
on:
1012
pull_request_target:
1113
types: [opened, reopened, synchronize, ready_for_review, labeled, unlabeled]
12-
pull_request_review:
13-
types: [submitted, dismissed]
1414

1515
concurrency:
1616
group: codeowners-${{ github.event.pull_request.number }}
@@ -27,16 +27,19 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: "Checkout Base Branch"
30+
if: github.event.pull_request.head.ref != 'changeset-release/main'
3031
uses: actions/checkout@v4
3132
with:
3233
fetch-depth: 0
3334

3435
- name: "Fetch PR Head (for diff computation)"
36+
if: github.event.pull_request.head.ref != 'changeset-release/main'
3537
run: git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head
3638
env:
3739
GITHUB_TOKEN: "${{ secrets.CODEOWNERS_GITHUB_PAT }}"
3840

3941
- name: "Codeowners Plus"
42+
if: github.event.pull_request.head.ref != 'changeset-release/main'
4043
uses: multimediallc/codeowners-plus@ff02aa993a92e8efe01642916d0877beb9439e9f # v1.9.0
4144
with:
4245
github-token: "${{ secrets.CODEOWNERS_GITHUB_PAT }}"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Rerun Code Owners"
2+
3+
# When a review is submitted or dismissed, re-run the Code Owners check from the
4+
# main codeowners.yml workflow (triggered by pull_request_target) rather than
5+
# running the check again under a separate event context. This avoids duplicate
6+
# "Code Owners" checks appearing on the PR.
7+
on:
8+
pull_request_review:
9+
types: [submitted, dismissed]
10+
11+
permissions: {}
12+
13+
jobs:
14+
rerun-codeowners:
15+
name: "Rerun Codeowners Plus"
16+
runs-on: ubuntu-latest
17+
permissions:
18+
actions: write
19+
checks: read
20+
steps:
21+
- name: "Re-run Codeowners Check"
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
25+
REPO: ${{ github.repository }}
26+
run: |
27+
# Find the "Run Codeowners Plus" check run for the PR head branch
28+
# and extract the Actions job ID from its details URL.
29+
job_id=$(gh api "repos/${REPO}/commits/${HEAD_REF}/check-runs" \
30+
--jq '.check_runs[] | select(.name == "Run Codeowners Plus") | .details_url' \
31+
| head -1 \
32+
| grep -oE '[0-9]+$')
33+
34+
if [ -n "$job_id" ]; then
35+
gh api "repos/${REPO}/actions/jobs/${job_id}/rerun" --method POST \
36+
|| echo "Job may already be running"
37+
echo "Re-triggered 'Run Codeowners Plus' (job ${job_id})"
38+
else
39+
echo "Check 'Run Codeowners Plus' not found for ref ${HEAD_REF}"
40+
fi

0 commit comments

Comments
 (0)