Skip to content

Commit 1454122

Browse files
improve contrast check workflow (#1073)
* update contrast check * add identifier
1 parent 028ad8e commit 1454122

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

.github/workflows/a11y-contrast.yml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ jobs:
4747
const results = require('./color-contrast-check.json');
4848
const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);
4949
50+
5051
// prepare outputs for all failed themes
5152
const failedResults = results.filter(themeResults => themeResults.failingContrast > 0).map(({theme, failingContrast, markdownTable}) => ({
52-
title: `# ❌ \`${theme}\`: ${failingContrast} checks failed`,
53+
title: `# ❌ \`${theme}\`: ${failingContrast} checks failed`,
5354
body: `${markdownTable}`
55+
identifier: `<!-- contrast check --><!-- Theme: ${theme} -->`
5456
}))
5557
5658
// prepare summary body
@@ -101,6 +103,7 @@ jobs:
101103
with:
102104
script: |
103105
const results = ${{ steps.check-results.outputs.failedResults }}
106+
104107
const WORKFLOW_SUMMARY_URL = `https://github.com/${{env.GITHUB_REPOSITORY}}/actions/runs/${{env.GITHUB_RUN_ID}}`
105108
106109
// get comments
@@ -110,30 +113,47 @@ jobs:
110113
repo: context.repo.repo
111114
});
112115
113-
for (const {title, body} of results) {
114-
// get token issue
115-
const tokenCheckComment = comments.filter(comment => comment.body.includes(title));
116-
const outputBody = `${title}\n\n${body}\n\n<a href="${WORKFLOW_SUMMARY_URL}">→ Details</a>`
116+
// get comments of token issues
117+
let currentComments = comments.filter(comment => possibleTitles.some(titleStart => comment.body.includes(titleStart)));
117118
118-
// if token issue exists, update it
119-
if(tokenCheckComment.length > 0) {
120-
await github.rest.issues.updateComment({
121-
comment_id: tokenCheckComment[0].id,
119+
// get token issue
120+
const tokenCheckComment = comments.filter(comment => comment.body.includes("<!-- contrast check -->"));
121+
122+
// if token issue exists, update it
123+
if(tokenCheckComment.length > 0) {
124+
for (const comment of tokenCheckComment) {
125+
await github.rest.issues.deleteComment({
126+
comment_id: comment.id,
122127
owner: context.repo.owner,
123128
repo: context.repo.repo,
124-
body: outputBody
125129
})
126130
}
131+
}
132+
133+
for (const {title, body, indentifier} of results) {
134+
// get token issue
135+
136+
const outputBody = `${title}\n\n${body}\n\n<a href="${WORKFLOW_SUMMARY_URL}">→ Details</a>${indentifier}`
127137
128138
// if token issue does not exist, create it
129-
else {
130-
await github.rest.issues.createComment({
131-
issue_number: context.issue.number,
139+
await github.rest.issues.createComment({
140+
issue_number: context.issue.number,
141+
owner: context.repo.owner,
142+
repo: context.repo.repo,
143+
body: outputBody
144+
})
145+
}
146+
147+
// if token issue exists, update it
148+
if(currentComments.length > 0) {
149+
await currentComments.map(comment => {
150+
console.log('deleting comment', comment.id, comment)
151+
github.rest.issues.deleteComment({
152+
comment_id: comment.id,
132153
owner: context.repo.owner,
133154
repo: context.repo.repo,
134-
body: outputBody
135155
})
136-
}
156+
})
137157
}
138158
139159
Fail_action_on_contrast_failing:
@@ -165,15 +185,17 @@ jobs:
165185
});
166186
167187
// get token issue
168-
const tokenCheckComment = comments.filter(comment => comment.body.includes('## Design Token Contrast Check'));
188+
const tokenCheckComment = comments.filter(comment => comment.body.includes("<!-- contrast check -->"));
169189
170190
// if token issue exists, update it
171191
if(tokenCheckComment.length > 0) {
172-
await github.rest.issues.deleteComment({
173-
comment_id: tokenCheckComment[0].id,
174-
owner: context.repo.owner,
175-
repo: context.repo.repo,
176-
})
192+
for (const comment of tokenCheckComment) {
193+
await github.rest.issues.deleteComment({
194+
comment_id: comment.id,
195+
owner: context.repo.owner,
196+
repo: context.repo.repo,
197+
})
198+
}
177199
}
178200
179201
// remove summary

0 commit comments

Comments
 (0)