Skip to content

Commit f358119

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 bb81bad commit f358119

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

scripts/ci/check_changeset.ts

Lines changed: 7 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';
@@ -205,10 +206,13 @@ async function main() {
205206
* step. See:
206207
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
207208
*/
208-
if (errors.length > 0)
209-
await exec(
210-
`echo "CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}" >> $GITHUB_OUTPUT`
209+
if (errors.length > 0) {
210+
await writeFile(
211+
process.env.GITHUB_OUTPUT,
212+
`CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}\n`,
213+
{ flag: 'a' }
211214
);
215+
}
212216
process.exit();
213217
}
214218

0 commit comments

Comments
 (0)