Skip to content

ci: post HIL report comment from workflow_run so it works on forked PRs#3723

Merged
hathach merged 4 commits into
masterfrom
claude/hil-report-fork-prs
Jun 22, 2026
Merged

ci: post HIL report comment from workflow_run so it works on forked PRs#3723
hathach merged 4 commits into
masterfrom
claude/hil-report-fork-prs

Conversation

@hathach

@hathach hathach commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Problem

The hil-report job (the combined HIL sticky PR comment) lived in build.yml gated on:

github.event.pull_request.head.repo.fork == false

so it was skipped on forked PRs — even though the hil-tinyusb jobs themselves run there. Verified live on fork PR #3582: the HIL jobs ran (one failed, one passed) but hil-report was skipped. Root cause: a pull_request event from a fork gives GITHUB_TOKEN read-only permissions, so a pull-requests: write post would 403.

Fix

Use the standard workflow_run pattern (already used by metrics_comment.yml and membrowse-comment.yml): post the comment from a separate workflow that runs in the base-repo context with a write token and access to the triggering run's uploaded artifacts.

  • Renamed .github/workflows/metrics_comment.yml.github/workflows/pr_comment.yml (name: Metrics CommentPR Comment).
  • Added a hil-comment job that downloads the hil-report-* artifacts from the triggering run, combines one markdown table per rig (same logic as the old job), and posts the sticky hil-report comment.
  • Removed the hil-report job from build.yml.

Gate

hil-comment runs on workflow_run.event == 'pull_request' && conclusion != 'cancelled' — i.e. it posts even when the build/HIL failed (that's exactly when the report matters; the old job used always()). It deliberately does not require conclusion == 'success'.

PR number — resolved from trusted workflow_run metadata

github.event.workflow_run.pull_requests is empty for fork PRs, so a shared pr_number job resolves the number from trusted sources — never from build artifacts (a forked PR controls its own Build run and could plant an arbitrary number, which the privileged comment jobs would otherwise post to):

  • same-repo PRs → workflow_run.pull_requests (parsed in-shell);
  • forked PRs → look up the open PR by its trusted head ref (head_repository:head_branch) and verify head.sha == workflow_run.head_sha.

All lookups are best-effort, so a miss skips the comment rather than failing the job. Both metrics-comment and hil-comment consume needs.pr_number.outputs.number, so neither trusts artifact-supplied numbers. This also closes the same issue in the pre-existing metrics path; the now-unused pr_number.txt was dropped from the code-metrics artifact.

Hardening (review feedback)

  • The metrics-comment artifact download is best-effort (continue-on-error) so docs-only PRs (where code-metrics is skipped) don't fail the check.
  • @-mentions in the combined HIL report are neutralized (zero-width space) before posting, since fork PRs can influence report content and this job posts with a write token in base-repo context.

Note on testing

workflow_run workflows only trigger when present on the default branch, so pr_comment.yml will not run for this PR — it takes effect only after merge to master. Validated locally with actionlint (pr_comment.yml clean; the two build.yml warnings — if: false zephyr job, hifiphile self-hosted label — are pre-existing on master) and a YAML parse.

Minor heads-up: the workflow display name changed (Metrics CommentPR Comment). If any branch-protection required status check references the old name, it would need updating — unlikely for a workflow_run comment job, but flagging it.

🤖 Generated with Claude Code

The hil-report job lived in build.yml gated on pull_request.head.repo.fork == false, so the combined HIL sticky comment was skipped on forked PRs even though the HIL jobs themselves ran. Fork pull_request events get a read-only GITHUB_TOKEN, so posting from build.yml would 403.

Move the comment into the workflow_run-triggered pr_comment.yml (renamed from metrics_comment.yml), which runs in the base-repo context with a write token and access to the triggering run's artifacts. A new hil-comment job downloads the hil-report-* artifacts, combines one table per rig, and posts the sticky hil-report comment with an explicit PR number read from pr_number.txt in the metrics-comment artifact (workflow_run.pull_requests is empty for forks).

build.yml's hil-report job is removed; the HIL artifact uploads are unchanged. workflow_run workflows only trigger from the default branch, so this takes effect after merge to master.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 21, 2026 16:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Moves HIL report PR commenting out of the Build workflow and into a workflow_run-triggered workflow so the sticky HIL report comment can be posted with write permissions even for forked PRs (where the build-side GITHUB_TOKEN is read-only).

Changes:

  • Add .github/workflows/pr_comment.yml (workflow_run on “Build”) to post sticky PR comments (metrics + new combined HIL report).
  • Remove the in-workflow hil-report commenting job from .github/workflows/build.yml.
  • Remove the old standalone .github/workflows/metrics_comment.yml workflow (superseded by pr_comment.yml).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/pr_comment.yml New workflow_run workflow that posts metrics and combined HIL sticky PR comments in base-repo context.
.github/workflows/metrics_comment.yml Removed old metrics-only workflow_run commenter workflow (replaced by pr_comment.yml).
.github/workflows/build.yml Deletes the previous hil-report job that posted comments only for non-fork PRs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/pr_comment.yml
Comment thread .github/workflows/pr_comment.yml Outdated
Comment thread .github/workflows/pr_comment.yml
@claude

claude Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b7a507f25

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/pr_comment.yml Outdated
@github-actions

Copy link
Copy Markdown

Size Difference Report

Because TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds.

Note: If there is no change, only one value is shown.

Changes >1% in size

No entries.

Changes <1% in size

No entries.

No changes
file .text .rodata .data .bss size % diff
audio_device.c 2890 0 1259 1623 4508 +0.0%
cdc_device.c 1236 16 1092 728 1963 +0.0%
cdc_host.c 6399 487 15 971 7594 +0.0%
dcd_ch32_usbfs.c 1640 0 0 2444 4084 +0.0%
dcd_ch32_usbhs.c 1892 0 0 481 2373 +0.0%
dcd_ci_fs.c 1924 0 0 1290 3214 +0.0%
dcd_ci_hs.c 1756 0 0 1344 2534 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_dwc2.c 4223 19 0 265 4506 +0.0%
dcd_eptri.c 2273 0 0 259 2532 +0.0%
dcd_ft9xx.c 3284 0 0 172 3456 +0.0%
dcd_khci.c 1952 0 0 1290 3242 +0.0%
dcd_lpc17_40.c 1481 0 0 648 1805 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 +0.0%
dcd_mm32f327x_otg.c 1477 0 0 1290 2767 +0.0%
dcd_msp430x5xx.c 1801 0 0 176 1977 +0.0%
dcd_musb.c 2595 0 0 179 2773 +0.0%
dcd_nrf5x.c 2939 0 0 292 3231 +0.0%
dcd_nuc120.c 1096 0 0 78 1174 +0.0%
dcd_nuc121.c 1170 0 0 101 1270 +0.0%
dcd_nuc505.c 0 0 1533 157 1690 +0.0%
dcd_rp2040.c 840 0 764 653 2257 +0.0%
dcd_rusb2.c 2918 0 0 156 3074 +0.0%
dcd_samd.c 1036 0 0 266 1302 +0.0%
dcd_samg.c 1322 0 0 72 1394 +0.0%
dcd_stm32_fsdev.c 2534 0 0 291 2825 +0.0%
dfu_device.c 776 28 712 136 912 +0.0%
dfu_rt_device.c 157 0 134 0 157 +0.0%
dwc2_common.c 603 22 0 0 615 +0.0%
ecm_rndis_device.c 1059 0 1 2759 3818 +0.0%
ehci.c 2763 0 0 6274 7783 +0.0%
fsdev_common.c 180 0 0 0 180 +0.0%
hcd_ch32_usbfs.c 2491 0 0 502 2993 +0.0%
hcd_ci_hs.c 181 0 0 0 181 +0.0%
hcd_dwc2.c 5070 25 1 545 5640 +0.0%
hcd_khci.c 2443 0 0 454 2897 +0.0%
hcd_musb.c 3071 0 0 157 3228 +0.0%
hcd_pio_usb.c 262 0 240 0 502 +0.0%
hcd_rp2040.c 1996 17 4 321 2338 +0.0%
hcd_rusb2.c 2923 0 0 245 3168 +0.0%
hcd_samd.c 2220 0 0 324 2544 +0.0%
hcd_stm32_fsdev.c 3248 0 1 420 3670 +0.0%
hid_device.c 1123 44 997 119 1242 +0.0%
hid_host.c 1241 0 0 1270 2511 +0.0%
hub.c 1384 8 8 30 1419 +0.0%
midi2_device.c 2628 52 1175 561 3211 +0.0%
midi2_host.c 1802 0 0 5921 7723 +0.0%
midi_device.c 1149 0 1007 619 1765 +0.0%
midi_host.c 1339 7 7 3538 4880 +0.0%
msc_device.c 2513 108 2281 804 3318 +0.0%
msc_host.c 1633 0 0 395 2028 +0.0%
mtp_device.c 1713 22 743 589 2309 +0.0%
ncm_device.c 1761 28 819 4393 6167 +0.0%
ohci.c 1925 0 0 2503 4428 +0.0%
printer_device.c 828 0 706 560 1387 +0.0%
rp2040_usb.c 386 35 619 11 1051 +0.0%
rusb2_common.c 160 0 16 0 176 +0.0%
tusb.c 455 0 387 3 457 +0.0%
tusb_fifo.c 855 0 486 0 850 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 420 2 20 166 608 +0.0%
usbd.c 3530 57 90 355 3948 +0.0%
usbh.c 4967 57 82 1165 6238 +0.0%
usbtmc_device.c 2194 24 68 313 2539 +0.0%
vendor_device.c 639 0 534 559 1197 +0.0%
video_device.c 4433 5 1235 480 4905 +0.0%
TOTAL 124549 1071 17038 52137 178264 +0.0%

@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected across 2384 targets. View Project Dashboard →

- metrics-comment: make the artifact download best-effort so docs-only PRs (where code-metrics is skipped) don't fail the check (Copilot).

- HIL PR number: carry pr_number.txt inside each hil-report-* artifact and read it in hil-comment, so the HIL comment is self-contained and still posts when an unrelated build leg fails or code-metrics is skipped, on same-repo and forked PRs alike (Codex).

- hil-comment: neutralize @-mentions in the combined report before posting, since fork PRs can influence report content and this job posts with a write token in base-repo context (Copilot).

Co-Authored-By: Claude <noreply@anthropic.com>
@hathach

hathach commented Jun 22, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/pr_comment.yml Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3403865b13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/pr_comment.yml Outdated
Codex flagged that taking the PR number from a downloaded artifact lets a forked PR (which controls its own Build run) plant an arbitrary number, so the privileged workflow_run comment job could post to any PR/issue.

Resolve the number from trusted workflow_run metadata instead: same-repo PRs use github.event.workflow_run.pull_requests[0].number; forked PRs look up the PR by the trusted workflow_run.head_sha. A shared pr_number job feeds both metrics-comment and hil-comment so neither trusts artifact-supplied numbers.

Revert the Option B change that carried pr_number.txt in the HIL artifacts, and drop the now-unused pr_number.txt from the code-metrics metrics-comment artifact (build.yml back to baseline + that removal).

Addresses Codex review comment on #3723.

Co-Authored-By: Claude <noreply@anthropic.com>
@hathach hathach requested a review from Copilot June 22, 2026 07:55
@hathach

hathach commented Jun 22, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/pr_comment.yml
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: d60acb61df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot flagged that the fork lookup 'gh api commits/<sha>/pulls' can 404/fail under bash -e and block both comment jobs. Harden the pr_number job:

- parse workflow_run.pull_requests in-shell (jq over toJSON) instead of indexing [0] in an expression; - resolve fork PRs via the reliable targeted pulls?state=open&head=<owner>:<branch> filter, verifying head.sha == head_sha (still trusted metadata); - make every lookup best-effort so a miss skips the comment instead of failing the step.

Addresses Copilot review comment on #3723.

Co-Authored-By: Claude <noreply@anthropic.com>
@hathach hathach requested a review from Copilot June 22, 2026 08:11
@hathach

hathach commented Jun 22, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ebf9d8a12d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@hathach hathach merged commit 299c0a5 into master Jun 22, 2026
324 of 325 checks passed
@hathach hathach deleted the claude/hil-report-fork-prs branch June 22, 2026 08:33
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.

2 participants