nixpkgs/ci/github-script/run.js
Wolfgang Walther aaaabe0cb7
ci/github-script: add commander CLI interface
This makes it easier to add additional features.
2025-07-14 10:35:17 +02:00

56 lines
1.4 KiB
JavaScript
Executable file

#!/usr/bin/env node
import { execSync } from 'node:child_process'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { program } from 'commander'
import { getOctokit } from '@actions/github'
async function run(action, owner, repo) {
const token = execSync('gh auth token', { encoding: 'utf-8' }).trim()
const tmp = mkdtempSync(join(tmpdir(), 'github-script-'))
try {
process.env.GITHUB_WORKSPACE = tmp
process.chdir(tmp)
await action({
github: getOctokit(token),
context: {
payload: {},
repo: {
owner,
repo,
},
},
core: {
getInput() {
return token
},
error: console.error,
info: console.log,
notice: console.log,
setFailed(msg) {
console.error(msg)
process.exitCode = 1
},
},
dry: true,
})
} finally {
rmSync(tmp, { recursive: true })
}
}
program
.command('labels')
.description('Manage labels on pull requests.')
.argument('<owner>', 'Owner of the GitHub repository to label (Example: NixOS)')
.argument('<repo>', 'Name of the GitHub repository to label (Example: nixpkgs)')
.action(async (owner, repo) => {
const labels = (await import('./labels.cjs')).default
run(labels, owner, repo)
})
await program.parse()