Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

env.ts

35 lines1.1 KB

1/** Shared entry-point plumbing: token resolution and step-summary output. */
2​
3import { execFile } from 'node:child_process'
4import { appendFile } from 'node:fs/promises'
5import { promisify } from 'node:util'
6​
7const execFileAsync = promisify(execFile)
8​
9export async function resolveToken(): Promise<string> {
10 const fromEnv = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN
11 if (fromEnv) return fromEnv
12 try {
13 const { stdout } = await execFileAsync('gh', ['auth', 'token'])
14 const token = stdout.trim()
15 if (token) return token
16 } catch {
17 // fall through to the error below
18 }
19 throw new Error(
20 'No GitHub token: set GITHUB_TOKEN, or authenticate the gh CLI (`gh auth login`).',
21 )
23​
24export function isDryRun(): boolean {
25 return (
26 process.argv.includes('--dry-run') ||
27 ['1', 'true'].includes((process.env.DRY_RUN ?? '').toLowerCase())
28 )
30​
31/** Append markdown to the GitHub Actions step summary when running in CI. */
32export async function writeStepSummary(markdown: string): Promise<void> {
33 const path = process.env.GITHUB_STEP_SUMMARY
34 if (path) await appendFile(path, `${markdown}\n`)