Skip to content

Commit

Permalink
trying to update action
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Sep 26, 2024
1 parent 51b0324 commit 5fac5be
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 52 deletions.
96 changes: 57 additions & 39 deletions .github/workflows/a11y-contrast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,30 @@ jobs:
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` +
// 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"+
` ${markdownTable}` +
` ${failedMarkdownTable}` +
'\n</details>'
).join('\n\n')
}).join('\n\n')
// set output
core.setOutput('markdown', resultsMarkdown)
core.setOutput('summaryMarkdown', summaryMarkdown)
core.setOutput('failedResults', failedResults)
core.setOutput('faildChecks', faildChecks)
// fail action if any contrast check fails
Expand All @@ -71,12 +82,26 @@ jobs:
core.info('\u001b[32;1m✅ All contrast checks passed!')
}
- name: Report check results as summary
uses: actions/github-script@v7
with:
script: |
const resultsMarkdown = `${{ steps.check-results.outputs.summaryMarkdown }}`
// output results to summary
core.summary.addRaw(resultsMarkdown, true)
core.summary.write({overwrite: true})
- name: Report check results as comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
with:
script: |
const resultsMarkdown = `${{ steps.check-results.outputs.markdown }}`
const results = ${{ steps.check-results.outputs.failedResults }}
const GITHUB_WORKFLOW_URL = `https://github.com/${ ${{env.GITHUB_REPOSITORY}} }/actions/runs/${ ${{env.GITHUB_RUN_ID}} }`
// get comments
const {data: comments} = await github.rest.issues.listComments({
Expand All @@ -85,39 +110,32 @@ jobs:
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
})
for (const {title, body} of results) {
// get token issue
const tokenCheckComment = comments.filter(comment => comment.body.includes(title));
const body = `${title}\n\n${body}\\n${GITHUB_WORKFLOW_URL}`
// 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
})
}
// 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
})
}
}
- 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
Expand Down
22 changes: 11 additions & 11 deletions scripts/color-contrast.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,6 @@ const setContrastRatios = (
])
}

const defaultContrast: ContrastRequirement[] = setContrastRatios('default', [
...baseRequirements,
...displayColorRequirements,
])

const highContrast: ContrastRequirement[] = setContrastRatios('highContrast', [
...baseRequirements,
...displayColorRequirements,
// add high contrast overwrites or additions
])

export const bgColors: string[] = ['bgColor-default', 'bgColor-muted']

export type ThemeName =
Expand All @@ -273,6 +262,17 @@ export type ThemeName =
| 'dark_colorblind'
| 'dark_tritanopia'

const defaultContrast: ContrastRequirement[] = setContrastRatios('default', [
...baseRequirements,
...displayColorRequirements,
])

const highContrast: ContrastRequirement[] = setContrastRatios('highContrast', [
...baseRequirements,
...displayColorRequirements,
// add high contrast overwrites or additions
])

export type ContrastRequirements = {[key in ThemeName]: ContrastRequirement[]}
export const contrastRequirements: ContrastRequirements = {
// default light mode
Expand Down
10 changes: 9 additions & 1 deletion scripts/color-contrast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const testContrast = (
}

const checkContrastForThemes = async (themes: Theme[], contrastRequirementsObj: ContrastRequirements) => {
return await Promise.all(
const allResults = await Promise.all(
themes.map(async ([themeName, tokens]) => {
// run tests on all color pairs
const results = runContrastTest(contrastRequirementsObj[themeName], tokens)
Expand All @@ -123,10 +123,18 @@ const checkContrastForThemes = async (themes: Theme[], contrastRequirementsObj:
'contrastRatio',
'minimumContrastRatio',
]),
failedMarkdownTable:
failingContrast > 0 &&
(await makeMarkdownTable(
results.filter(item => item.pass === '❌'),
['contrastPair', 'pass', 'contrastRatio', 'minimumContrastRatio'],
)),
results,
}
}),
)
// return results
return allResults
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tokens/functional/color/dark/primitives-dark.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
fgColor: {
default: {
$value: '{base.color.neutral.12}',
$value: '{base.color.neutral.1}',
$type: 'color',
$extensions: {
'org.primer.figma': {
Expand Down

0 comments on commit 5fac5be

Please sign in to comment.