Skip to content

Commit 67ab88b

Browse files
Fix duplicate Code Owners checks on PRs (#12758)
1 parent f235827 commit 67ab88b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

.github/workflows/codeowners.yml

Lines changed: 3 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 }}
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_SHA: ${{ github.event.pull_request.head.sha }}
25+
REPO: ${{ github.repository }}
26+
run: |
27+
# Find the "Run Codeowners Plus" check run for the PR head commit
28+
# and extract the Actions job ID from its details URL.
29+
# Using the commit SHA (not branch name) so this works for fork PRs
30+
# where the branch name doesn't exist in the base repository.
31+
job_id=$(gh api "repos/${REPO}/commits/${HEAD_SHA}/check-runs?check_name=Run+Codeowners+Plus" \
32+
--jq '(.check_runs[0].details_url // "") | split("/") | last | split("?") | first' || true)
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 SHA ${HEAD_SHA}"
40+
fi

0 commit comments

Comments
 (0)