diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..9932261 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,34 @@ +name: Set up pnpm and Node.js +description: Install pnpm and Node.js (.node-version) and the dependencies from the lockfile. + +inputs: + install-scripts: + # Jobs that hold deployment credentials leave this off, so no install + # script ever runs next to a token. + description: '"true" runs the install scripts of dependencies; "false" passes --ignore-scripts.' + required: false + default: "false" + +runs: + using: composite + steps: + - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 + with: + node-version-file: .node-version + cache: pnpm + + - name: Install dependencies + shell: bash + run: | + case "$INSTALL_SCRIPTS" in + true) pnpm install --frozen-lockfile ;; + false) pnpm install --frozen-lockfile --ignore-scripts ;; + *) + echo "install-scripts must be \"true\" or \"false\": $INSTALL_SCRIPTS" >&2 + exit 1 + ;; + esac + env: + INSTALL_SCRIPTS: ${{ inputs.install-scripts }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fbb309..5074a34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,33 +24,21 @@ jobs: with: persist-credentials: false - - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 + - uses: ./.github/actions/setup with: - node-version-file: .node-version - cache: pnpm - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Lint (ESLint, Stylelint) - run: pnpm lint - - - name: Format check (Prettier) - run: pnpm format:check - - - name: Type check (astro check) - run: pnpm check - - - name: Build - run: pnpm build + install-scripts: "true" - - name: HTML validation (html-validate) - run: pnpm test:html + # The installs below run in the background while the checks and the + # build run; their PATH changes take effect only after a wait step. + - id: playwright + name: Install Playwright browser + background: true + run: pnpm exec playwright install --with-deps chromium # Pinned by version and checksum. The tests below use it as well. - - name: Install lychee + - id: lychee + name: Install lychee + background: true run: | archive="lychee-x86_64-unknown-linux-gnu" curl --proto "=https" --tlsv1.2 -fsSLo "${RUNNER_TEMP}/lychee.tar.gz" \ @@ -64,15 +52,36 @@ jobs: LYCHEE_VERSION: 0.24.2 LYCHEE_SHA256: 1f4e0ef7f6554a6ed33dd7ac144fb2e1bbed98598e7af973042fc5cd43951c9a + # The build stays out of this group: astro check writes .astro/ as well. + - parallel: + - name: Lint (ESLint, Stylelint) + run: pnpm lint + + - name: Format check (Prettier) + run: pnpm format:check + + - name: Type check (astro check) + run: pnpm check + + - name: Build + run: pnpm build + + - name: HTML validation (html-validate) + run: pnpm test:html + + - name: Wait for lychee + wait: lychee + - name: Link check (lychee, internal links only) run: pnpm test:links - - name: Install Playwright browser - run: pnpm exec playwright install --with-deps chromium + - name: Wait for the Playwright browser + wait: playwright - name: Accessibility (axe, light/dark x mobile/desktop) run: pnpm test:a11y + # Not alongside the tests: sharing the CPU skews the scores. - name: Lighthouse CI run: pnpm test:lighthouse @@ -131,16 +140,8 @@ jobs: with: persist-credentials: false - - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 - with: - node-version-file: .node-version - cache: pnpm - - # Only wrangler is needed here; no install scripts run next to the token. - - name: Install dependencies - run: pnpm install --frozen-lockfile --ignore-scripts + # Only wrangler is needed here; install scripts stay off next to the token. + - uses: ./.github/actions/setup - name: Download the build uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 @@ -213,16 +214,8 @@ jobs: with: persist-credentials: false - - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 - with: - node-version-file: .node-version - cache: pnpm - - # Only wrangler is needed here; no install scripts run next to the token. - - name: Install dependencies - run: pnpm install --frozen-lockfile --ignore-scripts + # Only wrangler is needed here; install scripts stay off next to the token. + - uses: ./.github/actions/setup - name: Download the build uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index ad5fdd0..f98b6b1 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -27,16 +27,8 @@ jobs: with: persist-credentials: false - - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 - - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 - with: - node-version-file: .node-version - cache: pnpm - - # Only wrangler is needed here; no install scripts run next to the token. - - name: Install dependencies - run: pnpm install --frozen-lockfile --ignore-scripts + # Only wrangler is needed here; install scripts stay off next to the token. + - uses: ./.github/actions/setup # The Worker that holds the Previews; see the preview job in ci.yml. - name: Delete the Preview diff --git a/AGENTS.md b/AGENTS.md index 08e7d24..4f6ed95 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,8 @@ pnpm test:lighthouse # Lighthouse CI(Performance ≥ 0.95、他 3 項目 = 1 - Playwright は `pnpm build` 済みの `dist/client` を検査する。ソースを変えたらビルドし直してから走らせる。 - 単一テスト: `pnpm exec playwright test tests/seo.spec.ts`、名前で絞るなら `-g ""`、プロジェクトを絞るなら `--project=mobile-light`(`{mobile,desktop}-{light,dark}` の 4 つ)。 -- CI(`.github/workflows/ci.yml`)は lint → format:check → check → build → test:html → test:links → test:a11y → test:lighthouse の順に走る。PR テンプレートのチェックリストも同じ項目。 +- CI(`.github/workflows/ci.yml`)は lint・format:check・check を並列に走らせた後、build → test:html → test:links → test:a11y → test:lighthouse の順に走る。Playwright のブラウザと lychee は、その裏で入れる。PR テンプレートのチェックリストも同じ項目。 +- ワークフローの依存の準備(pnpm・Node・install)は composite action `.github/actions/setup` にまとめてある。install スクリプトは既定で動かさず、品質ゲートのジョブだけが `install-scripts: "true"` で動かす。 ## アーキテクチャ diff --git a/docs/deployment.md b/docs/deployment.md index 5263ccb..417a573 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -21,7 +21,7 @@ 2. PR のとき `preview` ジョブ: 1 の artifact を `wrangler preview` で Preview Worker に `pr-<番号>` として上げ、URL を PR にコメントする(同じコメントを更新し続ける) 3. main への push のとき `deploy` ジョブ: 1 の artifact を `wrangler deploy` で本番に上げる -デプロイのジョブはビルドし直さず、検査を通った成果物をそのまま配信します。依存も `--ignore-scripts` で入れ、トークンのある環境では install スクリプトを動かしません。 +デプロイのジョブはビルドし直さず、検査を通った成果物をそのまま配信します。依存の準備は composite action `.github/actions/setup` が行い、既定では `--ignore-scripts` で入れます。install スクリプトを動かすのは、Cloudflare のトークンを持たない `ci` ジョブだけ(`install-scripts: "true"`)です。 デプロイの後には `scripts/check-deployed-headers.mjs` が、配信された URL のレスポンスヘッダーが `dist/client/_headers` の `/*` のルール(CSP を含む)と一致するかを確かめます。デプロイ直後は古い版が応答することがあるため、5 秒間隔で最大 12 回試します(各リクエストのタイムアウトは 10 秒)。workers.dev のホストには `X-Robots-Tag: noindex` があること、kryota.dev には無いことも検査します。