Skip to content

Commit

Permalink
use cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Oct 8, 2024
1 parent 462b475 commit 8247a40
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/a11y-contrast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ jobs:
- name: Prepare check results
id: check-results
continue-on-error: true
run: |
node ${{ github.workspace }}/.github/workflows/scripts/a11y-contrast/prepare-check-results.js
shell: bash
uses: actions/github-script@v7
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);
- name: Report check results as summary
uses: actions/github-script@v7
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/scripts/a11y-contrast/prepare-check-results.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const prepareResults = (results) => {
const faildChecks = results.reduce((acc, {failingContrast}) => acc + failingContrast, 0);

// prepare outputs for all failed themes
const failedResults = results.filter(themeResults => themeResults.failingContrast > 0).map(({theme, failingContrast, markdownTable}) => ({
title: `# ❌ \`${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!')
}
}

module.exports = prepareResults
39 changes: 0 additions & 39 deletions .github/workflows/scripts/a11y-contrast/prepare-check-results.js

This file was deleted.

0 comments on commit 8247a40

Please sign in to comment.