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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/check-changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ jobs:
yarn ts-node-script scripts/ci/check_changeset.ts
id: check-changeset
- name: Print changeset checker output
run: echo "${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}"
run: |
cat << 'eof_delimiter_that_will_never_occur_in_CHANGESET_ERROR_MESSAGE'
${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
eof_delimiter_that_will_never_occur_in_CHANGESET_ERROR_MESSAGE
- name: Print blocking failure status
run: echo "${{steps.check-changeset.outputs.BLOCKING_FAILURE}}"
- name: Find Comment
Expand Down
18 changes: 15 additions & 3 deletions scripts/ci/check_changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { resolve } from 'path';
import { existsSync } from 'fs';
import { writeFile } from 'fs/promises';
import { exec } from 'child-process-promise';
import chalk from 'chalk';
import simpleGit from 'simple-git';
Expand All @@ -28,6 +29,14 @@ const git = simpleGit(root);
const baseRef = process.env.GITHUB_PULL_REQUEST_BASE_SHA || 'master';
const headRef = process.env.GITHUB_PULL_REQUEST_HEAD_SHA || 'HEAD';

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.

}
return value;
})();

// Version bump text converted to rankable numbers.
const bumpRank: Record<string, number> = {
'patch': 0,
Expand Down Expand Up @@ -205,10 +214,13 @@ async function main() {
* step. See:
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
*/
if (errors.length > 0)
await exec(
`echo "CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}" >> $GITHUB_OUTPUT`
if (errors.length > 0) {
await writeFile(
githubOutputFile,
`CHANGESET_ERROR_MESSAGE=${errors.join('%0A')}\n`,
{ flag: 'a' }
);
}
process.exit();
}

Expand Down