ci(gates): 의존성 캐시를 checkout과 같은 파일시스템의 폴더에 둔다
frontend-quality-gates / merge / static checks (pull_request) Successful in 1m56s
frontend-quality-gates / merge / tests (pull_request) Successful in 15m58s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 6m15s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped

문제: #41의 merge job 캐시는 hit해도 설치가 빨라지지 않았다. PR run
230에서 세 job 모두 복원했지만(222MB, 4.8초) pnpm 설치는 16.9·26.4·22.4초로
캐시 없는 run(13.8~22.8초)과 같았다. `reused 404, downloaded 0` 뒤 node_modules에
넣는 데만 15초 넘게 걸렸다. desktop 재현: 같은 파일시스템 2.1초, tar 왕복 뒤
7.6초, store가 다른 파일시스템이면 58.8초(하드링크 대신 복사). store가 job의
`/tmp`에 있어 checkout과 다른 파일시스템일 가능성이 크다.

고친 것(권하는 안으로 정함, 총괄): merge job의 첫 캐시 단계가
`scripts/ci/dependency-cache-root.sh "$RUNNER_TEMP" "$(dirname "$GITHUB_WORKSPACE")"`
를 돈다. 후보 중 checkout과 `stat -c %d`가 같고 checkout 밖인 첫 폴더를 고르고,
없으면 첫 후보를 쓴다. 고른 폴더, 견준 장치 번호, job 시작 때의 부하를 한
줄로 로그에 남기고, `COREPACK_HOME`·`PNPM_CONFIG_STORE_DIR`·
`PNPM_CONFIG_CACHE_DIR`를 `$GITHUB_ENV`로 넘긴다(job env 고정값을 뺌). 캐시
경로는 그 단계 출력을 쓴다. checkout 안은 후보가 아니다(`git status`, repo
배치 검사, 산출물에 잡히지 않게).

버린 대안: checkout 안 `.tmp` 아래(배치 검사·산출물에 걸림), workspace 부모를
고정 경로로(파일시스템이 같은지 runner마다 다를 수 있다).

위험·한계: 고른 폴더가 run마다 다르면 캐시 항목의 경로가 달라 hit하지 않는다
(같은 runner에서는 같다). 같은 파일시스템이 없으면 지금과 같다. runner에서의
효과는 main 저장 → 다음 PR 복원으로 잰다.

검증(desktop): 새 시험 `tests/unit/dependency-cache-root.test.ts`(가짜
`stat`으로 같은 파일시스템 고르기·checkout 안 제외·대체 경로) 통과, 최대
47ms. 생성 시험은 바꾸기 전 생성기에서 실패(RED), 고친 뒤
ci-workflow-generation·test-timeout-declarations·repository-layout 등 460개
통과. check:ci·check:types·eslint·verify:documentation rc=0.
This commit is contained in:
DongHyeonka
2026-11-13 14:05:46 +09:00
parent 94e9401af7
commit f21ea48911
8 changed files with 214 additions and 56 deletions
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Chooses where a merge job keeps its dependency cache (scripts/contracts/ci-gates.ts DEPENDENCY_CACHE): the first
# candidate folder on the checkout's filesystem, so pnpm hardlinks node_modules from the restored store. A store on
# another filesystem is copied file by file, and a warm install took longer than a cold one (desktop: 2.1 s on the
# same filesystem, 58.8 s across filesystems, 2026-11-13). A folder inside the checkout is never chosen: a cache
# there would show in `git status`, the repository layout checks and the uploaded artifacts.
#
# scripts/ci/dependency-cache-root.sh <candidate folder>...
#
# Writes COREPACK_HOME, PNPM_CONFIG_STORE_DIR and PNPM_CONFIG_CACHE_DIR to $GITHUB_ENV and root=<folder> to
# $GITHUB_OUTPUT, and logs one line: the folder, whether it shares the checkout's filesystem, each candidate's
# device and the load average at the job's start (the runner shares the desktop with other work). With no
# candidate on that filesystem it takes the first usable candidate, and the install still runs.
set -euo pipefail
workspace=$(cd "${GITHUB_WORKSPACE:?}" && pwd -P)
checkout=$(stat -c %d "$workspace")
chosen=""
fallback=""
devices=""
for candidate in "$@"; do
[ -n "$candidate" ] && [ -d "$candidate" ] && [ -w "$candidate" ] || continue
real=$(cd "$candidate" && pwd -P)
case "$real/" in "$workspace/"*) continue ;; esac
device=$(stat -c %d "$real")
devices="$devices $real=$device"
[ -n "$fallback" ] || fallback=$real
if [ -z "$chosen" ] && [ "$device" = "$checkout" ]; then chosen=$real; fi
done
same=yes
if [ -z "$chosen" ]; then
same=no
chosen=${fallback:-/tmp}
fi
root="${chosen%/}/fe-dependency-cache"
echo "dependency cache: $root (on the checkout's filesystem: $same; devices: checkout=$checkout$devices; load average at job start: $(cut -d' ' -f1-3 /proc/loadavg))"
{
echo "COREPACK_HOME=$root/corepack"
echo "PNPM_CONFIG_STORE_DIR=$root/pnpm-store"
echo "PNPM_CONFIG_CACHE_DIR=$root/pnpm-cache"
} >> "${GITHUB_ENV:?}"
echo "root=$root" >> "${GITHUB_OUTPUT:?}"
+19 -7
View File
@@ -123,17 +123,29 @@ export function resolveCiSubActionUses(actionId: CiActionId, subpath: "restore")
* (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).
*
* The cache folder is outside the checkout, on its filesystem
* (scripts/ci/dependency-cache-root.sh): with the store in the job's `/tmp`,
* a warm runner install still took 17 to 26 s, as pnpm copied node_modules
* across filesystems (run 230). The script logs the devices it compared and
* the load average at the job's start, and sets the variables below through
* `$GITHUB_ENV`, so every pnpm call of the job, the system container's
* included, reads the same folder.
*/
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" }),
]),
rootStepId: "dependency-cache-root",
rootScript: "scripts/ci/dependency-cache-root.sh",
/** Folders outside the checkout to try, in order (shell words). */
rootCandidates: Object.freeze(['"$RUNNER_TEMP"', '"$(dirname "$GITHUB_WORKSPACE")"'] as const),
paths: Object.freeze([
"/opt/hostedtoolcache/node",
"${{ steps.dependency-cache-root.outputs.root }}",
] as const),
/** What the script writes to `$GITHUB_ENV`. */
environmentNames: Object.freeze(["COREPACK_HOME", "PNPM_CONFIG_STORE_DIR", "PNPM_CONFIG_CACHE_DIR"] as const),
/** The jobs that may hold the step: the three merge jobs. */
jobIds: Object.freeze(["merge_static", "merge_test", "merge_browser"] as const),
});
@@ -868,7 +880,7 @@ function validateContractSemantics(
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) {
for (const name of DEPENDENCY_CACHE.environmentNames) {
if (job.environment.some((binding) => binding.name === name)) {
issue(`job ${job.id} binds ${name}, which its dependency cache sets`);
}
+5 -8
View File
@@ -236,16 +236,9 @@ 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)}`] : []),
...[...cacheEnvironment, ...jobEnvironment].map(
(binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`,
),
...jobEnvironment.map((binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`),
];
if (environmentLines.length > 0) lines.push(" env:", ...environmentLines);
if (job.kind === "gate-matrix") {
@@ -338,6 +331,10 @@ function renderStep(
` ${DEPENDENCY_CACHE.keyPrefix}`,
];
return [
// The folder on the checkout's filesystem, and the job's pnpm variables.
" - name: Choose the dependency cache folder",
` id: ${DEPENDENCY_CACHE.rootStepId}`,
` run: bash ${DEPENDENCY_CACHE.rootScript} ${DEPENDENCY_CACHE.rootCandidates.join(" ")}`,
" - name: Restore and save the dependency cache",
" if: ${{ gitea.ref == 'refs/heads/main' }}",
` uses: ${requiredStepActionUses(step.kind)}`,