Skip to content

New light and dark neutral scales #1801

New light and dark neutral scales

New light and dark neutral scales #1801

Workflow file for this run

name: A11y contrast check
on:
pull_request:
branches-ignore:
- 'changeset-release/**'
workflow_dispatch:
jobs:
changes:
uses: ./.github/workflows/hasChanged.yml
build:
needs: changes
if: needs.changes.outputs.tokens == 'true' || github.event_name == 'workflow_dispatch'
name: Check design token color contrast
runs-on: ubuntu-latest
continue-on-error: true
outputs:
faildChecks: ${{ steps.check-results.outputs.faildChecks }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci --no-audit --no-fund --ignore-scripts
- name: Build v8 tokens
run: npm run build:v8
- name: Run required checks
run: |
npm run contrast:check
- name: Prepare check results
id: check-results
continue-on-error: true
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
const resultsMarkdown = '## Design Token Contrast Check\n\n' +
results.map(({theme, failingContrast, markdownTable}) =>
"### \\`"+theme+"\\`: " + `${failingContrast === 0 ? '✅ all checks passed' : `❌ ${failingContrast} checks failed`}\n\n` +
'<details>' +
`<summary>Show results table for theme: ${theme}</summary>\n` +
" \n"+
` ${markdownTable}` +
'\n</details>'
).join('\n\n')
// set output
core.setOutput('markdown', resultsMarkdown)
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 comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const resultsMarkdown = `${{ steps.check-results.outputs.markdown }}`
// get comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// get token issue
const tokenCheckComment = comments.filter(comment => comment.body.includes('## Design Token Contrast Check'));
// if token issue exists, update it
if(tokenCheckComment.length > 0) {
await github.rest.issues.updateComment({
comment_id: tokenCheckComment[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
body: resultsMarkdown
})
}
// if token issue does not exist, create it
else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: resultsMarkdown
})
}
- name: Report check results as summary
uses: actions/github-script@v7
with:
script: |
const resultsMarkdown = `${{ steps.check-results.outputs.markdown }}`
// output results to summary
core.summary.addRaw(resultsMarkdown, true)
core.summary.write({overwrite: true})
Fail_action_on_contrast_failing:
needs: build
name: Fail action on contrast failing
if: needs.build.outputs.faildChecks > 0
runs-on: ubuntu-latest
steps:
- name: Contrast checks failed
run: |
echo "::error::${{ needs.build.outputs.faildChecks }} contrast checks failed. Please fix the failing checks and try again."
exit 1
remove_comment:
needs: changes
if: needs.changes.outputs.tokens == 'false'
runs-on: ubuntu-latest
steps:
- name: Remove comment and summary
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
// get comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// get token issue
const tokenCheckComment = comments.filter(comment => comment.body.includes('## Design Token Contrast Check'));
// if token issue exists, update it
if(tokenCheckComment.length > 0) {
await github.rest.issues.deleteComment({
comment_id: tokenCheckComment[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
})
}
// remove summary
core.summary.clear()
core.summary.write({overwrite: true})