ci(gates): merge job 셋이 의존성 캐시에서 설치를 시작하고 main만 저장한다 #41
@@ -41,10 +41,34 @@ jobs:
|
||||
if: ${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
env:
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: ${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: ${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
@@ -85,10 +109,34 @@ jobs:
|
||||
# FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
env:
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: ${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: ${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
@@ -131,10 +179,33 @@ jobs:
|
||||
image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
env:
|
||||
CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: ${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: ${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-${{ runner.os }}-${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
+3
-1
@@ -21,14 +21,16 @@ Gitea runner에서 merge 단계를 초록으로 만들고, worker를 늘리지
|
||||
- merge / browser tests job이 Playwright 공식 이미지(`config/ci/gates.json`의 `browser-install.image`, digest 고정)에서 돈다. `@playwright/test`를 올릴 때 이 digest도 같은 버전으로 바꾼다(`tests/unit/ci-browser-image.test.ts`가 막는다).
|
||||
- devDependencies에서 `dependency-cruiser`가 빠진다. 그 CLI를 따로 쓰고 있었으면 다시 더한다.
|
||||
- 선택 runtime 제거 드릴 셋이 merge의 FE-GATE-020에서 main 단계의 새 게이트 FE-GATE-030으로 옮는다. main job 이름이 `main / self-tests and removal drills`로 바뀐다. 그 이름을 필수 검사로 걸었으면 바꾼다. 선택 runtime을 바꾸는 PR은 `scripts/verify.sh gate FE-GATE-030`을 직접 돌린다.
|
||||
- merge job 셋이 runner의 actions/cache 저장소에서 Node·corepack·pnpm store와 메타데이터 캐시를 복원하고, main run만 저장한다. runner에 캐시 서버가 없으면 복원 단계가 경고만 내고 설치가 그대로 돈다. 자기 runner의 캐시 크기 상한을 확인한다(항목 하나가 압축 전 약 0.7GB, lockfile이 바뀔 때마다 새 항목).
|
||||
|
||||
### 보안·계약 변경
|
||||
|
||||
| 표시 | 변경 | 영향 경로 | 커밋 |
|
||||
| --- | --- | --- | --- |
|
||||
| [계약] | 게이트 필드 `hostEnvironment`(`"system-container"`)를 더한다. 생성기와 `scripts/verify.sh`가 그 게이트를 `scripts/run-in-system-container.sh`로 감싸고, 실행 검사는 계약이 정한 접두어로 돈 줄만 센다. FE-GATE-013에 준다 | `config/ci/gates.json`, `scripts/contracts/ci-gates.ts`, `scripts/generate-ci-workflow.ts`, `scripts/verify.sh`, `scripts/run-in-system-container.sh`, `config/ci/system-container.Dockerfile` | `1d3eb901` |
|
||||
| [계약] | 게이트 FE-GATE-030 `optional-removability`(main 단계)를 더하고 FE-GATE-020에서 선택 runtime 제거 드릴 셋을 옮긴다. 정규 게이트 ID는 001..030, MAIN_READY는 029·030, 계약 보고서 `gateCount`는 29다(소유자 결정 2026-11-12) | `config/ci/gates.json`, `scripts/contracts/ci-gates.ts`, `scripts/lib/promotion-readiness.ts`, `scripts/lib/ci-contract-report.ts`, `scripts/lib/feature-scaffold-drill.ts` | `8de1403b` |
|
||||
| [계약] | 게이트 FE-GATE-030 `optional-removability`(main 단계)를 더하고 FE-GATE-020에서 선택 runtime 제거 드릴 셋을 옮긴다. 정규 게이트 ID는 001..030, MAIN_READY는 029·030, 계약 보고서 `gateCount`는 29다(권하는 안으로 정함 2026-11-12, 총괄) | `config/ci/gates.json`, `scripts/contracts/ci-gates.ts`, `scripts/lib/promotion-readiness.ts`, `scripts/lib/ci-contract-report.ts`, `scripts/lib/feature-scaffold-drill.ts` | `8de1403b` |
|
||||
| [계약] | `browser-install` 단계에 `image`(Playwright 레지스트리 noble 태그 + digest)를 더한다. 생성기는 그 job의 container와 job env `CI_RUNNER_IMAGE`로 그리고, 단계는 글꼴만 설치한다. gate-sequence job에만 둔다 | 같은 파일, `tests/unit/ci-browser-image.test.ts` | `92abfd20` |
|
||||
| [계약] | job 단계 `dependency-cache`와 CI action `cache`(actions/cache v4.3.0, 짝 백엔드와 같은 pin)를 더한다. merge job 셋에만 두고(계약이 다른 job을 거절), 생성기가 main 복원·저장과 그 밖 복원만 두 단계, job env `COREPACK_HOME`·`PNPM_CONFIG_STORE_DIR`·`PNPM_CONFIG_CACHE_DIR`로 그린다. `scripts/run-in-system-container.sh`가 그 store와 메타데이터 캐시를 컨테이너에 넘긴다(권하는 안으로 정함 2026-11-13, 총괄) | `config/ci/gates.json`, `scripts/contracts/ci-gates.ts`, `scripts/generate-ci-workflow.ts`, `scripts/run-in-system-container.sh`, `.gitea/workflows/quality-gates.yml` | `7ed0af3d` |
|
||||
|
||||
### 그 밖의 변경
|
||||
|
||||
|
||||
@@ -2158,6 +2158,9 @@
|
||||
{
|
||||
"kind": "checkout"
|
||||
},
|
||||
{
|
||||
"kind": "dependency-cache"
|
||||
},
|
||||
{
|
||||
"kind": "setup-node"
|
||||
},
|
||||
@@ -2199,6 +2202,9 @@
|
||||
{
|
||||
"kind": "checkout"
|
||||
},
|
||||
{
|
||||
"kind": "dependency-cache"
|
||||
},
|
||||
{
|
||||
"kind": "setup-node"
|
||||
},
|
||||
@@ -2239,6 +2245,9 @@
|
||||
{
|
||||
"kind": "checkout"
|
||||
},
|
||||
{
|
||||
"kind": "dependency-cache"
|
||||
},
|
||||
{
|
||||
"kind": "setup-node"
|
||||
},
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
"agent-harness": "에이전트 하네스 파일(tests/unit/template-contract-documents.test.ts)",
|
||||
"feature-typecheck": "기능 코드와 기능 시험을 타입 검사하는 tsconfig(tests/unit/manual-code-blocks.test.ts)",
|
||||
"product-typecheck": "제품 사본을 타입 검사하는 tsconfig(tests/unit/product-extension-typecheck.test.ts)",
|
||||
"app-typecheck": "앱 프로그램 tsconfig와 그 기반 설정(tests/unit/two-feature-install-typecheck.test.ts)"
|
||||
"app-typecheck": "앱 프로그램 tsconfig와 그 기반 설정(tests/unit/two-feature-install-typecheck.test.ts)",
|
||||
"dependency-cache-key": "merge job 의존성 캐시의 키를 정하는 입력(scripts/contracts/ci-gates.ts의 DEPENDENCY_CACHE)"
|
||||
},
|
||||
"entries": [
|
||||
{
|
||||
@@ -105,7 +106,7 @@
|
||||
"kind": "tool-convention",
|
||||
"role": "Node 버전",
|
||||
"readBy": "nvm, CI",
|
||||
"sets": ["fixture-copy", "secret-scan"]
|
||||
"sets": ["fixture-copy", "secret-scan", "dependency-cache-key"]
|
||||
},
|
||||
{
|
||||
"path": ".release",
|
||||
@@ -285,7 +286,7 @@
|
||||
"kind": "tool-convention",
|
||||
"role": "잠금 파일",
|
||||
"readBy": "pnpm, 공급망 생성",
|
||||
"sets": ["fixture-copy", "secret-scan", "scale-source", "package-manifest"]
|
||||
"sets": ["fixture-copy", "secret-scan", "scale-source", "package-manifest", "dependency-cache-key"]
|
||||
},
|
||||
{
|
||||
"path": "pnpm-workspace.yaml",
|
||||
|
||||
@@ -8,10 +8,21 @@
|
||||
출력을 거절한다. `corepack pnpm check:ci`는 산출물 schema 검사, 타입이 있는 계약 검사기,
|
||||
이 workflow drift 검사를 돈다. merge 단계는 job 셋(`merge_static`, `merge_test`,
|
||||
`merge_browser`)으로 돌고 job마다 설치를 한 번 한다. 게이트마다 ID 이름의 step이 하나씩
|
||||
있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다. 검사기 자신의 음성 fixture와
|
||||
있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다.
|
||||
|
||||
merge job 셋만 의존성 캐시를 쓴다(권하는 안으로 정함 2026-11-13, 총괄). setup-node 앞에서
|
||||
Node toolcache, corepack이 받은 pnpm, pnpm store와 메타데이터 캐시를 `.nvmrc`와
|
||||
`pnpm-lock.yaml` 해시 키로 복원한다. 저장은 main run만 한다. 캐시 항목은 다음 run이 믿는
|
||||
입력이다. pnpm은 같은 lockfile의 공급망 검증 기록이 캐시에 있으면 검증을 다시 하지 않는다.
|
||||
그래서 브랜치 run은 복원만 한다. frozen install은 캐시가 맞든 없든 늘 돈다. 항목이 없거나
|
||||
깨지면 pnpm이 모자란 패키지만 내려받고 node_modules는 같다. FE-GATE-013의 시스템 컨테이너도
|
||||
같은 store와 메타데이터 캐시를 받는다. release·promotion·provider job은 공급망 증거를
|
||||
만들므로 매번 새로 설치한다. 이 규칙은 `scripts/contracts/ci-gates.ts`의 `DEPENDENCY_CACHE`와
|
||||
계약 검사가 지킨다. runner의 캐시 저장소는 짝 백엔드와 함께 쓰고 크기 상한이 있다(platform-core
|
||||
`infrastructure/ci/gitea-runner/config.yaml`). 검사기 자신의 음성 fixture와
|
||||
gating 검사는 branch에 push한 뒤 main 단계(`main_gate`, FE-GATE-029)에서 돈다. 선택 runtime
|
||||
제거 드릴 셋(FE-GATE-030)도 main 단계에서 돈다. PR runner 시간 약 30분 가운데 7분쯤이라
|
||||
merge에서 뺐고, 실패하면 main이 빨강이 되어 다음 PR이 고친다(소유자 결정 2026-11-12). release와
|
||||
merge에서 뺐고, 실패하면 main이 빨강이 되어 다음 PR이 고친다(권하는 안으로 정함 2026-11-12, 총괄). release와
|
||||
production 게이트는 matrix check로 남는다. 실패를 무시하는(soft-fail) 연결은 없다.
|
||||
같은 PR이나 같은 브랜치에 새 push가 오면 workflow `concurrency`가 앞 run을 취소한다. Gitea는
|
||||
앞 run의 대기 중인 job은 언제나, 돌고 있는 job은 `cancel-in-progress`가 참일 때 취소한다.
|
||||
|
||||
@@ -70,7 +70,8 @@
|
||||
| round9 R9-D10 예산과 advisory | 2026-11-12 | 권하는 안으로 정함(2026-11-12, 총괄). D1을 먼저 정한다: zod·react-router 갱신이 지금 초기 JS 예산 안에 들어가므로 갱신하고, 드릴을 다시 재서 D9 규칙으로 예산을 정한다. 버린 안: 예산만 먼저 내림 | 같음, 1106/15-01, 1103/13-03 |
|
||||
| round9 R9-D11 `@a11y` 두 번 실행 | 2026-11-12 | 권하는 안으로 정함(2026-11-12, 총괄). 그대로 둔다. 게이트마다 증거를 새로 만드는 계약이다. 결함 아님으로 닫는다. 버린 안: FE-GATE-009가 FE-GATE-008 결과를 쓰기 | 같음, 1112/03-10 |
|
||||
| round9 R9-D12 CSS·라우트 lazy 합 예산 | 2026-11-12 | 권하는 안으로 정함(2026-11-12, 총괄). 지금 값을 기록만 하고 예산은 두지 않는다. 다시 볼 때: 첫 공개 기능 라우트 lab. 버린 안: 예산 신설 | 같음, 1101/15-03 |
|
||||
| 결정 p 선택 runtime 제거 드릴을 main 단계로 | 2026-11-12 | FE-GATE-020의 선택 runtime 제거 드릴 셋(optional recipe, browser file/storage, realtime)을 새 게이트 FE-GATE-030으로 떼어 main 단계(`main_gate`)에서 돌린다. 기능 드릴(샘플 제거, scaffold)은 merge에 남는다. 이유: runner PR 1회 약 30분 가운데 7분쯤이고, worker를 늘리지 않고 merge 25분 목표에 닿는 길이 이것뿐이었다. 대가: 그 셋의 회귀를 병합 뒤 main run에서 본다. main이 빨강이면 다음 PR이 고친다. 짝 백엔드가 무거운 lane을 nightly로 옮긴 것과 같은 모양이다. 재검토: runner가 늘거나 드릴이 빨라져 merge에 다시 넣어도 25분 안이면 되돌린다 | 소유자 결정 p(2026-11-12, design-docs `template-program/README.md` 5절, W2-FE의 O1 권하는 안 채택) |
|
||||
| 결정 p 선택 runtime 제거 드릴을 main 단계로 | 2026-11-12 | FE-GATE-020의 선택 runtime 제거 드릴 셋(optional recipe, browser file/storage, realtime)을 새 게이트 FE-GATE-030으로 떼어 main 단계(`main_gate`)에서 돌린다. 기능 드릴(샘플 제거, scaffold)은 merge에 남는다. 이유: runner PR 1회 약 30분 가운데 7분쯤이고, worker를 늘리지 않고 merge 25분 목표에 닿는 길이 이것뿐이었다. 대가: 그 셋의 회귀를 병합 뒤 main run에서 본다. main이 빨강이면 다음 PR이 고친다. 짝 백엔드가 무거운 lane을 nightly로 옮긴 것과 같은 모양이다. 재검토: runner가 늘거나 드릴이 빨라져 merge에 다시 넣어도 25분 안이면 되돌린다 | 권하는 안으로 정함(2026-11-12, 총괄): 백엔드 nightly lane과 같은 모양(design-docs `template-program/README.md` 5절 p, w2-fe-2가 올린 O1) |
|
||||
| 의존성 캐시는 merge job만 | 2026-11-13 | merge job 셋(`merge_static`·`merge_test`·`merge_browser`)만 Node toolcache·corepack·pnpm store와 메타데이터 캐시를 `.nvmrc`·`pnpm-lock.yaml` 해시 키로 복원하고, 저장은 main run만 한다. release·promotion·provider job은 공급망 증거를 만들므로 매번 새로 설치한다. 이유: worker를 늘리지 않고 job마다 되풀이하던 내려받기와 공급망 검증 요청을 없앤다. 캐시가 없거나 깨져도 frozen install이 같은 node_modules를 만든다. 짝 백엔드의 JDK·Gradle·Trivy 캐시와 같은 저장 규칙이다. 버린 안: CI 이미지에 의존성을 굽기(레지스트리 쓰기 토큰이 든다). 규칙의 정본은 `scripts/contracts/ci-gates.ts`의 `DEPENDENCY_CACHE` | 권하는 안으로 정함(2026-11-13, 총괄): 의존성 캐시는 merge job만, 공급망 증거 job은 매번 새로 설치 |
|
||||
| 구조·기술 결정 기록 | 2026-07-26~ | `VD-01`~(빈 번호 있음) | `docs/adr/` |
|
||||
|
||||
## 3. 결정 대기 쓰는 법
|
||||
|
||||
@@ -114,7 +114,7 @@ src/ 최상위 폴더 ── 역할: docs/architecture/layers.md 표
|
||||
|
||||
## 12. 제거 가능성
|
||||
|
||||
지울 수 있는 단위는 드릴이 지킨다. 기능 드릴(샘플 제거, 생성 기능의 scaffold·제거)은 merge 게이트 FE-GATE-020, 선택 runtime 제거 드릴 셋(optional recipe, browser file/storage, realtime)은 main 단계 FE-GATE-030이다(소유자 결정 2026-11-12). 드릴 목록은 `config/ci/gates.json`의 두 게이트 `commandIds`다. 선택 runtime을 바꾼 PR은 merge에서 FE-GATE-030이 돌지 않으니 `scripts/verify.sh gate FE-GATE-030`을 직접 돌린다.
|
||||
지울 수 있는 단위는 드릴이 지킨다. 기능 드릴(샘플 제거, 생성 기능의 scaffold·제거)은 merge 게이트 FE-GATE-020, 선택 runtime 제거 드릴 셋(optional recipe, browser file/storage, realtime)은 main 단계 FE-GATE-030이다(권하는 안으로 정함 2026-11-12, 총괄). 드릴 목록은 `config/ci/gates.json`의 두 게이트 `commandIds`다. 선택 runtime을 바꾼 PR은 merge에서 FE-GATE-030이 돌지 않으니 `scripts/verify.sh gate FE-GATE-030`을 직접 돌린다.
|
||||
|
||||
- 구조를 바꾸면 드릴을 돌린다. 드릴 fixture가 복사하는 목록(`scripts/lib/removal-fixture.ts`, 이 목록 하나만 쓴다)이 바뀐 구조를 아는지 본다. 그 목록에 `README.md`·`CHANGELOG.md`가 없어 드릴 넷 중 셋이 항상 실패한 일이 있다(결함 패턴 G11).
|
||||
- 드릴은 오래 걸린다(desktop 2026-11-13 실측: FE-GATE-020과 FE-GATE-030 합쳐 약 10분 30초). desktop에서 잠금 아래 돌린다.
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
import { DEPENDENCY_ADVISORIES_RECORD_PATH } from "../lib/dependency-advisories.ts";
|
||||
import { selectRepositoryPaths } from "../lib/repository-layout.ts";
|
||||
import { PROMOTION_FORMULA } from "../lib/promotion-readiness.ts";
|
||||
import {
|
||||
RELEASE_CANDIDATE_EVIDENCE_PATHS,
|
||||
@@ -39,6 +40,7 @@ const ciActionRegistrySchema = z
|
||||
setupNode: ciActionRegistrationSchema,
|
||||
uploadArtifact: ciActionRegistrationSchema,
|
||||
downloadArtifact: ciActionRegistrationSchema,
|
||||
cache: ciActionRegistrationSchema,
|
||||
})
|
||||
.strict()
|
||||
.readonly();
|
||||
@@ -78,6 +80,12 @@ export const CI_ACTION_REGISTRY = parseCiActionRegistry({
|
||||
revision: "75635f32b4c1c41c4b3d64e8f85210112ed4c9c7",
|
||||
version: "v4 branch",
|
||||
},
|
||||
// The same pin as the paired backend's JDK, Gradle and Trivy caches.
|
||||
cache: {
|
||||
repository: "https://github.com/actions/cache",
|
||||
revision: "0057852bfaa89a56745cba8c7296529d2fc39830",
|
||||
version: "v4.3.0",
|
||||
},
|
||||
});
|
||||
|
||||
const actionIdByStepKind = Object.freeze({
|
||||
@@ -85,6 +93,7 @@ const actionIdByStepKind = Object.freeze({
|
||||
"setup-node": "setupNode",
|
||||
upload: "uploadArtifact",
|
||||
download: "downloadArtifact",
|
||||
"dependency-cache": "cache",
|
||||
} as const satisfies Readonly<Record<string, CiActionId>>);
|
||||
|
||||
export function resolveCiActionUses(actionId: CiActionId): string {
|
||||
@@ -93,6 +102,42 @@ export function resolveCiActionUses(actionId: CiActionId): string {
|
||||
return `${action.repository}@${action.revision}`;
|
||||
}
|
||||
|
||||
/** An action a registered repository holds below its root (`actions/cache/restore`), at the same pin. */
|
||||
export function resolveCiSubActionUses(actionId: CiActionId, subpath: "restore"): string {
|
||||
const action = CI_ACTION_REGISTRY[actionId];
|
||||
if (!action) throw new TypeError(`unknown CI action: ${String(actionId)}`);
|
||||
return `${action.repository}/${subpath}@${action.revision}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decision (2026-11-13, lead): the dependency cache is for the merge jobs
|
||||
* only; the jobs that produce supply-chain evidence install fresh every time
|
||||
* (docs/work/reference/decisions.md). A merge job restores the Node toolcache, the corepack
|
||||
* download and pnpm's store and metadata cache (with its record of the
|
||||
* lockfile's supply-chain verification) before setup-node, keyed by
|
||||
* `.nvmrc` and the lockfile. Only a run on main saves an entry, the paired
|
||||
* backend's rule for its caches: an entry is trusted input to the next run
|
||||
* (the verification record lets pnpm skip the check), so a branch must not
|
||||
* write one. The frozen install always runs after it: a missing or damaged
|
||||
* entry only makes pnpm download what it lacks, and node_modules is the same
|
||||
* (desktop, 2026-11-13: cold 13.9 s, warm 1.6 s, 40 broken store and 40
|
||||
* broken metadata files 3.6 s with 27 packages fetched again; the same tree
|
||||
* hash in all five installs).
|
||||
*/
|
||||
export const DEPENDENCY_CACHE = Object.freeze({
|
||||
keyPrefix: "fe-dependencies-${{ runner.os }}-${{ runner.arch }}-",
|
||||
// `.nvmrc` and `pnpm-lock.yaml` (config/repository-layout.json).
|
||||
keyInputs: selectRepositoryPaths("dependency-cache-key"),
|
||||
paths: Object.freeze(["/opt/hostedtoolcache/node", "/tmp/fe-dependency-cache"] as const),
|
||||
environment: Object.freeze([
|
||||
Object.freeze({ name: "COREPACK_HOME", value: "/tmp/fe-dependency-cache/corepack" }),
|
||||
Object.freeze({ name: "PNPM_CONFIG_STORE_DIR", value: "/tmp/fe-dependency-cache/pnpm-store" }),
|
||||
Object.freeze({ name: "PNPM_CONFIG_CACHE_DIR", value: "/tmp/fe-dependency-cache/pnpm-cache" }),
|
||||
]),
|
||||
/** The jobs that may hold the step: the three merge jobs. */
|
||||
jobIds: Object.freeze(["merge_static", "merge_test", "merge_browser"] as const),
|
||||
});
|
||||
|
||||
export function resolveCiStepActionUses(stepKind: string): string | null {
|
||||
const actionId = actionIdByStepKind[stepKind as keyof typeof actionIdByStepKind];
|
||||
return actionId ? resolveCiActionUses(actionId) : null;
|
||||
@@ -333,6 +378,7 @@ const environmentBindingSchema = z
|
||||
const checkoutStep = z.object({ kind: z.literal("checkout") }).strict();
|
||||
const setupNodeStep = z.object({ kind: z.literal("setup-node") }).strict();
|
||||
const frozenInstallStep = z.object({ kind: z.literal("frozen-install") }).strict();
|
||||
const dependencyCacheStep = z.object({ kind: z.literal("dependency-cache") }).strict();
|
||||
/**
|
||||
* `image`: the job runs in Playwright's own image for the pinned
|
||||
* @playwright/test version, which already holds the browsers and their OS
|
||||
@@ -405,6 +451,7 @@ const deployStep = z
|
||||
|
||||
const jobStepSchema = z.discriminatedUnion("kind", [
|
||||
checkoutStep,
|
||||
dependencyCacheStep,
|
||||
setupNodeStep,
|
||||
frozenInstallStep,
|
||||
browserInstallStep,
|
||||
@@ -817,6 +864,16 @@ function validateContractSemantics(
|
||||
}
|
||||
}
|
||||
validateJobStepKinds(job, issue);
|
||||
if (job.steps.some(({ kind }) => kind === "dependency-cache")) {
|
||||
if (!(DEPENDENCY_CACHE.jobIds as readonly string[]).includes(job.id)) {
|
||||
issue(`the dependency cache is for the merge jobs only: ${job.id}`);
|
||||
}
|
||||
for (const { name } of DEPENDENCY_CACHE.environment) {
|
||||
if (job.environment.some((binding) => binding.name === name)) {
|
||||
issue(`job ${job.id} binds ${name}, which its dependency cache sets`);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const step of job.steps) {
|
||||
const uses = resolveCiStepActionUses(step.kind);
|
||||
if (uses && !/^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+@[0-9a-f]{40}$/u.test(uses)) {
|
||||
@@ -910,9 +967,9 @@ function validateContractSemantics(
|
||||
}
|
||||
}
|
||||
const expectedStepKinds: Readonly<Record<string, readonly CiWorkflowStep["kind"][]>> = {
|
||||
merge_static: ["checkout", "setup-node", "frozen-install", "run-gate", "upload"],
|
||||
merge_test: ["checkout", "setup-node", "frozen-install", "run-gate", "upload"],
|
||||
merge_browser: ["checkout", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"],
|
||||
merge_static: ["checkout", "dependency-cache", "setup-node", "frozen-install", "run-gate", "upload"],
|
||||
merge_test: ["checkout", "dependency-cache", "setup-node", "frozen-install", "run-gate", "upload"],
|
||||
merge_browser: ["checkout", "dependency-cache", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"],
|
||||
release_gate: ["checkout", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"],
|
||||
immutable_build: ["checkout", "setup-node", "frozen-install", "run-gate", "archive-candidate", "upload", "upload"],
|
||||
vulnerability_provider: ["checkout", "setup-node", "frozen-install", "download", "run-provider", "validate-provider-evidence", "upload"],
|
||||
@@ -1324,7 +1381,7 @@ function validateJobStepKinds(
|
||||
): void {
|
||||
const allowed: Readonly<Record<z.infer<typeof jobSchema>["kind"], ReadonlySet<string>>> = {
|
||||
"gate-matrix": new Set(["checkout", "setup-node", "frozen-install", "browser-install", "download", "extract", "run-gate", "upload"]),
|
||||
"gate-sequence": new Set(["checkout", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"]),
|
||||
"gate-sequence": new Set(["checkout", "dependency-cache", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"]),
|
||||
"gate-single": new Set(["checkout", "setup-node", "frozen-install", "run-gate", "upload"]),
|
||||
immutable: new Set(["checkout", "setup-node", "frozen-install", "run-gate", "archive-candidate", "upload"]),
|
||||
provider: new Set(["checkout", "setup-node", "frozen-install", "download", "extract", "run-provider", "validate-provider-evidence", "upload"]),
|
||||
|
||||
@@ -11,9 +11,11 @@ import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
|
||||
import {
|
||||
DEPENDENCY_CACHE,
|
||||
indexCiGateContract,
|
||||
loadCiGateContract,
|
||||
resolveCiStepActionUses,
|
||||
resolveCiSubActionUses,
|
||||
type CiGateContract,
|
||||
type CiWorkflowJob,
|
||||
type CiWorkflowStep,
|
||||
@@ -234,9 +236,16 @@ function renderJob(
|
||||
const jobEnvironment = job.environment.filter((binding) => !isStepScopedSecret(job, binding));
|
||||
// The build records the image it ran in (scripts/lib/build-environment.ts):
|
||||
// a job in its own image names that one, not the runner label's.
|
||||
// Every pnpm and corepack call of the job reads the cached directories, the
|
||||
// install and the system container's own install alike.
|
||||
const cacheEnvironment = job.steps.some(({ kind }) => kind === "dependency-cache")
|
||||
? DEPENDENCY_CACHE.environment
|
||||
: [];
|
||||
const environmentLines = [
|
||||
...(image ? [` CI_RUNNER_IMAGE: ${yamlScalar(image)}`] : []),
|
||||
...jobEnvironment.map((binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`),
|
||||
...[...cacheEnvironment, ...jobEnvironment].map(
|
||||
(binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`,
|
||||
),
|
||||
];
|
||||
if (environmentLines.length > 0) lines.push(" env:", ...environmentLines);
|
||||
if (job.kind === "gate-matrix") {
|
||||
@@ -316,6 +325,29 @@ function renderStep(
|
||||
" with:",
|
||||
" node-version-file: .nvmrc",
|
||||
];
|
||||
case "dependency-cache": {
|
||||
// DEPENDENCY_CACHE: main restores and saves, every other ref restores.
|
||||
// The frozen install after it runs either way.
|
||||
const inputs = DEPENDENCY_CACHE.keyInputs.map((file) => `'${file}'`).join(", ");
|
||||
const cache = [
|
||||
" with:",
|
||||
" path: |",
|
||||
...DEPENDENCY_CACHE.paths.map((cachePath) => ` ${cachePath}`),
|
||||
` key: ${DEPENDENCY_CACHE.keyPrefix}\${{ hashFiles(${inputs}) }}`,
|
||||
" restore-keys: |",
|
||||
` ${DEPENDENCY_CACHE.keyPrefix}`,
|
||||
];
|
||||
return [
|
||||
" - name: Restore and save the dependency cache",
|
||||
" if: ${{ gitea.ref == 'refs/heads/main' }}",
|
||||
` uses: ${requiredStepActionUses(step.kind)}`,
|
||||
...cache,
|
||||
" - name: Restore the dependency cache",
|
||||
" if: ${{ gitea.ref != 'refs/heads/main' }}",
|
||||
` uses: ${resolveCiSubActionUses("cache", "restore")}`,
|
||||
...cache,
|
||||
];
|
||||
}
|
||||
case "frozen-install":
|
||||
return [
|
||||
" - name: Frozen install",
|
||||
|
||||
@@ -32,6 +32,7 @@ export const REPOSITORY_LAYOUT_SETS = Object.freeze([
|
||||
"feature-typecheck",
|
||||
"product-typecheck",
|
||||
"app-typecheck",
|
||||
"dependency-cache-key",
|
||||
] as const);
|
||||
export type RepositoryLayoutSet = (typeof REPOSITORY_LAYOUT_SETS)[number];
|
||||
|
||||
|
||||
@@ -25,6 +25,15 @@ node_root=$(dirname "$(dirname "$(command -v node)")")
|
||||
corepack_home=${COREPACK_HOME:-$HOME/.cache/node/corepack}
|
||||
# The environment the gate reads (scripts/verify.sh ci_env, the workflow's global env).
|
||||
pass_env=(CI VITE_BUILD_ID VITE_COMMIT_SHA RELEASE_ID CI_RUNNER_IMAGE SOURCE_DATE_EPOCH APP_PROFILE RELEASE_TARGET)
|
||||
# A merge job's dependency cache (scripts/contracts/ci-gates.ts DEPENDENCY_CACHE): pnpm's store and metadata
|
||||
# cache go in at the same paths, so the install in here reuses what the job's install fetched.
|
||||
pnpm_dirs=()
|
||||
for name in PNPM_CONFIG_STORE_DIR PNPM_CONFIG_CACHE_DIR; do
|
||||
if [ -n "${!name:-}" ] && [ -d "${!name}" ]; then
|
||||
pass_env+=("$name")
|
||||
pnpm_dirs+=("${!name}")
|
||||
fi
|
||||
done
|
||||
|
||||
say() { echo "system-container: $*" >&2; }
|
||||
fail() { say "$*"; exit 3; }
|
||||
@@ -68,6 +77,10 @@ else
|
||||
fi
|
||||
tar -C "$node_root" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/node && tar -C /opt/node --no-same-owner -xf -' \
|
||||
|| fail "copying node failed"
|
||||
for dir in "${pnpm_dirs[@]}"; do
|
||||
tar -C "$dir" -cf - . | $docker exec -i "$cid" sh -c "mkdir -p '$dir' && tar -C '$dir' --no-same-owner -xf -" \
|
||||
|| fail "copying $dir failed"
|
||||
done
|
||||
if [ -d "$corepack_home" ]; then
|
||||
tar -C "$corepack_home" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/corepack && tar -C /opt/corepack --no-same-owner -xf -' \
|
||||
|| fail "copying the corepack cache failed"
|
||||
|
||||
@@ -44,10 +44,34 @@ jobs:
|
||||
if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
env:
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: \${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: \${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
@@ -88,10 +112,34 @@ jobs:
|
||||
# FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
env:
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: \${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: \${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
@@ -134,10 +182,33 @@ jobs:
|
||||
image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
env:
|
||||
CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
COREPACK_HOME: /tmp/fe-dependency-cache/corepack
|
||||
PNPM_CONFIG_STORE_DIR: /tmp/fe-dependency-cache/pnpm-store
|
||||
PNPM_CONFIG_CACHE_DIR: /tmp/fe-dependency-cache/pnpm-cache
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore and save the dependency cache
|
||||
if: \${{ gitea.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- name: Restore the dependency cache
|
||||
if: \${{ gitea.ref != 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830
|
||||
with:
|
||||
path: |
|
||||
/opt/hostedtoolcache/node
|
||||
/tmp/fe-dependency-cache
|
||||
key: fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-\${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
fe-dependencies-\${{ runner.os }}-\${{ runner.arch }}-
|
||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
|
||||
@@ -9,6 +9,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CI_ACTION_REGISTRY,
|
||||
DEPENDENCY_CACHE,
|
||||
indexCiGateContract,
|
||||
loadCiGateContract,
|
||||
parseCiActionRegistry,
|
||||
@@ -1674,16 +1675,18 @@ describe("CI workflow generation", () => {
|
||||
'if [ -n "$PROMOTION_STAGING_ROOT" ] && [ -n "$PROMOTION_CLEANUP_TOKEN" ] && [ -n "$PROMOTION_RUNNER_TEMP_DEV" ] && [ -n "$PROMOTION_RUNNER_TEMP_INO" ] && [ -n "$PROMOTION_STAGING_DEV" ] && [ -n "$PROMOTION_STAGING_INO" ]; then',
|
||||
);
|
||||
const actionUses = [...first.matchAll(/^\s+-?\s*uses: (.+)$/gmu)].map((match) => match[1]);
|
||||
expect(actionUses).toHaveLength(43);
|
||||
expect(actionUses).toHaveLength(49);
|
||||
expect(new Set(actionUses)).toEqual(
|
||||
new Set([
|
||||
"https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5",
|
||||
"https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020",
|
||||
"https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7",
|
||||
"https://github.com/ChristopherHX/gitea-download-artifact@75635f32b4c1c41c4b3d64e8f85210112ed4c9c7",
|
||||
"https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830",
|
||||
"https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830",
|
||||
]),
|
||||
);
|
||||
expect(actionUses.every((uses) => /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+@[0-9a-f]{40}$/u.test(uses!))).toBe(true);
|
||||
expect(actionUses.every((uses) => /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:\/restore)?@[0-9a-f]{40}$/u.test(uses!))).toBe(true);
|
||||
});
|
||||
|
||||
// 1103/11-02. tests/visual/fonts.conf reads the goldens' faces from OS
|
||||
@@ -1783,6 +1786,111 @@ describe("CI workflow generation", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// Decision 2026-11-13 (lead): the dependency cache is for the merge jobs
|
||||
// only, and the jobs that produce supply-chain evidence install fresh.
|
||||
describe("dependency cache", () => {
|
||||
const jobSection = (workflow: string, jobId: string) => {
|
||||
const start = workflow.indexOf(`\n ${jobId}:\n`);
|
||||
expect(start, jobId).toBeGreaterThan(0);
|
||||
const next = workflow.slice(start + 1).search(/\n {2}[a-z_]+:\n/u);
|
||||
return workflow.slice(start + 1, next < 0 ? undefined : start + 1 + next + 1);
|
||||
};
|
||||
const save = "https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830";
|
||||
const restore = "https://github.com/actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830";
|
||||
|
||||
it("restores it in each merge job before setup-node, saves it only on main, and installs either way", async () => {
|
||||
const workflow = renderCiWorkflow(await loadCiGateContract(process.cwd()));
|
||||
for (const jobId of DEPENDENCY_CACHE.jobIds) {
|
||||
const job = jobSection(workflow, jobId);
|
||||
const steps = job.split("\n - ");
|
||||
const saveIndex = steps.findIndex((step) => step.includes(`uses: ${save}`));
|
||||
const restoreIndex = steps.findIndex((step) => step.includes(`uses: ${restore}`));
|
||||
const setupIndex = steps.findIndex((step) => step.startsWith("uses: https://github.com/actions/setup-node@"));
|
||||
const installIndex = steps.findIndex((step) => step.startsWith("name: Frozen install"));
|
||||
expect([saveIndex, restoreIndex].every((index) => index > 0 && index < setupIndex), jobId).toBe(true);
|
||||
expect(setupIndex).toBeLessThan(installIndex);
|
||||
expect(steps[saveIndex]).toContain("if: ${{ gitea.ref == 'refs/heads/main' }}");
|
||||
expect(steps[restoreIndex]).toContain("if: ${{ gitea.ref != 'refs/heads/main' }}");
|
||||
for (const step of [steps[saveIndex]!, steps[restoreIndex]!]) {
|
||||
expect(step).toContain(
|
||||
"key: fe-dependencies-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.nvmrc', 'pnpm-lock.yaml') }}",
|
||||
);
|
||||
expect(step).toContain(" /opt/hostedtoolcache/node\n /tmp/fe-dependency-cache\n");
|
||||
}
|
||||
// The install does not depend on a hit: a missing or damaged entry
|
||||
// only makes pnpm fetch what it lacks.
|
||||
expect(steps[installIndex]).toBe(
|
||||
"name: Frozen install\n run: |\n corepack enable\n corepack pnpm install --frozen-lockfile --ignore-scripts",
|
||||
);
|
||||
for (const { name, value } of DEPENDENCY_CACHE.environment) {
|
||||
expect(job).toContain(` ${name}: ${value}\n`);
|
||||
expect(value.startsWith("/tmp/fe-dependency-cache/")).toBe(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// A pull request run (`refs/pull/<n>/head`) restores what main saved and
|
||||
// cannot change it: only actions/cache saves (in its post step), and only
|
||||
// the step a main run takes uses it.
|
||||
it("gives a pull request run main's entry read-only, under the same key", async () => {
|
||||
const workflow = renderCiWorkflow(await loadCiGateContract(process.cwd()));
|
||||
const steps = workflow.split("\n - ");
|
||||
const saving = steps.filter((step) => step.includes(`uses: ${save}`));
|
||||
const restoring = steps.filter((step) => step.includes(`uses: ${restore}`));
|
||||
expect(saving).toHaveLength(DEPENDENCY_CACHE.jobIds.length);
|
||||
expect(restoring).toHaveLength(DEPENDENCY_CACHE.jobIds.length);
|
||||
const condition = (step: string) => /\n {8}if: (.+)\n/u.exec(step)?.[1];
|
||||
expect(new Set(saving.map(condition))).toEqual(new Set(["${{ gitea.ref == 'refs/heads/main' }}"]));
|
||||
expect(new Set(restoring.map(condition))).toEqual(new Set(["${{ gitea.ref != 'refs/heads/main' }}"]));
|
||||
// The restore-only action has no post step, so nothing it runs writes the cache.
|
||||
expect(restore).toMatch(/^https:\/\/github\.com\/actions\/cache\/restore@[0-9a-f]{40}$/u);
|
||||
const withBlock = (step: string) => step.slice(step.indexOf(" with:\n"));
|
||||
for (let index = 0; index < saving.length; index += 1) {
|
||||
expect(withBlock(restoring[index]!)).toBe(withBlock(saving[index]!));
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves every other job on a fresh install", async () => {
|
||||
const contract = await loadCiGateContract(process.cwd());
|
||||
const workflow = renderCiWorkflow(contract);
|
||||
const others = contract.jobs.map(({ id }) => id).filter(
|
||||
(id) => !(DEPENDENCY_CACHE.jobIds as readonly string[]).includes(id),
|
||||
);
|
||||
expect(others).toEqual(expect.arrayContaining([
|
||||
"release_gate", "immutable_build", "vulnerability_provider", "provenance_provider", "promotion", "main_gate",
|
||||
]));
|
||||
for (const jobId of others) {
|
||||
const job = jobSection(workflow, jobId);
|
||||
expect(job, jobId).not.toContain("actions/cache");
|
||||
expect(job, jobId).not.toMatch(/PNPM_CONFIG_|COREPACK_HOME|fe-dependency-cache/u);
|
||||
}
|
||||
expect(workflow.match(/uses: https:\/\/github\.com\/actions\/cache/gu)).toHaveLength(2 * DEPENDENCY_CACHE.jobIds.length);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a release job", "release_gate", 1, /step kind dependency-cache is forbidden for gate-matrix job release_gate/u],
|
||||
["the main job", "main_gate", 1, /the dependency cache is for the merge jobs only: main_gate/u],
|
||||
["a provider job", "vulnerability_provider", 1, /step kind dependency-cache is forbidden for provider job vulnerability_provider/u],
|
||||
])("refuses the cache in %s", async (_name, jobId, at, diagnostic) => {
|
||||
const contract = JSON.parse(JSON.stringify(await loadCiGateContract(process.cwd()))) as Record<string, any>;
|
||||
contract.jobs.find((job: Record<string, any>) => job.id === jobId).steps.splice(at, 0, { kind: "dependency-cache" });
|
||||
expect(() => parseCiGateContract(contract)).toThrow(diagnostic);
|
||||
});
|
||||
|
||||
it("refuses a merge job that drops the cache or binds its directories itself", async () => {
|
||||
const dropped = JSON.parse(JSON.stringify(await loadCiGateContract(process.cwd()))) as Record<string, any>;
|
||||
const test = dropped.jobs.find((job: Record<string, any>) => job.id === "merge_test");
|
||||
test.steps = test.steps.filter((step: Record<string, any>) => step.kind !== "dependency-cache");
|
||||
expect(() => parseCiGateContract(dropped)).toThrow(/canonical job step sequence drift: merge_test/u);
|
||||
|
||||
const bound = JSON.parse(JSON.stringify(await loadCiGateContract(process.cwd()))) as Record<string, any>;
|
||||
bound.jobs.find((job: Record<string, any>) => job.id === "merge_static").environment.push(
|
||||
{ name: "COREPACK_HOME", value: "/somewhere" },
|
||||
);
|
||||
expect(() => parseCiGateContract(bound)).toThrow(/job merge_static binds COREPACK_HOME, which its dependency cache sets/u);
|
||||
});
|
||||
});
|
||||
|
||||
// The job container has neither systemd nor bubblewrap, so FE-GATE-013 runs
|
||||
// in the system container its contract names (hostEnvironment).
|
||||
it("runs a gate with a host environment through it, and counts only that run", async () => {
|
||||
|
||||
Reference in New Issue
Block a user