Skip to content

Commit 579b216

Browse files
committed
Add changeset status check
1 parent 0c53a93 commit 579b216

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

.github/workflows/check-changeset.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,38 @@ jobs:
2222
- name: Run changeset script
2323
run: yarn ts-node-script scripts/check_changeset.ts
2424
id: check-changeset
25-
- name: Read output
26-
run: echo "${{steps.check-changeset.outputs.MISSING_PACKAGES}}"
25+
- name: Print changeset checker output
26+
run: echo "${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}"
2727
- name: Find Comment
2828
uses: peter-evans/find-comment@v1
2929
id: fc
3030
with:
3131
issue-number: ${{github.event.number}}
3232
body-includes: Changeset File Check
3333
- name: Create comment (missing packages)
34-
if: ${{!steps.fc.outputs.comment-id && steps.check-changeset.outputs.MISSING_PACKAGES}}
34+
if: ${{!steps.fc.outputs.comment-id && steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
3535
uses: peter-evans/create-or-update-comment@v1
3636
with:
3737
issue-number: ${{github.event.number}}
3838
body: |
3939
### Changeset File Check :warning:
40-
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
41-
${{steps.check-changeset.outputs.MISSING_PACKAGES}}
42-
43-
Make sure this was intentional.
40+
${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
4441
- name: Update comment (missing packages)
4542
if: ${{steps.fc.outputs.comment-id}}
4643
uses: peter-evans/create-or-update-comment@v1
4744
with:
48-
comment-id: ${{steps.fc.outputs.comment-id}} && steps.check-changeset.outputs.MISSING_PACKAGES}}
45+
comment-id: ${{steps.fc.outputs.comment-id}} && steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
4946
edit-mode: replace
5047
body: |
5148
### Changeset File Check :warning:
52-
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
53-
${{steps.check-changeset.outputs.MISSING_PACKAGES}}
54-
55-
Make sure this was intentional.
49+
${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
5650
- name: Update comment (no missing packages)
57-
if: ${{steps.fc.outputs.comment-id && !steps.check-changeset.outputs.MISSING_PACKAGES}}
51+
if: ${{steps.fc.outputs.comment-id && !steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
5852
uses: peter-evans/create-or-update-comment@v1
5953
with:
6054
comment-id: ${{steps.fc.outputs.comment-id}}
6155
edit-mode: replace
6256
body: |
6357
### Changeset File Check :white_check_mark:
64-
No modified packages are missing from the changeset file.
58+
- No modified packages are missing from the changeset file.
59+
- No changeset formatting errors detected.

scripts/check_changeset.ts

Lines changed: 37 additions & 11 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 { exec } from 'child-process-promise';
2021
import chalk from 'chalk';
2122
import simpleGit from 'simple-git/promise';
2223
import fs from 'mz/fs';
@@ -83,6 +84,21 @@ async function parseChangesetFile(changesetFile: string) {
8384
}
8485

8586
async function main() {
87+
let formattedStatusError: string = '';
88+
let missingPackagesError: string = '';
89+
try {
90+
await exec('yarn changeset status');
91+
} catch (e) {
92+
const messageLines = e.message.replace(/🦋 error /g, '').split('\n');
93+
formattedStatusError = 'Changeset formatting error in following file:%0A';
94+
formattedStatusError += messageLines
95+
.filter(
96+
(line: string) => !line.match(/^ at [\w\.]+ \(.+:[0-9]+:[0-9]+\)/)
97+
)
98+
.filter((line: string) => !line.includes('Command failed'))
99+
.filter((line: string) => !line.includes('exited with error code 1'))
100+
.join('%0A');
101+
}
86102
try {
87103
const diffData = await getDiffData();
88104
if (diffData == null) {
@@ -94,23 +110,33 @@ async function main() {
94110
changedPkg => !changesetPackages.includes(changedPkg)
95111
);
96112
if (missingPackages.length > 0) {
97-
/**
98-
* Sets Github Actions output for a step. Pass missing package list to next
99-
* step. See:
100-
* https://github.com/actions/toolkit/blob/master/docs/commands.md#set-outputs
101-
*/
102-
console.log(
103-
`::set-output name=MISSING_PACKAGES::${missingPackages
104-
.map(pkg => `- ${pkg}`)
105-
.join('%0A')}`
106-
);
113+
missingPackagesError = `Warning: This PR modifies files in the following packages but they have not been included in the changeset file:%0A
114+
${missingPackages.map(pkg => `- ${pkg}`).join('%0A')}
115+
%0A
116+
Make sure this was intentional.%0A`;
107117
}
108-
process.exit();
109118
}
110119
} catch (e) {
111120
console.error(chalk`{red ${e}}`);
112121
process.exit(1);
113122
}
123+
124+
/**
125+
* Sets Github Actions output for a step. Pass changeset error message to next
126+
* step. See:
127+
* https://github.com/actions/toolkit/blob/master/docs/commands.md#set-outputs
128+
*/
129+
console.log(
130+
`::set-output name=CHANGESET_ERROR_MESSAGE::${[
131+
formattedStatusError,
132+
missingPackagesError
133+
].join('%0A')}`
134+
);
135+
if (formattedStatusError) {
136+
process.exit(1);
137+
} else {
138+
process.exit();
139+
}
114140
}
115141

116142
main();

0 commit comments

Comments
 (0)