ci: fix fork-PR workflow permissions#131
Merged
Merged
Conversation
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.
|
📦 Build artifact for this PR is available in the GitHub Actions workflow run under Artifacts. |
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 ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
PR Build and Commentworkflow is failing on fork PRs (e.g. #130 fromecho-layker/apilot) with:Root cause: For PRs triggered on the
pull_requestevent from a fork, GitHub forces theGITHUB_TOKENto read-only regardless of thepermissions:block. The failing run showsIssues: 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:pr-package.ymlcontinue-on-erroron both comment stepsgo buildon PR code → must stay onpull_request(switching topull_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.ymlpull_request→pull_request_targetgithub-scriptAPI calls only, no PR code. Gets a write token so labels work on fork PRs.pr-release.ymlpull_request→pull_request_target, explicit PR-head fetch, branch name moved toenvpull_request_targetchecks out the base branch by default, so fetch PR head explicitly (pull/N/head—Nis a controlled integer). Branch name is attacker-controlled, so move it toenv: BRANCH_NAMEto prevent script injection.No source code changes — CI config only.