Skip to content

Commit 47bb2bf

Browse files
Fail workflow on contrast check fail (#890)
1 parent ef6a6c3 commit 47bb2bf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

.github/workflows/a11y-contrast.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ jobs:
4141
with:
4242
script: |
4343
const results = require('./color-contrast-check.json');
44+
const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);
45+
4446
// prepare comment body
45-
const body = '## Design Token Contrast Check\n\n' +
47+
const resultsMarkdown = '## Design Token Contrast Check\n\n' +
4648
results.map(({theme, failingContrast, markdownTable}) =>
4749
"### `"+theme+"`: " + `${failingContrast === 0 ? '✅ all checks passed' : `❌ ${failingContrast} checks failed`}\n\n` +
4850
'<details>' +
@@ -51,29 +53,42 @@ jobs:
5153
` ${markdownTable}` +
5254
'\n</details>'
5355
).join('\n\n')
56+
5457
// get comments
5558
const {data: comments} = await github.rest.issues.listComments({
5659
issue_number: context.issue.number,
5760
owner: context.repo.owner,
5861
repo: context.repo.repo
5962
});
63+
6064
// get token issue
6165
const tokenCheckComment = comments.filter(comment => comment.body.includes('## Design Token Contrast Check'));
66+
6267
// if token issue exists, update it
6368
if(tokenCheckComment.length > 0) {
6469
await github.rest.issues.updateComment({
6570
comment_id: tokenCheckComment[0].id,
6671
owner: context.repo.owner,
6772
repo: context.repo.repo,
68-
body
73+
body: resultsMarkdown
6974
})
7075
}
76+
7177
// if token issue does not exist, create it
7278
else {
7379
await github.rest.issues.createComment({
7480
issue_number: context.issue.number,
7581
owner: context.repo.owner,
7682
repo: context.repo.repo,
77-
body
83+
body: resultsMarkdown
7884
})
7985
}
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

Comments
 (0)