Skip to content

ci: make Recommend integration tests workflow fork-safe#7861

Closed
ianwinsemius wants to merge 1 commit into
primer:mainfrom
ianwinsemius:chore/recommend-workflow-fork-safe
Closed

ci: make Recommend integration tests workflow fork-safe#7861
ianwinsemius wants to merge 1 commit into
primer:mainfrom
ianwinsemius:chore/recommend-workflow-fork-safe

Conversation

@ianwinsemius
Copy link
Copy Markdown

Closes #

Problem

The Recommend integration tests workflow runs on every pull_request event, including PRs opened from forks. When triggered by a fork PR the provided GITHUB_TOKEN has read-only access to the upstream repo and any write call (addLabels / createComment) fails with:

HttpError: Resource not accessible by integration (HTTP 403)

That failure surfaces as a red ❌ recommend check on every fork PR — even when the underlying source code is fine and all other checks (lint, tests, type-check, build, VRT, AAT, CodeQL) pass. It's misleading because the job's role is to suggest integration testing, not to gate the PR on its own infra success.

Example: see the three PRs I have open (#7855, #7856, #7857) — all 34 functional checks pass, and only the recommend workflow fails because of this permission limitation.

Fix

Wrap the label and comment API calls in a small helper that catches HTTP 403s and logs an actionable core.info message instead of throwing. The job runs to completion green, and maintainers can apply the integration-tests: recommended label manually if the change warrants integration testing.

Additionally, comment writes are skipped entirely on fork PRs (context.payload.pull_request.head.repo.full_name !== context.payload.repository.full_name). The bot's comment recommends running an internal-only workflow that a fork PR author cannot trigger anyway — better to suppress the noise.

Before / After

Before:

  • Fork PR opens → recommend job fails with Resource not accessible by integration → red ❌ on the PR.

After:

  • Fork PR opens → recommend job catches the 403, logs Skipped addLabels: GITHUB_TOKEN cannot write to this repository from a forked PR. A maintainer can apply the 'integration-tests: recommended' label manually if integration tests are warranted. → green ✅ on the PR.
  • Internal-branch PR behaviour unchanged: the job still adds the label and posts the comment.

Changelog

New

  • (none)

Changed

  • .github/workflows/recommend-integration-tests.yml — wrap label/comment writes in try/catch keyed on HTTP 403 so the job no longer fails on fork PRs.

Removed

  • (none)

Rollout strategy

  • Patch release (CI-only change, no runtime impact)
  • Minor release
  • Major release
  • None

This is a CI-only change with no impact on the published @primer/react package, so it does not include a changeset. Please apply the skip changeset label.

Testing & Reviewing

  • YAML validated locally (python3 -c "import yaml; yaml.safe_load(...)").
  • Logic is small enough to reason about by inspection — the only added complexity is a softWrite(operation, fn) helper that distinguishes 403 from other errors.
  • Will be exercised in CI as soon as this PR opens (it's itself a fork PR, so it should self-validate that the new code path is green).

Merge checklist

  • Added/updated tests (N/A — workflow file change; behaviour will be exercised by every PR opened against this repo, including this one)
  • Added/updated documentation (inline comments explaining the soft-fail rationale)
  • Added/updated previews (Storybook)
  • Changes are SSR compatible (N/A — CI workflow change)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge
  • (GitHub staff only) Integration tests pass at github/github-ui

The Recommend integration tests workflow runs on every `pull_request`
event, including PRs opened from forks. When triggered by a fork PR the
provided GITHUB_TOKEN has read-only access to the upstream repo and any
write call (addLabels / createComment) returns:

  HttpError: Resource not accessible by integration (HTTP 403)

That failure surfaces as a red 'recommend' check on every fork PR even
when the underlying source code is fine. It's also misleading: the
job's job is to recommend integration tests, not to gate the PR on its
own infra success.

Fix: wrap the label and comment API calls in a small helper that
catches 403s and logs an actionable message instead of throwing. The
job runs to completion green, and maintainers can apply the
'integration-tests: recommended' label manually if the change warrants
integration testing.

Comment writes are additionally skipped entirely on fork PRs because
the GitHub UI already shows a banner explaining how external
contributors can request review — a bot comment to a fork PR author
who cannot apply labels themselves would just add noise.

This is a CI-only change with no runtime impact, so it does not include
a changeset (per .github/skills/changesets/SKILL.md). The PR needs the
`skip changeset` label applied by a maintainer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 17:35
@ianwinsemius ianwinsemius requested a review from a team as a code owner May 20, 2026 17:35
@ianwinsemius ianwinsemius requested a review from joshblack May 20, 2026 17:35
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

⚠️ No Changeset found

Latest commit: f10835d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

This PR makes the Recommend integration tests GitHub Actions workflow resilient to forked pull requests, where GITHUB_TOKEN is read-only and write operations (labels/comments) otherwise fail with HTTP 403.

Changes:

  • Add a softWrite(operation, fn) helper to catch HTTP 403s from GitHub API write calls and log an informational message instead of failing the job.
  • Detect fork PRs and skip posting the “action required” comment for forks while keeping internal PR behavior (label + comment) intended to remain the same.
Show a summary per file
File Description
.github/workflows/recommend-integration-tests.yml Soft-fails label/comment writes on 403 and suppresses comments for fork PRs to avoid misleading red checks.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +64 to +72
const softWrite = async (operation, fn) => {
try {
await fn()
} catch (error) {
if (error.status === 403) {
core.info(`Skipped ${operation}: GITHUB_TOKEN cannot write to this repository from a forked PR. A maintainer can apply the '${INTEGRATION_LABEL_NAMES.recommended}' label manually if integration tests are warranted.`)
return
}
throw error
@joshblack
Copy link
Copy Markdown
Member

Hi there @ianwinsemius! 👋 Thanks for taking the time to make this PR 🙏

I opened up an alternative idea for this over at: #7862, would this work for you, as well? This should skip the job entirely at the workflow level so you shouldn't run into the case where a Pull Request from a fork has a red status check for this workflow.

Let me know what you think!

@joshblack
Copy link
Copy Markdown
Member

Merged in: #7862 if that works for you @ianwinsemius! Closing this out but feel free to reach out if this isn't addressing the underlying need here 👀

@joshblack joshblack closed this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants