Skip to content

Commit

Permalink
improve action to output summary and fail on non-pr run
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Apr 30, 2024
1 parent 02777f6 commit be4da4a
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions .github/workflows/a11y-contrast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ jobs:
- name: Run required checks
run: |
npm run contrast:check
- name: Report check results
if: github.event_name == 'pull_request'
- name: Fail or pass action based on check results
id: check-results
uses: actions/github-script@v7
with:
script: |
const results = require('./color-contrast-check.json');
const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);
// prepare comment body
// prepare results markdown
const resultsMarkdown = '## Design Token Contrast Check\n\n' +
results.map(({theme, failingContrast, markdownTable}) =>
"### `"+theme+"`: " + `${failingContrast === 0 ? '✅ all checks passed' : `❌ ${failingContrast} checks failed`}\n\n` +
Expand All @@ -54,6 +53,25 @@ jobs:
'\n</details>'
).join('\n\n')
// set output
core.setOutput('resultsMarkdown', resultsMarkdown);
// fail action if any contrast check fails
if (faildChecks > 0) {
core.setFailed(`${faildChecks} contrast checks failed. Please fix the failing checks and try again.\n\nCheck action summary for more details.`);
core.error(`\u001b[91;1m🛑 ${faildChecks} contrast checks failed!`)
}
// success
core.info('\u001b[32;1m✅ All contrast checks passed!')
- name: Report check results as comment
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const resultsMarkdown = "${{ steps.check-results.outputs.resultsMarkdown }}"
// get comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
Expand Down Expand Up @@ -84,11 +102,12 @@ jobs:
})
}
- name: Report check results as summary
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const resultsMarkdown = "${{ steps.check-results.outputs.resultsMarkdown }}"
// output results to summary
core.summary.addRaw(resultsMarkdown, true)
core.summary.write({overwrite: true})
// fail action if any contrast check fails
if (faildChecks > 0) {
core.setFailed(`${faildChecks} contrast checks failed. Please fix the failing checks and try again.\n\nCheck action summary for more details.`);
}
core.summary.write({overwrite: true})

0 comments on commit be4da4a

Please sign in to comment.