Skip to content

Fix errors in reporting errors in the "Check changeset vs changed files" workflow #7964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2024

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Jan 19, 2024

…AGE 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.
```
…interpolation of special characters in CHANGESET_ERROR_MESSAGE

This fixes the following error in the "Print changeset checker output" step:

```
/home/runner/work/_temp/05ad4244-c741-4473-b5fa-88197e013f3c.sh: line 1: fg: no job control
/home/runner/work/_temp/05ad4244-c741-4473-b5fa-88197e013f3c.sh: command substitution: line 1: unexpected EOF while looking for matching `''
/home/runner/work/_temp/05ad4244-c741-4473-b5fa-88197e013f3c.sh: command substitution: line 2: syntax error: unexpected end of file
/home/runner/work/_temp/05ad4244-c741-4473-b5fa-88197e013f3c.sh: line 1: .%0A: command not found
- Changeset formatting error in following file:%0A    changeset addchangeset add --empty%0A
```

e.g. https://github.com/firebase/firebase-js-sdk/actions/runs/7586786834/job/20665754718
@dconeybe dconeybe self-assigned this Jan 19, 2024
Copy link

changeset-bot bot commented Jan 19, 2024

⚠️ No Changeset found

Latest commit: 16984af

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

dconeybe added a commit that referenced this pull request Jan 19, 2024
…i/check_changeset.ts since they have been moved to a separate PR (#7964)
@google-oss-bot
Copy link
Contributor

@google-oss-bot
Copy link
Contributor

@dconeybe dconeybe marked this pull request as ready for review January 19, 2024 18:28
@dconeybe dconeybe requested a review from a team as a code owner January 19, 2024 18:28
const githubOutputFile = (function (): string {
const value = process.env.GITHUB_OUTPUT;
if (!value) {
throw new Error('GITHUB_OUTPUT environment variable must be set');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what was the case where GITHUB_OUTPUT was not set? Is this for local testing? With this error does it get far enough in local testing for the output to be useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never encountered that. I just added that check so that the TypeScript compiler would type githubOutputFile as string instead of string | undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The later call to writeFile(githubOutputFile, ...) will fail to compile if githubOutputFile is string | undefined; however, it compiles fine if it is string.

@dconeybe dconeybe merged commit 4b5a82e into master Jan 19, 2024
@dconeybe dconeybe deleted the dconeybe/CheckChangesetErrorShellInterpolationBugFix branch January 19, 2024 18:48
@firebase firebase locked and limited conversation to collaborators Feb 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants