mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
fix(scripts): add short help to stale CI cleanup (#3222)
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import { dirname, join, resolve } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { test } from 'node:test';
|
||||||
|
|
||||||
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const SCRIPT = resolve(HERE, '..', 'cancel-stale-pr-ci.mjs');
|
||||||
|
|
||||||
|
function runHelp(flag) {
|
||||||
|
const binDir = fs.mkdtempSync(join(os.tmpdir(), 'openhuman-gh-stub-'));
|
||||||
|
fs.writeFileSync(
|
||||||
|
join(binDir, 'gh'),
|
||||||
|
'#!/usr/bin/env sh\necho "gh should not run for help" >&2\nexit 99\n',
|
||||||
|
{ mode: 0o755 },
|
||||||
|
);
|
||||||
|
|
||||||
|
return spawnSync(process.execPath, [SCRIPT, flag], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PATH: `${binDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH ?? ''}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('cancel-stale-pr-ci help exits before invoking gh', () => {
|
||||||
|
for (const flag of ['--help', '-h']) {
|
||||||
|
const result = runHelp(flag);
|
||||||
|
|
||||||
|
assert.equal(result.status, 0, result.stderr);
|
||||||
|
assert.match(result.stdout, /Usage: cancel-stale-pr-ci\.mjs \[options\]/);
|
||||||
|
assert.match(result.stdout, /-h, --help\s+Show this message\./);
|
||||||
|
assert.equal(result.stderr, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -21,7 +21,7 @@ Options:
|
|||||||
--exclude-workflow <pattern> Case-insensitive substring/regex fragment to skip.
|
--exclude-workflow <pattern> Case-insensitive substring/regex fragment to skip.
|
||||||
May be passed multiple times. Default: ${DEFAULT_EXCLUDE_WORKFLOW_PATTERNS.join(', ')}
|
May be passed multiple times. Default: ${DEFAULT_EXCLUDE_WORKFLOW_PATTERNS.join(', ')}
|
||||||
--execute Actually cancel matching runs.
|
--execute Actually cancel matching runs.
|
||||||
--help Show this message.
|
-h, --help Show this message.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
node scripts/cancel-stale-pr-ci.mjs
|
node scripts/cancel-stale-pr-ci.mjs
|
||||||
@@ -61,7 +61,7 @@ function parseArgs(argv) {
|
|||||||
|
|
||||||
for (let i = 0; i < argv.length; i += 1) {
|
for (let i = 0; i < argv.length; i += 1) {
|
||||||
const arg = argv[i];
|
const arg = argv[i];
|
||||||
if (arg === '--help') {
|
if (arg === '--help' || arg === '-h') {
|
||||||
printUsage();
|
printUsage();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user