- .github/workflows: ci.yml (job único checks hosted), deploy.yml (verify hosted full → deploy self-hosted no homeserver), flips pós-merge via API (FORGEJO_API_TOKEN/PR_BODY, fail-loud), auto-merge nativo (GraphQL) - scripts: github-api/pr-flow/branch-protection (plain Node zero-dep), pr.mjs reescrito (GitHub + auto-merge), configure-branch-protection, deploy-iara.sh (local, sem SSH, idempotente), forgejo-issue-transition com PR_BODY + fail-loud (I10 absorvida) - AGENTS.md/runbook: seção CI GitHub, branch protection REAL em main, passos manuais do cutover
70 lines
2.7 KiB
JavaScript
70 lines
2.7 KiB
JavaScript
/**
|
|
* Project env loader — lê `.forgejo/worktree.env` do repo (subindo do CWD) e
|
|
* aplica em `process.env` quando as variáveis ainda não estão setadas. É o que
|
|
* permite que os scripts rodem por qualquer caminho (comando `/worktree` do
|
|
* opencode, `bun run issue`, roteador de terminal) sem depender de exportação
|
|
* global. Arquivo commitado, sem segredos.
|
|
*
|
|
* OPS1: além do tracker (FORGEJO_REPOSITORY), também resolve o repo GitHub
|
|
* (GITHUB_REPOSITORY) — o default dos scripts de PR/CI (`pr.mjs`,
|
|
* `configure-branch-protection.mjs`).
|
|
*/
|
|
|
|
import { existsSync, readFileSync } from 'node:fs'
|
|
import { dirname, join, resolve } from 'node:path'
|
|
|
|
const parseEnvFile = (text) => {
|
|
const out = {}
|
|
for (const raw of text.split('\n')) {
|
|
const line = raw.trim()
|
|
if (line === '' || line.startsWith('#')) continue
|
|
const eq = line.indexOf('=')
|
|
if (eq <= 0) continue
|
|
const key = line.slice(0, eq).trim()
|
|
const value = line.slice(eq + 1).trim().replace(/^["']|["']$/g, '')
|
|
if (key) out[key] = value
|
|
}
|
|
return out
|
|
}
|
|
|
|
/** Caminho do `.forgejo/worktree.env` do projeto dono do CWD (ou null). */
|
|
export const findProjectEnvFile = (from = process.cwd()) => {
|
|
let dir = resolve(from)
|
|
for (;;) {
|
|
const candidate = join(dir, '.forgejo', 'worktree.env')
|
|
if (existsSync(candidate)) return candidate
|
|
const parent = dirname(dir)
|
|
if (parent === dir) return null
|
|
dir = parent
|
|
}
|
|
}
|
|
|
|
/** Expande um `~` inicial (ex. `~/.worktrees/iara`) para o homedir. */
|
|
export const expandHome = (value) => {
|
|
if (typeof value !== 'string' || !value.startsWith('~')) return value
|
|
return join(process.env.HOME ?? '', value.slice(1))
|
|
}
|
|
|
|
/**
|
|
* Carrega o `.forgejo/worktree.env` do projeto do CWD (se existir) em
|
|
* process.env — só preenche o que ainda não está definido. Retorna o config
|
|
* resolvido: { repo, worktreesRoot }.
|
|
*/
|
|
export const loadProjectEnv = (from = process.cwd()) => {
|
|
const file = findProjectEnvFile(from)
|
|
const parsed = file ? parseEnvFile(readFileSync(file, 'utf8')) : {}
|
|
|
|
const repo =
|
|
process.env.FORGEJO_REPOSITORY ?? parsed.FORGEJO_REPOSITORY ?? process.env.GITHUB_REPOSITORY ?? 'amana/iara-pwa'
|
|
const githubRepo =
|
|
process.env.GITHUB_REPOSITORY ?? parsed.GITHUB_REPOSITORY ?? 'fsolla/iara-pwa'
|
|
const worktreesRoot = expandHome(
|
|
process.env.WORKTREES_ROOT ?? parsed.WORKTREES_ROOT ?? `~/.worktrees/${repo.split('/')[1] ?? 'work'}`,
|
|
)
|
|
|
|
if (!process.env.FORGEJO_REPOSITORY) process.env.FORGEJO_REPOSITORY = repo
|
|
if (!process.env.GITHUB_REPOSITORY) process.env.GITHUB_REPOSITORY = githubRepo
|
|
if (!process.env.WORKTREES_ROOT) process.env.WORKTREES_ROOT = worktreesRoot
|
|
|
|
return { repo, worktreesRoot, envFile: file }
|
|
}
|