Skip to content

Commit d946e2b

Browse files
committed
fix: run gates without optional arguments
1 parent e3cb6f3 commit d946e2b

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎.github/actions/run-gate/action.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ runs:
2222
INPUT_ARGS: ${{ inputs.args }}
2323
run: |
2424
set -euo pipefail
25-
args=()
25+
command=(pnpm gate "$INPUT_GATE")
2626
while IFS= read -r arg; do
2727
if [ -n "$arg" ]; then
28-
args+=("$arg")
28+
command+=("$arg")
2929
fi
3030
done <<< "$INPUT_ARGS"
3131
output_file="$(mktemp)"
32-
pnpm gate "$INPUT_GATE" "${args[@]}" | tee "$output_file"
32+
trap 'rm -f "$output_file"' EXIT
33+
"${command[@]}" | tee "$output_file"
3334
{
3435
echo 'result<<__GATE_OUTPUT__'
3536
tail -n 1 "$output_file"

‎scripts/gate/workflows.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const tracked = execFileSync('git', ['ls-files'], {
2020
.filter(Boolean);
2121
const model = loadModel(repoRoot, tracked);
2222

23-
test('the canonical action binds its structural gate input to pnpm gate', () => {
23+
test('the canonical action binds and runs a structural gate without optional arguments', () => {
2424
const action = parse(
2525
fs.readFileSync(path.join(repoRoot, '.github/actions/run-gate/action.yml'), 'utf8'),
2626
) as {
@@ -31,6 +31,26 @@ test('the canonical action binds its structural gate input to pnpm gate', () =>
3131
const runner = action.runs.steps.at(-1);
3232
assert.equal(runner?.env?.INPUT_GATE, '${{ inputs.gate }}');
3333
assert.match(runner?.run ?? '', /pnpm gate "\$INPUT_GATE"/);
34+
35+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'run-gate-'));
36+
try {
37+
const mockPnpm = path.join(root, 'pnpm');
38+
fs.writeFileSync(mockPnpm, '#!/bin/bash\nprintf "%s\\n" "$@"\n');
39+
fs.chmodSync(mockPnpm, 0o755);
40+
const stdout = execFileSync('/bin/bash', ['-c', runner?.run ?? ''], {
41+
encoding: 'utf8',
42+
env: {
43+
...process.env,
44+
PATH: `${root}:${process.env.PATH ?? ''}`,
45+
INPUT_GATE: 'layering',
46+
INPUT_ARGS: '',
47+
GITHUB_OUTPUT: path.join(root, 'output'),
48+
},
49+
});
50+
assert.equal(stdout, 'gate\nlayering\n');
51+
} finally {
52+
fs.rmSync(root, { recursive: true, force: true });
53+
}
3454
});
3555

3656
/** Write a workflow (and optionally a tree of actions) and load it with the real loader. */

0 commit comments

Comments
 (0)