Skip to content

Commit f8c6ab3

Browse files
committed
Add breaking/dangerous/safe messages to action output
1 parent 1143810 commit f8c6ab3

File tree

9 files changed

+164
-45
lines changed

9 files changed

+164
-45
lines changed

action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
For example, "Check Public API" and "Check Internal API".
1313
annotations:
1414
description: Use annotation (enabled by default)
15+
create-action-check:
16+
description: |
17+
Create Github Action check with summary. When disabled, annotations are disabled too. (enabled by default)
18+
It can be useful to disable, when running on master branch or similar. And when subsequent step is using output and annotations nor check is required.
1519
fail-on-breaking:
1620
description: Fail on breaking changes (enabled by default)
1721
approve-label:
@@ -56,6 +60,12 @@ inputs:
5660
outputs:
5761
changes:
5862
description: Total number of changes
63+
breaking-changes:
64+
description: List of breaking changes. Each item is message string.
65+
dangerous-changes:
66+
description: List of dangerous changes. Each item is message string.
67+
safe-changes:
68+
description: List of safe changes. Each item is message string.
5969
runs:
6070
using: node16
6171
main: action/index.js

action/index.js

+42-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@types/express": "4.17.20",
7979
"@types/node": "20.8.7",
8080
"@types/yargs": "17.0.32",
81-
"@zeit/ncc": "0.22.3",
81+
"@vercel/ncc": "0.38.1",
8282
"bob-the-bundler": "7.0.1",
8383
"eslint": "8.51.0",
8484
"graphql": "16.8.1",

packages/action/helpers/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface ActionResult {
88
changes?: Change[];
99
}
1010

11+
export interface GroupedChanges {
12+
breaking: Change[];
13+
dangerous: Change[];
14+
safe: Change[];
15+
}
16+
1117
export interface Annotation {
1218
path: string;
1319
start_line: number;

packages/action/helpers/utils.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Change, CriticalityLevel } from '@graphql-inspector/core';
22
import { Endpoint } from './config.js';
3+
import { GroupedChanges } from './types.js';
34

45
export function bolderize(msg: string): string {
56
return quotesTransformer(msg, '**');
@@ -28,17 +29,23 @@ export function filterChangesByLevel(level: CriticalityLevel) {
2829
return (change: Change) => change.criticality.level === level;
2930
}
3031

32+
export function splitChangesIntoGroups(changes: Change[]): GroupedChanges {
33+
return {
34+
breaking: changes.filter(filterChangesByLevel(CriticalityLevel.Breaking)),
35+
dangerous: changes.filter(filterChangesByLevel(CriticalityLevel.Dangerous)),
36+
safe: changes.filter(filterChangesByLevel(CriticalityLevel.NonBreaking)),
37+
};
38+
}
39+
3140
export function createSummary(changes: Change[], summaryLimit: number, isLegacyConfig = false) {
32-
const breakingChanges = changes.filter(filterChangesByLevel(CriticalityLevel.Breaking));
33-
const dangerousChanges = changes.filter(filterChangesByLevel(CriticalityLevel.Dangerous));
34-
const safeChanges = changes.filter(filterChangesByLevel(CriticalityLevel.NonBreaking));
41+
const groupedChanges = splitChangesIntoGroups(changes);
3542

3643
const summary: string[] = [
3744
`# Found ${changes.length} change${changes.length > 1 ? 's' : ''}`,
3845
'',
39-
`Breaking: ${breakingChanges.length}`,
40-
`Dangerous: ${dangerousChanges.length}`,
41-
`Safe: ${safeChanges.length}`,
46+
`Breaking: ${groupedChanges.breaking.length}`,
47+
`Dangerous: ${groupedChanges.dangerous.length}`,
48+
`Safe: ${groupedChanges.safe.length}`,
4249
];
4350

4451
if (isLegacyConfig) {
@@ -74,16 +81,16 @@ export function createSummary(changes: Change[], summaryLimit: number, isLegacyC
7481
summaryLimit -= changes.length;
7582
}
7683

77-
if (breakingChanges.length) {
78-
addChangesToSummary('Breaking', breakingChanges);
84+
if (groupedChanges.breaking.length) {
85+
addChangesToSummary('Breaking', groupedChanges.breaking);
7986
}
8087

81-
if (dangerousChanges.length) {
82-
addChangesToSummary('Dangerous', dangerousChanges);
88+
if (groupedChanges.dangerous.length) {
89+
addChangesToSummary('Dangerous', groupedChanges.dangerous);
8390
}
8491

85-
if (safeChanges.length) {
86-
addChangesToSummary('Safe', safeChanges);
92+
if (groupedChanges.safe.length) {
93+
addChangesToSummary('Safe', groupedChanges.safe);
8794
}
8895

8996
summary.push(

packages/action/src/run.ts

+48-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { diff } from '../helpers/diff.js';
77
import { printSchemaFromEndpoint } from '../helpers/loaders.js';
88
import { produceSchema } from '../helpers/schema.js';
99
import { CheckConclusion } from '../helpers/types.js';
10-
import { createSummary } from '../helpers/utils.js';
10+
import { createSummary, splitChangesIntoGroups } from '../helpers/utils.js';
1111
import { updateCheckRun } from './checks.js';
1212
import { fileLoader } from './files.js';
1313
import { getAssociatedPullRequest, getCurrentCommitSha } from './git.js';
@@ -41,6 +41,7 @@ export async function run() {
4141
const approveLabel: string = core.getInput('approve-label') || 'approved-breaking-change';
4242
const rulesList = getInputAsArray('rules') || [];
4343
const onUsage = core.getInput('onUsage');
44+
const createActionCheck = castToBoolean(core.getInput('create-action-check'), true);
4445

4546
const octokit = github.getOctokit(token);
4647

@@ -50,19 +51,26 @@ export async function run() {
5051
// pull request
5152
const pullRequest = await getAssociatedPullRequest(octokit, commitSha);
5253

53-
core.info(`Creating a check named "${checkName}"`);
54-
55-
const check = await octokit.checks.create({
56-
owner,
57-
repo,
58-
name: checkName,
59-
head_sha: commitSha,
60-
status: 'in_progress',
61-
});
54+
let checkId = null;
55+
let seeCheckURL = '';
56+
if (createActionCheck) {
57+
core.info(`Creating a check named "${checkName}"`);
58+
59+
const check = await octokit.checks.create({
60+
owner,
61+
repo,
62+
name: checkName,
63+
head_sha: commitSha,
64+
status: 'in_progress',
65+
});
6266

63-
const checkId = check.data.id;
67+
checkId = check.data.id;
68+
seeCheckURL = ' For more info see: ' + check.data.html_url;
6469

65-
core.info(`Check ID: ${checkId}`);
70+
core.info(`Check ID: ${checkId}`);
71+
} else {
72+
core.info('Skipping check creation - disabled by input option');
73+
}
6674

6775
const schemaPointer = core.getInput('schema', { required: true });
6876

@@ -188,8 +196,20 @@ export async function run() {
188196
let annotations = action.annotations || [];
189197
const changes = action.changes || [];
190198

199+
const groupedChanges = splitChangesIntoGroups(changes);
191200
core.setOutput('changes', String(changes.length || 0));
192-
core.info(`Changes: ${changes.length || 0}`);
201+
core.setOutput(
202+
'breaking-changes',
203+
groupedChanges.breaking.map(c => c.message),
204+
);
205+
core.setOutput(
206+
'dangerous-changes',
207+
groupedChanges.dangerous.map(c => c.message),
208+
);
209+
core.setOutput(
210+
'safe-changes',
211+
groupedChanges.safe.map(c => c.message),
212+
);
193213

194214
const hasApprovedBreakingChangeLabel = pullRequest?.labels?.some(
195215
(label: any) => label.name === approveLabel,
@@ -204,20 +224,26 @@ export async function run() {
204224
conclusion = CheckConclusion.Success;
205225
}
206226

207-
if (useAnnotations === false || isNewSchemaUrl) {
208-
core.info(`Anotations are disabled. Skipping annotations...`);
209-
annotations = [];
210-
}
211-
212-
const summary = createSummary(changes, 100, false);
213-
214227
const title =
215228
conclusion === CheckConclusion.Failure
216-
? 'Something is wrong with your schema'
229+
? 'Something is wrong with your schema.' + seeCheckURL // add Check URL to navigate users to Check from action.
217230
: 'Everything looks good';
218-
219231
core.info(`Conclusion: ${conclusion}`);
220232

233+
// Action Check is disabled
234+
if (checkId === null) {
235+
core.info('Github Action Check is disabled, use outputs to determine errors');
236+
if (conclusion === CheckConclusion.Failure) {
237+
core.setFailed(conclusion);
238+
}
239+
return;
240+
}
241+
242+
if (useAnnotations === false || isNewSchemaUrl) {
243+
core.info(`Anotations are disabled. Skipping annotations...`);
244+
annotations = [];
245+
}
246+
const summary = createSummary(changes, 100, false);
221247
try {
222248
return await updateCheckRun(octokit, checkId, {
223249
conclusion,

pnpm-lock.yaml

+8-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/src/pages/docs/products/action.mdx

+27
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ Use annotation (`true` by default).
7676
annotations: false
7777
```
7878

79+
### `create-action-check`
80+
81+
Create Github Action check with summary. When disabled, annotations are disabled too. (`true` by default)
82+
83+
It can be useful to disable, when running on master branch or similar. And when subsequent step is using output and annotations nor check is required.
84+
85+
```yaml
86+
- uses: kamilkisiela/graphql-inspector@master
87+
with:
88+
schema: 'master:schema.graphql'
89+
create-action-check: false
90+
```
91+
7992
### `fail-on-breaking`
8093

8194
Fail on breaking changes (`true` by default).
@@ -161,6 +174,20 @@ to see how to use outputs.
161174

162175
Total number of changes
163176

177+
### `breaking-changes`
178+
179+
List of breaking changes. Each item is message string.
180+
181+
Example: ```["Type `Abc` was removed", "Field `Xyz` was removed from object type `Abc`"]```
182+
183+
### `dangerous-changes`
184+
185+
List of dangerous changes. Each item is message string, see `breaking-changes` for example.
186+
187+
### `safe-changes`
188+
189+
List of safe changes. Each item is message string, see `breaking-changes` for example.
190+
164191
![Summary](/assets/img/github/summary.jpg)
165192

166193
![Annotations](/assets/img/cli/github.jpg)

0 commit comments

Comments
 (0)