Repository navigation
fix(ci): fail when yarn.lock does not match package.json - #67
Merged
Merged
Conversation
Both workflows install with Yarn 1, which Corepack selects because package.json has no packageManager field. Yarn 1 ignores the unknown --immutable flag, so ui-test rewrote yarn.lock and passed. lint-and-format fell back to the same command when --frozen-lockfile failed, so it passed as well. Install with `yarn install --frozen-lockfile` alone in both workflows, the same command the dev container uses. Document in the README and AGENTS.md that the project uses Yarn 1 and that yarn.lock must be committed with package.json changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
CI の依存のインストールで、
yarn.lockがpackage.jsonと合っていないときにジョブが失敗するようにしました。変更
ui-test.yml・lint-format.ymlの依存のインストールをyarn install --frozen-lockfileだけにしました。ui-testのyarn install --immutableは、Yarn 1 が知らないフラグとして無視し、yarn.lockを書き換えて成功していました。lint-and-formatは、--frozen-lockfileが失敗するとyarn install --immutableに切り替わり、同じく成功していました。yarn.lockも一緒にコミットすること(合っていないと CI が失敗すること)を書きました。例として、
package.jsonのreact-ga4を^3.0.1から^3.0.0に変え、yarn.lockを変えずに push した場合の結果です(GitHub Actions で確かめた結果。下の「検証」を参照)。ui-testyarn.lockを書き換えてテストまで実行)Install dependenciesで失敗lint-and-format--frozen-lockfileが失敗した後、--immutableで書き換えて続行)Install dependenciesで失敗失敗時の出力は
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.です。Yarn の版
各環境で使われる Yarn を確かめ、すべて 1.22.22 でした。
packageManagerは AGENTS.md の方針どおり追加していません。npm のyarnパッケージの latest は 1.22.22 で、Corepack が選ぶ版もこれになります。corepack enableの後、package.jsonにpackageManagerがないため Corepack の既定の Yarn 1 を使うyarn install v1.22.22)node:24-bookwormイメージに入っている Yarn(/usr/local/bin/yarn→/opt/yarn-v1.22.22)。Corepack は有効にしていない開発コンテナ(
docker-compose.yml)と README のホストの手順は、もともとyarn install --frozen-lockfileで、CI と同じコマンドになりました。変更した仕様・設計
CI の依存のインストールの流れを次のように変えました。
flowchart TD subgraph before["変更前"] U1["ui-test: yarn install --immutable"] --> U2["Yarn 1 はフラグを無視し、<br>yarn.lock を書き換えて成功"] L1["lint-and-format: yarn install --frozen-lockfile"] -->|合っている| L3["成功"] L1 -->|yarn.lock の更新が必要| L2["yarn install --immutable で<br>yarn.lock を書き換えて成功"] end subgraph after["変更後(両ジョブ)"] A1["yarn install --frozen-lockfile"] -->|合っている| A2["lint・format・test に進む"] A1 -->|yarn.lock の更新が必要| A3["ジョブが失敗"] endYarn 1 の
--frozen-lockfileは、package.jsonから依存を消してyarn.lockに項目が残っている場合は失敗しません(下の表の「依存を削除」)。このときインストールされるパッケージはpackage.jsonのとおりで、残った項目は使われません。検証
lockfile がずれた状態(ローカル)
開発コンテナ(Yarn 1.22.22)で、
package.jsonとyarn.lockの写しを作り、package.jsonだけを変えて各コマンドを実行しました。値は終了コードと、実行後のyarn.lockが元と同じかどうかです。package.jsonの状態ui-testlint-and-formatreact-ga4を^3.0.0)left-padを1.3.0)react-ga4)lockfile がずれた状態(GitHub Actions)
この PR とは別の一時ブランチに、上の「範囲を変更」のコミットと、そのブランチへの push で CI が動くようにトリガーを足したコミットを push しました。確認後に一時ブランチは削除しました。
ui-testlint-and-formatmain(変更前)そのほか
yarn typecheck・yarn lint・yarn format・yarn test(26 件):成功ui-test・lint-and-format):yarn install --frozen-lockfileで依存を入れ、成功.prettierignoreで.githubとREADME.mdは Prettier の対象外のため、ワークフローは YAML として読み込み、各ジョブのコマンドがyarn install --frozen-lockfileになっていることを確かめました。README.md#development-setup)を確かめました。yarn buildは実行していません。アプリのコードとビルドの設定は変えていないためです。🤖 Generated with Claude Code