From 8247a40682328a7b73ef6e114c73c38f10c9601e Mon Sep 17 00:00:00 2001 From: Lukas Oppermann Date: Tue, 8 Oct 2024 14:26:37 +0200 Subject: [PATCH] use cjs --- .github/workflows/a11y-contrast.yml | 10 +++-- .../a11y-contrast/prepare-check-results.cjs | 40 +++++++++++++++++++ .../a11y-contrast/prepare-check-results.js | 39 ------------------ 3 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/scripts/a11y-contrast/prepare-check-results.cjs delete mode 100644 .github/workflows/scripts/a11y-contrast/prepare-check-results.js diff --git a/.github/workflows/a11y-contrast.yml b/.github/workflows/a11y-contrast.yml index ccffdbc03..47c03d066 100644 --- a/.github/workflows/a11y-contrast.yml +++ b/.github/workflows/a11y-contrast.yml @@ -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 diff --git a/.github/workflows/scripts/a11y-contrast/prepare-check-results.cjs b/.github/workflows/scripts/a11y-contrast/prepare-check-results.cjs new file mode 100644 index 000000000..86316729f --- /dev/null +++ b/.github/workflows/scripts/a11y-contrast/prepare-check-results.cjs @@ -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` + + '
' + + `Show results table for theme: ${theme}\n` + + " \n"+ + ` ${failedMarkdownTable}` + + '\n
' + }).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 \ No newline at end of file diff --git a/.github/workflows/scripts/a11y-contrast/prepare-check-results.js b/.github/workflows/scripts/a11y-contrast/prepare-check-results.js deleted file mode 100644 index 16d1adeb2..000000000 --- a/.github/workflows/scripts/a11y-contrast/prepare-check-results.js +++ /dev/null @@ -1,39 +0,0 @@ -import core from '@actions/core'; -import results from './color-contrast-check.json' assert {type: 'json'}; -// get failed checks count -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` + - '
' + - `Show results table for theme: ${theme}\n` + - " \n"+ - ` ${failedMarkdownTable}` + - '\n
' - }).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!') -} \ No newline at end of file