How to Add Linter to GitHub Actions¶
Ensure your app stays accessible by checking colors automatically on every code change.
The goal¶
We want to run the Color Contrast Linter every time someone pushes code or opens a Pull Request. If they add a color that isn’t readable, the build will fail, preventing the bad color from merging.
Step 1: Create the workflow file¶
Create a new file in your repository at:
.github/workflows/color-contrast.yml
Step 2: Add the configuration¶
Paste this code into the file:
# .github/workflows/color-contrast.yml
name: Color Contrast Check
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
lint-colors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check Color Contrast
uses: comfort-mode-toolkit/color-contrast-linter-action@main
Step 3: Add your color config¶
Make sure you have a .color_pairs.yml file in the root of your repository.
If you don’t have one, run this locally to create it:
pip install color-contrast-linter
cc-lint init
Then commit and push this file.
How it works¶
You push code to GitHub.
GitHub Actions sees the
accessibility.ymlfile and starts a job.It installs the linter and reads your
.color_pairs.yml.It checks all your defined color pairs.
If all pass: You get a green checkmark
If any fail: You get a red X and the build fails.
Viewing results¶
Click on the “Actions” tab in your GitHub repository to see the results. You’ll see a detailed log showing exactly which colors passed and failed.
Blocking bad merges¶
To strictly enforce accessibility:
Go to your repository Settings.
Click Branches → Branch protection rules.
Edit your main branch rule.
Check Require status checks to pass before merging.
Select lint-colors from the list.
Now, nobody can merge code that breaks your color accessibility rules!
See also¶
How to Use Color Contrast Linter - Learn how to configure the linter
What Makes CM-Colors Work - Understand why we care about contrast