fix(ci): unblock headless test runs and manage Forgejo secrets from .env
- desktop: mock @nut-tree-fork/nut-js in the shared Vitest setup; template
tests reached the real TextInsertService and libnut killed the worker on the
display-less Linux runner ("Could not open main display").
- mobile: the knowledge realtime test now unsubscribes, so the deletion
reconcile interval no longer keeps Jest alive forever.
- set-forgejo-secrets.mjs syncs every Forgejo secret from the root .env and
refuses local URLs; SUPABASE_URL had been registered as 127.0.0.1:55321, so
payple-renew never succeeded.
This commit is contained in:
parent
3cac14f668
commit
a7c0d6fb21
5 changed files with 98 additions and 59 deletions
|
|
@ -1,13 +1,18 @@
|
|||
// scripts/ci/set-forgejo-secrets.mjs
|
||||
// Forgejo Actions 저장소 시크릿을 점검하거나 등록한다.
|
||||
// Forgejo Actions 저장소 시크릿을 루트 .env 기준으로 점검하거나 맞춘다.
|
||||
//
|
||||
// 배경: 데스크톱 릴리스 워크플로(.forgejo/workflows/release.yml)는 아래 시크릿이
|
||||
// 없으면 fail-closed로 중단한다. 저장소에 시크릿이 하나도 없으면 태그를 올려도
|
||||
// 설치본이 게시되지 않는다(실측: run 49/51 모두 서명 가드에서 실패).
|
||||
// 원칙: 시크릿 값의 정본은 루트 .env 다. Forgejo 웹 UI 에서 손으로 넣지 말고
|
||||
// .env 를 고친 뒤 --write 로 밀어 넣는다. Forgejo API 는 값을 돌려주지 않으므로
|
||||
// --write 는 .env 에 값이 있는 시크릿을 항상 덮어쓴다.
|
||||
//
|
||||
// 배경: 2026-09-26 SUPABASE_URL 시크릿에 로컬 Supabase 주소(127.0.0.1:55321)가
|
||||
// 들어가 payple-renew 크론이 한 번도 성공하지 못했다. 그래서 운영 시크릿에는
|
||||
// 로컬 주소를 거부하는 검사를 둔다.
|
||||
//
|
||||
// 사용:
|
||||
// node scripts/ci/set-forgejo-secrets.mjs --check # 현재 상태만 확인
|
||||
// node --env-file-if-exists=.env scripts/ci/set-forgejo-secrets.mjs --write
|
||||
// node scripts/ci/set-forgejo-secrets.mjs --check # 등록 여부 + .env 값 검사
|
||||
// node scripts/ci/set-forgejo-secrets.mjs --write # .env 값으로 등록/덮어쓰기
|
||||
// node scripts/ci/set-forgejo-secrets.mjs --write SUPABASE_URL CRON_SECRET # 일부만
|
||||
//
|
||||
// 값은 출력하지 않는다(이름/존재 여부/길이만). FORGEJO_TOKEN(쓰기 스코프 필요)은
|
||||
// .env 또는 환경변수에서 읽는다.
|
||||
|
|
@ -16,18 +21,26 @@ import { readFileSync, existsSync } from 'node:fs'
|
|||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const REQUIRED = [
|
||||
'WIN_CSC_LINK',
|
||||
'WIN_CSC_KEY_PASSWORD',
|
||||
'WIN_CSC_EXPECTED_SIGNER_SUBJECT',
|
||||
'FORGEJO_TOKEN',
|
||||
// Forgejo 시크릿 이름 → .env 키. required=false 는 값이 없으면 건너뛴다.
|
||||
const SECRETS = [
|
||||
{ name: 'SUPABASE_URL', envKey: 'SUPABASE_URL', required: true, url: true, usedBy: 'payple-renew.yml' },
|
||||
{ name: 'CRON_SECRET', envKey: 'CRON_SECRET', required: true, usedBy: 'payple-renew.yml' },
|
||||
{ name: 'CF_API_TOKEN', envKey: 'CLOUDFLARE_API_TOKEN', required: true, usedBy: 'deploy-site.yml' },
|
||||
{ name: 'CF_ACCOUNT_ID', envKey: 'CLOUDFLARE_ACCOUNT_ID', required: true, usedBy: 'deploy-site.yml' },
|
||||
{ name: 'FORGEJO_TOKEN', envKey: 'FORGEJO_TOKEN', required: true, usedBy: 'release.yml, portable.yml' },
|
||||
{ name: 'WIN_CSC_LINK', envKey: 'WIN_CSC_LINK', required: false, usedBy: 'release.yml' },
|
||||
{ name: 'WIN_CSC_KEY_PASSWORD', envKey: 'WIN_CSC_KEY_PASSWORD', required: false, usedBy: 'release.yml' },
|
||||
{ name: 'WIN_CSC_EXPECTED_SIGNER_SUBJECT', envKey: 'WIN_CSC_EXPECTED_SIGNER_SUBJECT', required: false, usedBy: 'release.yml' },
|
||||
]
|
||||
|
||||
const LOCAL_HOST = /^(https?:\/\/)?(localhost|127\.|0\.0\.0\.0|\[::1\]|host\.docker\.internal)/i
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
|
||||
const args = process.argv.slice(2)
|
||||
const write = args.includes('--write')
|
||||
const only = args.filter((arg) => !arg.startsWith('--'))
|
||||
|
||||
/** .env(있으면) + 환경변수에서 값 조회. 값은 로그에 절대 남기지 않는다. */
|
||||
/** .env(있으면) + 환경변수에서 값 조회. .env 가 우선이다(정본). 값은 로그에 남기지 않는다. */
|
||||
function readEnv() {
|
||||
const values = { ...process.env }
|
||||
const envPath = join(root, '.env')
|
||||
|
|
@ -35,14 +48,23 @@ function readEnv() {
|
|||
for (const line of readFileSync(envPath, 'utf8').split(/\r?\n/)) {
|
||||
if (!/^[A-Z0-9_]+=/.test(line)) continue
|
||||
const index = line.indexOf('=')
|
||||
const key = line.slice(0, index)
|
||||
if (values[key]) continue
|
||||
values[key] = line.slice(index + 1).trim()
|
||||
const value = line.slice(index + 1).trim().replace(/^(['"])(.*)\1$/, '$2')
|
||||
if (value) values[line.slice(0, index)] = value
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
/** 값이 운영 시크릿으로 쓸 수 있는지. 문제가 있으면 이유를, 없으면 null. */
|
||||
function validate(spec, value) {
|
||||
if (!value) return spec.required ? '.env 에 값 없음' : null
|
||||
if (spec.url) {
|
||||
if (LOCAL_HOST.test(value)) return '로컬 주소는 운영 시크릿이 될 수 없음'
|
||||
if (!/^https:\/\/[^/]+$/.test(value.replace(/\/$/, ''))) return 'https://<host> 형식이어야 함'
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const env = readEnv()
|
||||
const token = env.FORGEJO_TOKEN?.trim()
|
||||
const server = (env.GIT_SERVER_URL?.trim() || 'https://git.chanpaca.net').replace(/\/$/, '')
|
||||
|
|
@ -72,60 +94,51 @@ async function putSecret(name, value) {
|
|||
headers: { ...headers, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ data: value }),
|
||||
})
|
||||
if (!response.ok && response.status !== 201 && response.status !== 204) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`${name} 등록 실패: HTTP ${response.status}`)
|
||||
}
|
||||
}
|
||||
|
||||
const existing = await listSecrets()
|
||||
console.log(`저장소: ${owner}/${repo} (${server})`)
|
||||
console.log(`시크릿 API: ${apiBase}\n`)
|
||||
|
||||
let missing = 0
|
||||
for (const name of REQUIRED) {
|
||||
const present = existing.has(name)
|
||||
if (present) {
|
||||
console.log(` [x] ${name} — 등록됨`)
|
||||
continue
|
||||
}
|
||||
missing += 1
|
||||
const value = env[name]?.trim()
|
||||
console.log(` [ ] ${name} — 없음${value ? ` (환경/.env에 값 있음, 길이 ${value.length})` : ' (값 없음)'}`)
|
||||
const unknown = only.filter((name) => !SECRETS.some((spec) => spec.name === name))
|
||||
if (unknown.length) {
|
||||
console.error(`알 수 없는 시크릿: ${unknown.join(', ')}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const targets = only.length ? SECRETS.filter((spec) => only.includes(spec.name)) : SECRETS
|
||||
|
||||
if (missing === 0) {
|
||||
console.log('\n모든 릴리스 시크릿이 준비되었습니다.')
|
||||
process.exit(0)
|
||||
const existing = await listSecrets()
|
||||
console.log(`저장소: ${owner}/${repo} (${server})\n`)
|
||||
|
||||
let problems = 0
|
||||
for (const spec of targets) {
|
||||
const value = env[spec.envKey]?.trim()
|
||||
const issue = validate(spec, value)
|
||||
const registered = existing.has(spec.name) ? '등록됨' : '없음'
|
||||
const source = value ? `.env ${spec.envKey} 길이 ${value.length}` : `.env ${spec.envKey} 없음`
|
||||
if (issue && (spec.required || value)) problems += 1
|
||||
console.log(` [${issue ? '!' : 'x'}] ${spec.name} — ${registered}, ${source}${issue ? ` — ${issue}` : ''} (${spec.usedBy})`)
|
||||
}
|
||||
|
||||
if (!write) {
|
||||
console.log(
|
||||
[
|
||||
`\n누락 ${missing}건. 값이 준비되면 다음으로 등록한다:`,
|
||||
' node --env-file-if-exists=.env scripts/ci/set-forgejo-secrets.mjs --write',
|
||||
'',
|
||||
'WIN_CSC_LINK는 public-trust Authenticode PFX를 base64로 인코딩한 값이어야 하며,',
|
||||
'WIN_CSC_EXPECTED_SIGNER_SUBJECT는 그 인증서의 정확한 subject 문자열이어야 한다.',
|
||||
'(개발용 Everything2EverythingDev 인증서는 production으로 인정되지 않는다.)',
|
||||
].join('\n'),
|
||||
)
|
||||
process.exit(missing === 0 ? 0 : 2)
|
||||
console.log(problems ? `\n문제 ${problems}건.` : '\n.env 값 검사 통과. --write 로 Forgejo 에 반영한다.')
|
||||
process.exit(problems ? 2 : 0)
|
||||
}
|
||||
|
||||
if (problems) {
|
||||
console.error('\n.env 값에 문제가 있어 아무것도 쓰지 않았다. .env 를 고친 뒤 다시 실행한다.')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
let written = 0
|
||||
for (const name of REQUIRED) {
|
||||
if (existing.has(name)) continue
|
||||
const value = env[name]?.trim()
|
||||
if (!value) {
|
||||
console.log(` 건너뜀: ${name} (값 없음)`)
|
||||
continue
|
||||
}
|
||||
await putSecret(name, value)
|
||||
for (const spec of targets) {
|
||||
const value = env[spec.envKey]?.trim()
|
||||
if (!value) continue
|
||||
await putSecret(spec.name, value)
|
||||
written += 1
|
||||
console.log(` 등록: ${name}`)
|
||||
console.log(` 반영: ${spec.name}`)
|
||||
}
|
||||
|
||||
const after = await listSecrets()
|
||||
const stillMissing = REQUIRED.filter((name) => !after.has(name))
|
||||
console.log(`\n등록 ${written}건. 남은 누락: ${stillMissing.length ? stillMissing.join(', ') : '없음'}`)
|
||||
process.exit(stillMissing.length === 0 ? 0 : 2)
|
||||
const stillMissing = targets.filter((spec) => spec.required && !after.has(spec.name)).map((spec) => spec.name)
|
||||
console.log(`\n반영 ${written}건. 남은 누락: ${stillMissing.length ? stillMissing.join(', ') : '없음'}`)
|
||||
process.exit(stillMissing.length === 0 ? 0 : 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue