Skip to content

Commit c12d6e5

Browse files
committed
check_changeset.ts: use writeFile() to write the CHANGESET_ERROR_MESSAGE to $GITHUB_OUTPUT instead of echo since embedded quotes in the error message cause the shell to mis-interpret them
For example, in https://github.com/firebase/firebase-js-sdk/actions/runs/7586489122/job/20664769245?pr=7952 the following error occurred, which this commit fixes: ``` $ /home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/.bin/ts-node-script scripts/ci/check_changeset.ts /home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/child-process-promise/lib/index.js:33 var cpError = new ChildProcessError(err.message, err.code, child_process, stdout, stderr); ^ ChildProcessError: Command failed: echo "CHANGESET_ERROR_MESSAGE=- Changeset formatting error in following file:%0A \`\`\`%0A Some packages have been changed but no changesets were found. Run \`changeset add\` to resolve this error.%0A If this change doesn't need a release, run \`changeset add --empty\`.%0A \`\`\`%0A" >> $GITHUB_OUTPUT /bin/sh: 1: Syntax error: Unterminated quoted string \`echo "CHANGESET_ERROR_MESSAGE=- Changeset formatting error in following file:%0A \`\`\`%0A Some packages have been changed but no changesets were found. Run \`changeset add\` to resolve this error.%0A If this change doesn't need a release, run \`changeset add --empty\`.%0A \`\`\`%0A" >> $GITHUB_OUTPUT\` (exited with error code 2) at callback (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/child-process-promise/lib/index.js:33:27) at ChildProcess.exithandler (node:child_process:410:5) at ChildProcess.emit (node:events:513:28) at ChildProcess.emit (node:domain:489:12) at maybeClose (node:internal/child_process:1100:16) at Socket.<anonymous> (node:internal/child_process:458:11) at Socket.emit (node:events:513:28) at Socket.emit (node:domain:489:12) at Pipe.<anonymous> (node:net:301:12) { code: 2, childProcess: { _forkChild: [Function: _forkChild], ChildProcess: [Function: ChildProcess], exec: [Function: exec], execFile: [Function: execFile], execFileSync: [Function: execFileSync], execSync: [Function: execSync], fork: [Function: fork], spawn: [Function: spawn], spawnSync: [Function: spawnSync] }, stdout: '', stderr: '/bin/sh: 1: Syntax error: Unterminated quoted string\n' } error Command failed with exit code 1. ```
1 parent 49c7903 commit c12d6e5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

scripts/ci/check_changeset.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { resolve } from 'path';
1919
import { existsSync } from 'fs';
20+
import { writeFile } from 'fs/promises';
2021
import { exec } from 'child-process-promise';
2122
import chalk from 'chalk';
2223
import simpleGit from 'simple-git';
@@ -28,6 +29,14 @@ const git = simpleGit(root);
2829
const baseRef = process.env.GITHUB_PULL_REQUEST_BASE_SHA || 'master';
2930
const headRef = process.env.GITHUB_PULL_REQUEST_HEAD_SHA || 'HEAD';
3031

32+
const githubOutputFile = (function (): string {
33+
const value = process.env.GITHUB_OUTPUT;
34+
if (!value) {
35+
throw new Error('GITHUB_OUTPUT environment variable must be set');
36+
}
37+
return value;
38+
})();
39+
3140
// Version bump text converted to rankable numbers.
3241
const bumpRank: Record<string, number> = {
3342
'patch': 0,
@@ -205,10 +214,13 @@ async function main() {
205214
* step. See:
206215
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
207216
*/
208-
if (errors.length > 0)
209-
await exec(
210-
`echo "CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}" >> $GITHUB_OUTPUT`
217+
if (errors.length > 0) {
218+
await writeFile(
219+
githubOutputFile,
220+
`CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}\n`,
221+
{ flag: 'a' }
211222
);
223+
}
212224
process.exit();
213225
}
214226

0 commit comments

Comments
 (0)