Skip to content

ci: fix fork-PR workflow permissions#131

Merged
tangcent merged 1 commit into
mainfrom
ci/fork-pr-permissions
Jun 22, 2026
Merged

ci: fix fork-PR workflow permissions#131
tangcent merged 1 commit into
mainfrom
ci/fork-pr-permissions

Conversation

@tangcent

Copy link
Copy Markdown
Owner

Problem

The PR Build and Comment workflow is failing on fork PRs (e.g. #130 from echo-layker/apilot) with:

Resource not accessible by integration

Root cause: For PRs triggered on the pull_request event from a fork, GitHub forces the GITHUB_TOKEN to read-only regardless of the permissions: block. The failing run shows Issues: read, PullRequests: read, so every write step (comments, labels, PR-body updates) fails.

Fix

Mirrors the fix already shipped in easy-yapi — 9bbcd67 + 24c004f — tailored per workflow depending on whether it executes PR-supplied code:

Workflow Change Why
pr-package.yml continue-on-error on both comment steps Runs go build on PR code → must stay on pull_request (switching to pull_request_target + checking out PR head would run untrusted code with a write token). Build/artifact upload still runs; only the impossible-on-fork comments are skipped.
auto-label.yml pull_requestpull_request_target github-script API calls only, no PR code. Gets a write token so labels work on fork PRs.
pr-release.yml pull_requestpull_request_target, explicit PR-head fetch, branch name moved to env No build of PR code, safe to elevate. pull_request_target checks out the base branch by default, so fetch PR head explicitly (pull/N/headN is a controlled integer). Branch name is attacker-controlled, so move it to env: BRANCH_NAME to prevent script injection.

No source code changes — CI config only.

For fork PRs the GITHUB_TOKEN is forced read-only on the pull_request
event, causing write steps (comments, labels, PR-body updates) to fail
with 'Resource not accessible by integration'. Apply the same fix used
in easy-yapi (9bbcd67, 24c004f), tailored per workflow:

- pr-package.yml: runs go build on PR code, so keep pull_request but
  add continue-on-error to the comment steps. The build/artifact
  upload still runs; only the impossible-on-fork comments are skipped.
- auto-label.yml: github-script only (no PR code), switch to
  pull_request_target to get a write token for labelling fork PRs.
- pr-release.yml: git log + API only, switch to pull_request_target,
  fetch PR head explicitly, and move the branch name into an env var
  to prevent script injection from attacker-controlled branch names.
@github-actions

Copy link
Copy Markdown

📦 Build artifact for this PR is available in the GitHub Actions workflow run under Artifacts.

@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@tangcent tangcent merged commit 1c5c3e2 into main Jun 22, 2026
51 checks passed
@tangcent tangcent deleted the ci/fork-pr-permissions branch June 22, 2026 14:41
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.

2 participants