Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Oct 8, 2024
1 parent 8247a40 commit 4a9a18f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 65 deletions.
69 changes: 44 additions & 25 deletions .github/workflows/a11y-contrast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,45 @@ jobs:
with:
script: |
const results = require('./color-contrast-check.json');
const prepareResults = require('${{ github.workspace }}/.github/workflows/scripts/a11y-contrast/prepare-check-results.cjs');
prepareResults(results);
const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);
const themesTitlePrefixes = Object.fromEntries(results.map(({theme}) => [theme, `❌ \`${theme}\`: `]))
core.setOutput('themesTitlePrefixes', themesTitlePrefixes)
// prepare outputs for all failed themes
const failedResults = results.filter(themeResults => themeResults.failingContrast > 0).map(({theme, failingContrast, markdownTable}) => ({
title: `# ${themesTitlePrefixes[theme]} ${failingContrast} checks failed`,
body: `${markdownTable}`
}))
// prepare summary body
const summaryMarkdown = '## Design Token Contrast Check\n\n' +
results.map(({theme, failingContrast, failedMarkdownTable}) => {
if(failingContrast === 0) {
return "### \\`"+theme+"\\`: " + `✅ all checks passed\n\n`
}
// if there are failing checks, return a summary with a details section
return "### \\`"+theme+"\\`: " + `❌ ${failingContrast} checks failed\n\n` +
'<details>' +
`<summary>Show results table for theme: ${theme}</summary>\n` +
" \n"+
` ${failedMarkdownTable}` +
'\n</details>'
}).join('\n\n')
// set output
core.setOutput('summaryMarkdown', summaryMarkdown)
core.setOutput('failedResults', failedResults)
core.setOutput('faildChecks', faildChecks)
// fail action if any contrast check fails
if (faildChecks > 0) {
core.setFailed(`\u001b[91;1m🛑 ${faildChecks} contrast checks failed. Please fix the failing checks and try again.\n\nCheck action summary for more details.`);
}
// success
else {
core.info('\u001b[32;1m✅ All contrast checks passed!')
}
- name: Report check results as summary
uses: actions/github-script@v7
Expand All @@ -68,6 +104,8 @@ jobs:
with:
script: |
const results = ${{ steps.check-results.outputs.failedResults }}
const themesTitlePrefixes = ${{ steps.check-results.outputs.themesTitlePrefixes }}
const WORKFLOW_SUMMARY_URL = `https://github.com/${{env.GITHUB_REPOSITORY}}/actions/runs/${{env.GITHUB_RUN_ID}}`
// get comments
Expand All @@ -77,17 +115,7 @@ jobs:
repo: context.repo.repo
});
const possibleTitles = [
'❌ `light`:',
'❌ `light_high_contrast`:',
'❌ `light_colorblind`:',
'❌ `light_tritanopia`:',
'❌ `dark`:',
'❌ `dark_dimmed`:',
'❌ `dark_high_contrast`:',
'❌ `dark_colorblind`:',
'❌ `dark_tritanopia`:'
]
const possibleTitles = Object.values(themesTitlePrefixes)
// get comments of token issues
let currentComments = comments.filter(comment => possibleTitles.some(titleStart => comment.body.includes(titleStart)));
Expand Down Expand Up @@ -155,24 +183,15 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const themesTitlePrefixes = ${{ steps.check-results.outputs.themesTitlePrefixes }}
// get comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const possibleTitles = [
'❌ `light`:',
'❌ `light_high_contrast`:',
'❌ `light_colorblind`:',
'❌ `light_tritanopia`:',
'❌ `dark`:',
'❌ `dark_dimmed`:',
'❌ `dark_high_contrast`:',
'❌ `dark_colorblind`:',
'❌ `dark_tritanopia`:'
]
const possibleTitles = Object.values(themesTitlePrefixes)
// get token issue
const tokenCheckComment = comments.filter(comment => possibleTitles.some(titleStart => comment.body.includes(titleStart)));
Expand Down
40 changes: 0 additions & 40 deletions .github/workflows/scripts/a11y-contrast/prepare-check-results.cjs

This file was deleted.

0 comments on commit 4a9a18f

Please sign in to comment.