41
41
with :
42
42
script : |
43
43
const results = require('./color-contrast-check.json');
44
+ const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);
45
+
44
46
// prepare comment body
45
- const body = '## Design Token Contrast Check\n\n' +
47
+ const resultsMarkdown = '## Design Token Contrast Check\n\n' +
46
48
results.map(({theme, failingContrast, markdownTable}) =>
47
49
"### `"+theme+"`: " + `${failingContrast === 0 ? '✅ all checks passed' : `❌ ${failingContrast} checks failed`}\n\n` +
48
50
'<details>' +
@@ -51,29 +53,42 @@ jobs:
51
53
` ${markdownTable}` +
52
54
'\n</details>'
53
55
).join('\n\n')
56
+
54
57
// get comments
55
58
const {data: comments} = await github.rest.issues.listComments({
56
59
issue_number: context.issue.number,
57
60
owner: context.repo.owner,
58
61
repo: context.repo.repo
59
62
});
63
+
60
64
// get token issue
61
65
const tokenCheckComment = comments.filter(comment => comment.body.includes('## Design Token Contrast Check'));
66
+
62
67
// if token issue exists, update it
63
68
if(tokenCheckComment.length > 0) {
64
69
await github.rest.issues.updateComment({
65
70
comment_id: tokenCheckComment[0].id,
66
71
owner: context.repo.owner,
67
72
repo: context.repo.repo,
68
- body
73
+ body: resultsMarkdown
69
74
})
70
75
}
76
+
71
77
// if token issue does not exist, create it
72
78
else {
73
79
await github.rest.issues.createComment({
74
80
issue_number: context.issue.number,
75
81
owner: context.repo.owner,
76
82
repo: context.repo.repo,
77
- body
83
+ body: resultsMarkdown
78
84
})
79
85
}
86
+
87
+ // output results to summary
88
+ core.summary.addRaw(resultsMarkdown, true)
89
+ core.summary.write({overwrite: true})
90
+
91
+ // fail action if any contrast check fails
92
+ if (faildChecks > 0) {
93
+ core.setFailed(`${faildChecks} contrast checks failed. Please fix the failing checks and try again.\n\nCheck action summary for more details.`);
94
+ }
0 commit comments