diff --git a/ci/github-script/README.md b/ci/github-script/README.md index 73cb4119a68d..e71a4f173c57 100644 --- a/ci/github-script/README.md +++ b/ci/github-script/README.md @@ -10,4 +10,4 @@ To run any of the scripts locally: ## Labeler -Run `./run.js OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs". +Run `./run.js labels OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs". diff --git a/ci/github-script/package-lock.json b/ci/github-script/package-lock.json index 5c5ee09ad67e..538083dcea93 100644 --- a/ci/github-script/package-lock.json +++ b/ci/github-script/package-lock.json @@ -1,5 +1,5 @@ { - "name": "labels", + "name": "github-script", "lockfileVersion": 3, "requires": true, "packages": { @@ -7,7 +7,8 @@ "dependencies": { "@actions/artifact": "2.3.2", "@actions/github": "6.0.1", - "bottleneck": "2.19.5" + "bottleneck": "2.19.5", + "commander": "14.0.0" } }, "node_modules/@actions/artifact": { @@ -950,6 +951,15 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/commander": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz", + "integrity": "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, "node_modules/compress-commons": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-6.0.2.tgz", diff --git a/ci/github-script/package.json b/ci/github-script/package.json index e07813aa86b5..906f371f0d5d 100644 --- a/ci/github-script/package.json +++ b/ci/github-script/package.json @@ -4,6 +4,7 @@ "dependencies": { "@actions/artifact": "2.3.2", "@actions/github": "6.0.1", - "bottleneck": "2.19.5" + "bottleneck": "2.19.5", + "commander": "14.0.0" } } diff --git a/ci/github-script/run.js b/ci/github-script/run.js index 7f3f92e7b1f0..5127a6a0ee95 100755 --- a/ci/github-script/run.js +++ b/ci/github-script/run.js @@ -3,43 +3,53 @@ 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' -import labels from './labels.cjs' -if (process.argv.length !== 4) - throw new Error('Call this with exactly three arguments: ./run OWNER REPO') -const [, , owner, repo] = process.argv +async function run(action, owner, repo) { + const token = execSync('gh auth token', { encoding: 'utf-8' }).trim() -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) -const tmp = mkdtempSync(join(tmpdir(), 'labels-')) -try { - process.env.GITHUB_WORKSPACE = tmp - process.chdir(tmp) - - await labels({ - github: getOctokit(token), - context: { - payload: {}, - repo: { - owner, - repo, + await action({ + github: getOctokit(token), + context: { + payload: {}, + repo: { + owner, + repo, + }, }, - }, - core: { - getInput() { - return token + core: { + getInput() { + return token + }, + error: console.error, + info: console.log, + notice: console.log, + setFailed(msg) { + console.error(msg) + process.exitCode = 1 + }, }, - error: console.error, - info: console.log, - notice: console.log, - setFailed(msg) { - console.error(msg) - process.exitCode = 1 - }, - }, - dry: true, - }) -} finally { - rmSync(tmp, { recursive: true }) + dry: true, + }) + } finally { + rmSync(tmp, { recursive: true }) + } } + +program + .command('labels') + .description('Manage labels on pull requests.') + .argument('', 'Owner of the GitHub repository to label (Example: NixOS)') + .argument('', '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()