Repository navigation
fix(ci): PR の CI が master を検証していた問題を修正し、token 権限を最小化する - #555
Merged
Merged
Conversation
pull_request_target はbaseをcheckoutするためPRの内容が未検証だった。 permissions明示とactions/checkout@v7への統一も同時に行う。
yuiseki
force-pushed
the
fix/ci-run-pr-head-not-base
branch
from
July 29, 2026 23:30
949f856 to
a7a41dc
Compare
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.
問題1: PR の CI が PR の内容を検証していない
test / lint / e2e / generate-pages の4本が
pull_request_targetトリガのため、PR に表示される緑のチェックは PR の内容ではなく master を検証した結果 でした。pull_request_targetではactions/checkoutの既定の対象が base ブランチになります。実際のログで確認しました。PR #553(head =25803b48)の test ジョブ:GitHub の UI 上は
head_branchとhead_shaが PR のものとして表示されるため、見た目では区別できません。副作用として、放置された PR は古い判定を持ち続けます。#544 は 2026-02-17 時点の master を検証した
failureを5か月間表示していました。同じ master に対して 2/13 と 3/4 の run は成功しているので、PR の内容とは無関係な一時的な失敗でした。問題2: token 権限が既定値のまま
どのワークフローにも
permissions:の指定がなく、リポジトリ既定値の token 権限で走っていました。問題1と組み合わさると影響が大きくなります。修正
トリガ
4本を
pull_requestに変更します。pull_request_targetにref: ${{ github.event.pull_request.head.sha }}を足すのは 避けるべきです。base リポジトリの文脈で書き込み可能な token 付きに fork の任意のコードを持ち込むことになります。GitHub 自身もこれを問題として扱っており、actions/checkout v7.0.0(2026-06-18)でpull_request_target/workflow_runからの fork PR チェックアウトを既定でブロックし、2026-07-20 に v4.4.0 / v5.1.0 / v6.1.0 へ BREAKING change として backport しています。参考: https://github.blog/changelog/2026-06-18-safer-pull_request_target-defaults-for-github-actions-checkout/
この4本は secrets を参照していないので
pull_requestで足ります。permissions
contents: readcontents: write(peaceiris/actions-gh-pagesが gh-pages ブランチへ push するため。同 action の README が要求する権限)actions/upload-artifactはACTIONS_RUNTIME_TOKENを使うのでcontents: readで足ります。actions/checkout
v2 / v3 / v4 が混在していたので v7 に統一します。v7 は node24 ランタイムで、Actions Runner v2.327.1 以上を要求します(GitHub ホストランナーは満たしています)。v2 は Node 16 で、すでにサポート対象外です。
影響
この PR 自体の検証について
この PR の CI は変更前の設定(= master を検証)で走るため、この PR 自体の CI 結果は変更の正しさを示しません。
マージ後、最初の PR のログで
git checkoutの対象が PR の head sha になること、および gh-pages のデプロイが成功することを確認してください。この PR に含めていないもの
gh-pages.ymlのnode-version: '20.10.0'直書き(他4本は.node-version参照)。Node 20 はすでに EOL なので、別途対応が必要ですactions/setup-node@v4/actions/cache@v4/actions/upload-artifact@v4の更新