문제:
PR 병합 뒤 refs/heads/main push run이 merge job 셋(merge_static,
merge_test, merge_browser)을 처음부터 다시 돈다. 최근 병합 대부분은
병합 커밋 트리가 PR head(HEAD^2) 트리와 같아 같은 입력을 두 번 돌고
있다.
고른 방법과 버린 대안:
- merge job 셋의 Frozen install 바로 뒤에 main-push-reuse step을
두고 checkout에 fetch-depth: 2를 준다.
- 여섯 조건(main push, 부모 둘 병합 커밋과 tree(HEAD)==tree(HEAD^2),
.nvmrc·pnpm-lock.yaml 무변경, HEAD^2 최신 pull_request run의 같은
job success, 그 job 로그가 비어 있지 않고 SKIPPED_GATE_LINE 형식
건너뜀 줄 없음, Gitea API 정상 읽기)이 모두 참일 때만 뒤 step
(글꼴·게이트·scripts/tests·증거 업로드)을 건너뛰고 건너뜀 한 줄로
성공 종료한다. 하나라도 모르거나 실패하면 전부 돈다(fail open).
- main_gate(FE-GATE-029·030)와 release·tag run은 건너뛰지 않는다.
- 버린 안: main에서 경로표 재계산(PR 기준과 HEAD^1 사이 되돌림 누락),
보호 규칙만 믿고 조건 4 생략(우회 병합 누락), 게이트 단위 건너뛰기
(D-1 범위 밖).
위험·한계:
- job 토큰(gitea.token)으로 Gitea 1.27의 actions/runs·jobs/logs API를
읽을 수 있는지는 첫 main push 로그로 확인한다. 403이면 조건 6이
모두 돌게 하므로 기존보다 나빠지지 않는다.
- 같은 트리의 두 번째 실행 표본이 줄어든다(D-3 판정용 재시도가 PR
안에서 흔들림 판정을 대신한다).
검증:
- laptop-gate tests/unit/{main-push-reuse,ci-workflow-generation,script-entry-guards}.test.ts rc=0
- laptop-gate check:types, lint, check:ci, verify:documentation rc=0
- scripts/verify.sh docs rc=0, scripts/verify.sh hooks rc=0 (112 tests)
Refs: CI-FE-0004
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { appendFile } from "node:fs/promises";
|
|
|
|
import { isEntryModule } from "../lib/entry-module.ts";
|
|
import {
|
|
evaluateMainPushReuse,
|
|
type MainPushReuseFetch,
|
|
type MainPushReuseGit,
|
|
type ReuseDecision,
|
|
} from "../lib/main-push-reuse.ts";
|
|
|
|
/**
|
|
* FE-1 (CI-FE-0004) CLI step for merge jobs on refs/heads/main push runs.
|
|
* Writes `reuse=true|false` to `$GITHUB_OUTPUT` and logs either the canonical
|
|
* `건너뜀:` line or the reason the job will run. Fails open on any error so a
|
|
* reuse lookup problem never fails a main push build.
|
|
*/
|
|
|
|
export type MainPushReuseCliOptions = Readonly<{
|
|
argv?: readonly string[] | undefined;
|
|
environment?: NodeJS.ProcessEnv | undefined;
|
|
git?: MainPushReuseGit | undefined;
|
|
fetcher?: MainPushReuseFetch | undefined;
|
|
timeoutMs?: number | undefined;
|
|
stdout?: Pick<typeof process.stdout, "write"> | undefined;
|
|
}>;
|
|
|
|
function parseArgs(argv: readonly string[]): Readonly<{ jobName?: string; githubOutput?: string }> {
|
|
let jobName: string | undefined;
|
|
let githubOutput: string | undefined;
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const token = argv[index]!;
|
|
if (token === "--job") {
|
|
jobName = argv[index + 1];
|
|
index += 1;
|
|
} else if (token === "--github-output") {
|
|
githubOutput = argv[index + 1];
|
|
index += 1;
|
|
}
|
|
}
|
|
return {
|
|
...(jobName !== undefined ? { jobName } : {}),
|
|
...(githubOutput !== undefined ? { githubOutput } : {}),
|
|
};
|
|
}
|
|
|
|
export async function runMainPushReuseCli(options: MainPushReuseCliOptions = {}): Promise<ReuseDecision> {
|
|
const argv = options.argv ?? process.argv.slice(2);
|
|
const environment = options.environment ?? process.env;
|
|
const stdout = options.stdout ?? process.stdout;
|
|
const parsed = parseArgs(argv);
|
|
const jobName = parsed.jobName?.trim() ?? "";
|
|
const githubOutput = parsed.githubOutput ?? environment["GITHUB_OUTPUT"] ?? "";
|
|
|
|
let decision: ReuseDecision;
|
|
if (jobName.length === 0) {
|
|
decision = { reuse: false, reason: "--job 인자가 없음" };
|
|
} else {
|
|
try {
|
|
decision = await evaluateMainPushReuse({
|
|
jobName,
|
|
environment,
|
|
git: options.git,
|
|
fetcher: options.fetcher,
|
|
timeoutMs: options.timeoutMs,
|
|
});
|
|
} catch (error) {
|
|
const detail = error instanceof Error ? error.message : String(error);
|
|
decision = { reuse: false, reason: `예기치 않은 오류: ${detail}` };
|
|
}
|
|
}
|
|
|
|
stdout.write(decision.reuse ? `${decision.line}\n` : `main push 재사용 안 함: ${decision.reason}\n`);
|
|
if (githubOutput.trim().length > 0) {
|
|
await appendFile(githubOutput, `reuse=${decision.reuse ? "true" : "false"}\n`, "utf8");
|
|
}
|
|
return decision;
|
|
}
|
|
|
|
if (isEntryModule(import.meta)) {
|
|
await runMainPushReuseCli();
|
|
}
|