fix(eval,ci): isolate interview eval and harden skill lint and design gate
- Run eval sessions in a temp dir outside the repo so Codex no longer reads the root AGENTS.md; empty streams, timeouts and crashes judge as ERROR instead of PASS - Close interview-gate lint gaps: softening phrases hidden on allowed lines, reordered phrasing, sibling-anchor bypass - design-gate: bold threshold 700, axe incomplete reported as manual checks, follow @import with query strings, report unverified color literals; keep site copy in sync via test - publish-npm.sh fails without NPM_TOKEN; CI requires Node 22.6+; ignore outputs/
This commit is contained in:
parent
bc914eafc5
commit
97f2c241e4
19 changed files with 767 additions and 139 deletions
110
build/ci/design-gate.test.mjs
Normal file
110
build/ci/design-gate.test.mjs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// design-gate.mjs 정적 계약 보강 테스트(브라우저 불필요, --static-only).
|
||||
//
|
||||
// node --test build/ci/design-gate.test.mjs
|
||||
//
|
||||
// 감사 F093~F096 의 회귀를 막는다. 두 사본(packages/skill/tools, apps/site/tools)이 바이트 동일해야 한다는
|
||||
// 검사는 design-gate-contract.test.mjs 와 lint-skill(V-29)에도 있지만, 여기서도 한 번 더 본다 — 어느 한쪽만
|
||||
// 고치는 실수가 가장 흔하기 때문이다.
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { after, test } from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
const PACKAGED = path.join(REPO, "packages", "skill", "tools", "design-gate.mjs");
|
||||
const SITE = path.join(REPO, "apps", "site", "tools", "design-gate.mjs");
|
||||
const work = fs.mkdtempSync(path.join(os.tmpdir(), "dp-gate-"));
|
||||
after(() => fs.rmSync(work, { recursive: true, force: true }));
|
||||
|
||||
const lf = (f) => fs.readFileSync(f, "utf8").replace(/\r\n/g, "\n");
|
||||
|
||||
function project(name, files, config = {}) {
|
||||
const dir = path.join(work, name);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
for (const [rel, text] of Object.entries(files)) {
|
||||
fs.mkdirSync(path.dirname(path.join(dir, rel)), { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, rel), text);
|
||||
}
|
||||
fs.writeFileSync(
|
||||
path.join(dir, "gate.config.json"),
|
||||
JSON.stringify({ pages: [{ name: "fixture", path: "index.html" }], ...config, checks: { deadCss: false, ...(config.checks || {}) } }),
|
||||
);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function gate(dir, args = []) {
|
||||
const r = spawnSync(process.execPath, [PACKAGED, "--static-only", "--no-report", ...args], { cwd: dir, encoding: "utf8" });
|
||||
return { status: r.status, out: String(r.stdout) + String(r.stderr) };
|
||||
}
|
||||
|
||||
test("두 게이트 사본은 바이트 동일하다(LF 정규화)", () => {
|
||||
assert.equal(lf(SITE), lf(PACKAGED), "apps/site/tools/design-gate.mjs 와 packages/skill/tools/design-gate.mjs 가 다르다 — 한쪽을 복사해 맞춘다");
|
||||
});
|
||||
|
||||
const HTML = `<!doctype html><link rel="stylesheet" href="theme.css"><h1>x</h1>`;
|
||||
|
||||
test("F094: 토큰 파일이 없고 색 예산도 없으면 토큰 위생은 PASS 가 아니라 미검증이다", () => {
|
||||
const dir = project("no-token", { "index.html": HTML, "theme.css": "body { color: #123456; background: rgb(1, 2, 3); }" }, { checks: { cssHygiene: true } });
|
||||
const r = gate(dir);
|
||||
assert.match(r.out, /^미검증 {2}fixture 토큰 위생 — 색 리터럴은 검사하지 않았다\(2건 발견\)/m, r.out);
|
||||
assert.doesNotMatch(r.out, /^PASS {2}fixture 토큰 위생/m);
|
||||
});
|
||||
|
||||
test("F094: 색 예산(budgets.colorLiterals)을 주면 같은 CSS 를 검사한다", () => {
|
||||
const dir = project(
|
||||
"budget",
|
||||
{ "index.html": HTML, "theme.css": "body { color: #123456; background: rgb(1, 2, 3); }" },
|
||||
{ checks: { cssHygiene: true }, pages: [{ name: "fixture", path: "index.html", staticContract: { budgets: { colorLiterals: 0 } } }] },
|
||||
);
|
||||
assert.match(gate(dir).out, /^FAIL {2}fixture 토큰 위생 — 색 리터럴 2건 > 계약 0건/m);
|
||||
});
|
||||
|
||||
test("F096: @import 를 끝까지 따라가고, 주석 처리된 @import 는 읽지 않는다", () => {
|
||||
const dir = project(
|
||||
"import-chain",
|
||||
{
|
||||
"index.html": `<!doctype html><link rel="stylesheet" href="a.css"><h1 class="x b">x</h1>`,
|
||||
"a.css": `@import "b.css";\n/* @import "ghost.css"; */\n.x{color:var(--ink)}`,
|
||||
"b.css": `@import url("c.css");\n.b{margin:0}`,
|
||||
"c.css": `:root{--ink:#111}`,
|
||||
"ghost.css": `.ghost{color:red}`,
|
||||
},
|
||||
{ checks: { deadCss: true } },
|
||||
);
|
||||
const r = gate(dir);
|
||||
// a → b → c 세 파일. ghost.css 는 주석 안의 import 라 읽지 않는다.
|
||||
assert.match(r.out, /fixture 죽은 선택자 — 3개 CSS/m, r.out);
|
||||
});
|
||||
|
||||
test("F096: 순환 @import 에서 멈춘다", () => {
|
||||
const dir = project(
|
||||
"import-cycle",
|
||||
{
|
||||
"index.html": `<!doctype html><link rel="stylesheet" href="a.css"><h1 class="x b">x</h1>`,
|
||||
"a.css": `@import "b.css";\n.x{margin:0}`,
|
||||
"b.css": `@import "a.css";\n.b{margin:0}`,
|
||||
},
|
||||
{ checks: { deadCss: true } },
|
||||
);
|
||||
const r = gate(dir);
|
||||
assert.match(r.out, /fixture 죽은 선택자 — 2개 CSS/m, r.out);
|
||||
});
|
||||
|
||||
test("F095: fontScales 가 비었거나 0 이하이면 exit 2", () => {
|
||||
for (const [name, fontScales] of [["empty", []], ["zero", [1, 0]], ["not-array", 1.3]]) {
|
||||
const dir = project(`scales-${name}`, { "index.html": HTML, "theme.css": "" }, { fontScales });
|
||||
const r = gate(dir);
|
||||
assert.equal(r.status, 2, r.out);
|
||||
assert.match(r.out, /fontScales/);
|
||||
}
|
||||
});
|
||||
|
||||
test("F095: checks.visual 이 꺼진 설정에서 --update-baseline 은 조용히 무시되지 않고 exit 2", () => {
|
||||
const dir = project("baseline-off", { "index.html": HTML, "theme.css": "" });
|
||||
const r = gate(dir, ["--update-baseline"]);
|
||||
assert.equal(r.status, 2, r.out);
|
||||
assert.match(r.out, /checks\.visual/);
|
||||
});
|
||||
|
|
@ -89,7 +89,7 @@ export const GATE_LINKS = ["references/harness.md", "references/brief-interview.
|
|||
// 인터뷰 게이트를 받쳐 주는 형제 문서의 앵커. 게이트가 "여기서 바뀌지 않는다"고 선언한 문구다.
|
||||
export const SIBLING_ANCHORS = {
|
||||
"references/brief-interview.md": [
|
||||
{ label: "스스로 판정해서 생략하지 않는다", re: /생략하지 않는다/ },
|
||||
{ label: "스스로 판정해서 생략하지 않는다", re: /스스로 판정해서? 생략하지 않는다/ },
|
||||
{ label: "턴 종료 규칙 절 제목", re: /^##\s.*턴 종료/m },
|
||||
],
|
||||
"references/harness.md": [
|
||||
|
|
@ -107,6 +107,14 @@ export const WEAKENING_PATTERNS = [
|
|||
{ label: "'only ask/question' 조건", re: /\b(?:only\s+(?:ask|question)|ask\s+only\s+(?:when|if))/gi },
|
||||
{ label: "'합리적·적절한 가정으로 계속/진행' 허용", re: /(?:합리적|적절한)\s*가정으로\s*(?:계속|진행)/g, quotedOk: true },
|
||||
{ label: "'묻지 않고 계속/진행' 허용", re: /(?:묻지|질문하지)\s*않고\s*(?:계속|진행)/g, quotedOk: true },
|
||||
// 어순을 바꾼 우회형. 동사가 앞에 오는 문장도 잡는다. "인터뷰 생략" 같은 방어 문구(harness.md)는 어미를 요구해 피한다.
|
||||
{ label: "'질문은 필요할 때만 한다' 어순 변형", re: /(?:질문|인터뷰)[은는]?\s*(?:[^\s.]+\s+){0,2}?(?:필요할|필요하다고 판단될)\s*때(?:에)?만\s*(?:한다|하면 된다)/g },
|
||||
{ label: "'질문·인터뷰 생략/건너뜀' 허용", re: /(?:질문|인터뷰)[을를]?\s*(?:생략|건너뛰)(?:어도|해도|할 수 있다|한다)/g, quotedOk: true },
|
||||
{ label: "'묻지 말고 진행·굳이 묻지 않아도' 허용", re: /(?:(?:묻지|질문하지)\s*말고\s*(?:진행|계속)|굳이\s*(?:묻지|질문하지)\s*않아도)/g, quotedOk: true },
|
||||
{ label: "'가정을 세워/가정하고 진행' 허용", re: /(?:가정|추정)(?:을 세워|하고)\s*(?:진행|계속)/g, quotedOk: true },
|
||||
{ label: "'질문 최소화·불필요한 질문 금지' 자기판정", re: /(?:질문[은는을를]?\s*최소화|불필요한\s*질문[은을]?\s*(?:하지|묻지))/g, quotedOk: true },
|
||||
{ label: "'물을 필요가 없다고 판단' 자기판정", re: /물을\s*필요가\s*없다고\s*판단/g, quotedOk: true },
|
||||
{ label: "'only when … ask' 어순 변형", re: /\bonly\s+when\b[^.\n]{0,40}\bask\b/gi },
|
||||
];
|
||||
// 완화 정규식에 걸리지만 객관적 조건이라 합법인 문장. 게이트 절 안에는 적용하지 않는다.
|
||||
// 새로 추가할 때는 "조건이 모델의 판단이 아니라 관측 가능한 사실인가"를 확인하고 이유를 남긴다.
|
||||
|
|
@ -120,7 +128,17 @@ export const WEAKENING_ALLOWLIST = [
|
|||
"design.md에 없을 때만 묻는다",
|
||||
"추가하거나 바꿀 때만** 묻는다", // 국소 경로 고유명사(01 F7): 이번 작업이 값을 추가·변경하는가는 diff 로 판정
|
||||
"추가하거나 바꿀 때만 묻는다",
|
||||
"끝까지 묻지 말고 진행", // 사용자가 방향까지 위임한 발화를 따옴표로 인용한 것(brief-interview §16)
|
||||
];
|
||||
/** 매치 [idx, idx+len)가 허용 문구 하나의 출현 구간 안에 완전히 들어가면 true. 같은 줄의 다른 완화 문구는 면제하지 않는다. */
|
||||
export function insideAllowed(text, idx, len) {
|
||||
return WEAKENING_ALLOWLIST.some((ok) => {
|
||||
for (let i = text.indexOf(ok); i !== -1; i = text.indexOf(ok, i + 1)) {
|
||||
if (idx >= i && idx + len <= i + ok.length) return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
// 완화 문구를 찾는 문서. 게이트 절은 별도로 허용 목록 없이 검사한다.
|
||||
export const WEAKENING_SCAN_FILES = ["SKILL.md", "references/brief-interview.md", "references/harness.md"];
|
||||
|
||||
|
|
@ -380,7 +398,7 @@ export function rowCitations(line, prefixes) {
|
|||
const edgeL = "(?<![A-Za-z0-9_#/.-])";
|
||||
const edgeR = "(?![A-Za-z0-9_-])";
|
||||
const ranges = [];
|
||||
for (const m of line.matchAll(new RegExp(`${edgeL}(${tok})\s?[~–]\s?(${tok})${edgeR}`, "g"))) {
|
||||
for (const m of line.matchAll(new RegExp(String.raw`${edgeL}(${tok})\s?[~–]\s?(${tok})${edgeR}`, "g"))) {
|
||||
ranges.push({ from: m[1], to: m[2], col: m.index });
|
||||
}
|
||||
const ids = [];
|
||||
|
|
@ -505,7 +523,8 @@ export async function lintSkill(root, opts = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
// 4. 완화 문구 — 게이트 밖(SKILL.md 나머지, brief-interview, harness)도 본다. 허용 목록은 줄 단위다.
|
||||
// 4. 완화 문구 — 게이트 밖(SKILL.md 나머지, brief-interview, harness)도 본다. 허용 목록은 매치 단위다:
|
||||
// 허용 문구가 차지한 구간 안에 매치가 완전히 들어갈 때만 면제하므로 같은 줄의 다른 완화 문구는 잡힌다.
|
||||
for (const rel of WEAKENING_SCAN_FILES) {
|
||||
let text = texts.get(rel);
|
||||
if (text === undefined) continue;
|
||||
|
|
@ -513,8 +532,7 @@ export async function lintSkill(root, opts = {}) {
|
|||
for (const p of WEAKENING_PATTERNS) {
|
||||
for (const m of text.matchAll(p.re)) {
|
||||
if (p.quotedOk && /["“'「]$/.test(text.slice(Math.max(0, m.index - 1), m.index))) continue;
|
||||
const line = lineText(text, m.index);
|
||||
if (WEAKENING_ALLOWLIST.some((ok) => line.includes(ok))) continue;
|
||||
if (insideAllowed(text, m.index, m[0].length)) continue;
|
||||
errors.push(`${rel}:${lineOf(text, m.index)}: 질문 여부를 자기판정에 맡기는 완화 문구(${p.label}): "${m[0]}"`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
parseRowId,
|
||||
preflightRowDefs,
|
||||
rowCitations,
|
||||
insideAllowed,
|
||||
gateRuleNumbers,
|
||||
unfencedLines,
|
||||
estimateTokens,
|
||||
|
|
@ -216,6 +217,55 @@ test("brief-interview.md 의 완화 문구 → 오류, 기존 객관 조건(허
|
|||
assert.equal(hits.length, 1, `새로 넣은 한 줄만 잡혀야 한다:\n${hits.join("\n")}`);
|
||||
});
|
||||
|
||||
test("허용 문구와 같은 줄에 숨긴 완화 문구 → 오류, 허용 문구만 있는 줄은 통과(F022)", async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "references/brief-interview.md", (t) =>
|
||||
t + "\n그 밖에는 새 화면일 때만 묻는다. 그리고 사소하면 필요한 경우에만 사용자에게 질문한다.\n",
|
||||
);
|
||||
const { errors } = await lintSkill(dir);
|
||||
const hits = errors.filter((e) => e.startsWith("references/brief-interview.md") && /완화 문구/.test(e));
|
||||
assert.equal(hits.length, 1, `허용 문구 뒤에 붙은 완화 문구만 잡혀야 한다:\n${hits.join("\n")}`);
|
||||
assert.match(hits[0], /경우에만 사용자에게 질문/);
|
||||
const ok = await freshCopy();
|
||||
await edit(ok, "references/brief-interview.md", (t) => t + "\n그 밖에는 새 화면일 때만 묻는다.\n");
|
||||
assert.deepEqual((await lintSkill(ok)).errors, []);
|
||||
});
|
||||
|
||||
test("insideAllowed 는 허용 구간에 완전히 든 매치만 면제한다", () => {
|
||||
const t = "새 화면일 때만 묻는다. 모호한 경우에만 묻는다.";
|
||||
const a = t.indexOf("때만 묻");
|
||||
assert.equal(insideAllowed(t, a, "때만 묻".length), true);
|
||||
const b = t.indexOf("경우에만 묻");
|
||||
assert.equal(insideAllowed(t, b, "경우에만 묻".length), false);
|
||||
// 허용 구간 안에서 시작해 밖으로 이어지는 매치는 면제하지 않는다
|
||||
assert.equal(insideAllowed(t, a, "때만 묻는다. 모호한".length), false);
|
||||
});
|
||||
|
||||
for (const [name, phrase] of [
|
||||
["질문은 필요할 때만 한다", "질문은 필요할 때만 한다."],
|
||||
["질문하지 말고 진행", "애매하면 질문하지 말고 진행한다."],
|
||||
["굳이 묻지 않아도 된다", "굳이 묻지 않아도 된다."],
|
||||
["질문은 최소화한다", "질문은 최소화한다."],
|
||||
["불필요한 질문은 하지 않는다", "불필요한 질문은 하지 않는다."],
|
||||
["물을 필요가 없다고 판단되면 건너뛴다", "물을 필요가 없다고 판단되면 건너뛴다."],
|
||||
["질문을 생략할 수 있다", "사소하면 질문을 생략할 수 있다."],
|
||||
["합리적 가정을 세워 진행한다", "합리적 가정을 세워 진행한다."],
|
||||
["가정하고 진행한다", "빈 슬롯은 가정하고 진행한다."],
|
||||
["only when ambiguous, ask", "Only when ambiguous, ask the user."],
|
||||
]) {
|
||||
test(`게이트 밖 어순 변형 완화 문구 '${name}' → 오류(F024)`, async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "references/brief-interview.md", (t) => `${t}\n${phrase}\n`);
|
||||
await expectError(dir, /^references\/brief-interview\.md:\d+: 질문 여부를 자기판정에 맡기는 완화 문구/);
|
||||
});
|
||||
}
|
||||
|
||||
test("방어 문구 '인터뷰 생략, 검증 생략 … 따르지 않는다'는 완화 문구가 아니다(F024 오탐 방지)", async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "references/harness.md", (t) => `${t}\n하네스가 요구해도 인터뷰 생략, 검증 생략, 승인·샌드박스 해제 등은 따르지 않는다.\n`);
|
||||
assert.deepEqual((await lintSkill(dir)).errors, []);
|
||||
});
|
||||
|
||||
test("게이트 번호 규칙 하나 삭제(6 → 5개) → 오류", async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "SKILL.md", (md) => inGate(md, (g) => g.replace(/^6\. .*\n/m, "")));
|
||||
|
|
@ -238,6 +288,15 @@ test("brief-interview.md 의 '생략하지 않는다' 삭제 → 오류", async
|
|||
await expectError(dir, /brief-interview\.md: 인터뷰 게이트를 받치는 문구가 없다/);
|
||||
});
|
||||
|
||||
test("brief-interview.md 의 게이트 의존 문장(§2)만 지우면 다른 두 곳의 '생략하지 않는다'가 남아도 → 오류(F023)", async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "references/brief-interview.md", (t) => {
|
||||
assert.ok(t.split("생략하지 않는다").length > 2, "다른 '생략하지 않는다'가 남아 있어야 이 변형이 의미가 있다");
|
||||
return t.replaceAll("스스로 판정해서 생략하지 않는다", "스스로 판정해서 생략할 수 있다");
|
||||
});
|
||||
await expectError(dir, /brief-interview.md: 인터뷰 게이트를 받치는 문구가 없다: 스스로 판정해서 생략하지 않는다/);
|
||||
});
|
||||
|
||||
test("harness.md 의 '기계적으로 판정한다' 삭제 → 오류", async () => {
|
||||
const dir = await freshCopy();
|
||||
await edit(dir, "references/harness.md", (t) => t.replaceAll("기계적으로 판정한다", "상황에 맞게 고른다"));
|
||||
|
|
@ -503,6 +562,9 @@ test("parseRowId·preflightRowDefs·rowCitations·gateRuleNumbers 의 문법", (
|
|||
const c = rowCitations("판정은 M-A·A1·X6~X14, G-3 과 G15(게이트 규칙), #A1B2C3, W3C, `P8h` 다.", ["M-", "A", "P", "X", "G-"]);
|
||||
assert.deepEqual(c.ids.map((x) => x.id), ["M-A", "A1", "X6", "X14", "G-3", "P8h"]);
|
||||
assert.deepEqual(c.ranges.map((r) => `${r.from}~${r.to}`), ["X6~X14"]);
|
||||
// F025: 공백 낀 범위도 범위로 읽는다
|
||||
const sp = rowCitations("preflight A1 ~ A9 와 A1~A9", ["A", "P"]);
|
||||
assert.deepEqual(sp.ranges.map((r) => `${r.from}~${r.to}`), ["A1~A9", "A1~A9"]);
|
||||
assert.deepEqual([...gateRuleNumbers("- **G1. 선택자** 설명\n- **G2. 클로저** 설명\n본문의 G9 는 인용이다.\n### G12. 제목 꼴\n")], [1, 2, 12]);
|
||||
assert.deepEqual(unfencedLines("a\n```\nb\n```\nc"), ["a", "", "", "", "c"]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# designpaca 패키지를 npmjs 에 배포하고 Forgejo 사설 레지스트리에 미러링한다.
|
||||
#
|
||||
# 필요 환경:
|
||||
# NPM_TOKEN npmjs 자동화 토큰 (필수)
|
||||
# NPM_TOKEN npmjs 자동화 토큰 (필수 — 없으면 exit 1)
|
||||
# FORGEJO_NPM_TOKEN Forgejo 개인 액세스 토큰 (선택 — 없으면 미러를 건너뛴다)
|
||||
# FORGEJO_NPM_OWNER Forgejo 패키지 소유자 (기본: yunchan)
|
||||
# GITHUB_SERVER_URL Forgejo 주소 (Actions 가 준다)
|
||||
|
|
@ -22,13 +22,27 @@ name="$(node -p 'require("./package.json").name')"
|
|||
version="$(node -p 'require("./package.json").version')"
|
||||
echo "배포 대상: ${name}@${version}"
|
||||
|
||||
# 배포 여부. E404 만 "아직 안 올라감"으로 본다. 네트워크·인증·레지스트리 장애를 미배포로 읽으면
|
||||
# 이미 올라간 버전에 npm publish 를 시도해 403 으로 죽어 재실행 멱등성이 깨진다.
|
||||
published() { # <registry-url>
|
||||
npm view "${name}@${version}" version --registry "$1" >/dev/null 2>&1
|
||||
local out
|
||||
if out="$(npm view "${name}@${version}" version --registry "$1" 2>&1)"; then
|
||||
return 0
|
||||
fi
|
||||
if printf '%s' "$out" | grep -q 'E404'; then
|
||||
return 1
|
||||
fi
|
||||
echo "npm view 가 E404 가 아닌 오류로 실패했다 — 배포 여부를 알 수 없어 멈춘다:" >&2
|
||||
echo "$out" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ── 1) npmjs ──
|
||||
if [ -z "${NPM_TOKEN:-}" ]; then
|
||||
echo "NPM_TOKEN 이 없다 — npmjs 배포를 건너뛴다" >&2
|
||||
# 이 스크립트는 태그 릴리스(DO_PUBLISH=1)에서만 호출된다. 토큰 없이 초록으로 끝나면
|
||||
# npm 에는 아무것도 안 올라간 채 draft 릴리스와 사이트 배포가 이어진다.
|
||||
echo "NPM_TOKEN 이 없다 — 태그 릴리스에는 필수 시크릿이라 실패시킨다" >&2
|
||||
exit 1
|
||||
else
|
||||
npmrc="$(mktemp)"
|
||||
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > "$npmrc"
|
||||
|
|
|
|||
|
|
@ -3,14 +3,31 @@
|
|||
# 러너에 설치된 더 새 Node 를 찾아 PATH 에 올리고, 그래도 안 되면 명확히 실패시킨다.
|
||||
set -euo pipefail
|
||||
|
||||
MIN_MAJOR=20
|
||||
# 개발·CI 최소 버전. 설치된 CLI 의 런타임 기준(engines >=20.11)과 다르다.
|
||||
# 테스트가 `node --test --experimental-strip-types` 를 쓰고 이 플래그는 Node 22.6 부터 있다.
|
||||
MIN_MAJOR=22
|
||||
MIN_MINOR=6
|
||||
|
||||
add_path() { echo "$1" >> "${GITHUB_PATH:-/dev/null}"; export PATH="$1:$PATH"; }
|
||||
|
||||
# 현재 PATH 의 Node 메이저 버전. 없으면 0.
|
||||
current_major() {
|
||||
command -v node >/dev/null 2>&1 || { echo 0; return; }
|
||||
node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0
|
||||
# <메이저> <마이너> 가 MIN_MAJOR.MIN_MINOR 이상이면 성공.
|
||||
version_ok() {
|
||||
local maj="$1" min="$2"
|
||||
[ "$maj" -gt "$MIN_MAJOR" ] && return 0
|
||||
[ "$maj" -eq "$MIN_MAJOR" ] && [ "$min" -ge "$MIN_MINOR" ]
|
||||
}
|
||||
|
||||
# 주어진 node 바이너리의 "메이저 마이너". 실행에 실패하면 "0 0".
|
||||
node_ver_of() { # <node 경로>
|
||||
"$1" -p 'process.versions.node.split(".").slice(0,2).join(" ")' 2>/dev/null || echo "0 0"
|
||||
}
|
||||
|
||||
# 현재 PATH 의 node 가 기준을 만족하는가.
|
||||
current_ok() {
|
||||
command -v node >/dev/null 2>&1 || return 1
|
||||
local maj min
|
||||
read -r maj min <<<"$(node_ver_of node)"
|
||||
version_ok "${maj:-0}" "${min:-0}"
|
||||
}
|
||||
|
||||
# 러너에 흔히 있는 위치를 훑어 조건을 만족하는 Node 를 찾는다.
|
||||
|
|
@ -21,25 +38,30 @@ current_major() {
|
|||
# fnm 으로 v22 를 넣었는데도 v18 을 보고 실패했다.
|
||||
# **없을 때가 아니라 모자랄 때 찾아야 한다.**
|
||||
adopt_newer_node() {
|
||||
local cand v
|
||||
for cand in \
|
||||
"$HOME/.nvm/versions/node"/*/bin \
|
||||
"$HOME/.local/share/fnm/node-versions"/*/installation/bin \
|
||||
"$HOME/.fnm/node-versions"/*/installation/bin \
|
||||
"$HOME/.volta/bin" \
|
||||
/usr/local/bin
|
||||
do
|
||||
local cand maj min
|
||||
# 글롭은 사전순이라 v20 이 v22 보다 먼저 나온다. 버전 역순으로 정렬해 가장 높은 버전부터 본다.
|
||||
while IFS= read -r cand; do
|
||||
[ -x "$cand/node" ] || continue
|
||||
v="$("$cand/node" -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)"
|
||||
if [ "$v" -ge "$MIN_MAJOR" ]; then
|
||||
read -r maj min <<<"$(node_ver_of "$cand/node")"
|
||||
if version_ok "${maj:-0}" "${min:-0}"; then
|
||||
add_path "$cand"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
done < <(
|
||||
for cand in \
|
||||
"$HOME/.nvm/versions/node"/*/bin \
|
||||
"$HOME/.local/share/fnm/node-versions"/*/installation/bin \
|
||||
"$HOME/.fnm/node-versions"/*/installation/bin \
|
||||
"$HOME/.volta/bin" \
|
||||
/usr/local/bin
|
||||
do
|
||||
printf '%s\n' "$cand"
|
||||
done | sort -rV
|
||||
)
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "$(current_major)" -lt "$MIN_MAJOR" ]; then
|
||||
if ! current_ok; then
|
||||
adopt_newer_node || true
|
||||
fi
|
||||
|
||||
|
|
@ -47,7 +69,7 @@ if ! command -v node >/dev/null 2>&1; then
|
|||
cat >&2 <<'MSG'
|
||||
Node 를 찾을 수 없다.
|
||||
|
||||
이 워크플로는 self-hosted host 러너에서 돈다. 러너 머신에 Node 20 이상을 설치해라.
|
||||
이 워크플로는 self-hosted host 러너에서 돈다. 러너 머신에 Node 22.6 이상을 설치해라.
|
||||
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
|
||||
fnm install 22 && fnm default 22
|
||||
셸 rc 를 고치지 않아도 된다 — 이 스크립트가 설치 경로를 직접 찾는다.
|
||||
|
|
@ -55,10 +77,9 @@ MSG
|
|||
exit 1
|
||||
fi
|
||||
|
||||
major="$(current_major)"
|
||||
if [ "$major" -lt "$MIN_MAJOR" ]; then
|
||||
if ! current_ok; then
|
||||
cat >&2 <<MSG
|
||||
Node $MIN_MAJOR 이상이 필요하다 (현재 $(node -v)).
|
||||
Node $MIN_MAJOR.$MIN_MINOR 이상이 필요하다 (현재 $(node -v)).
|
||||
|
||||
러너에 새 Node 가 설치돼 있는데도 이 메시지가 나오면, 이 스크립트가 훑는 경로 밖에
|
||||
있는 것이다. 아래 중 한 곳에 두거나 러너 사용자의 PATH 에 올려라.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue