How to Lint YAML with yamllint in GitHub Actions
YAML is whitespace-sensitive and unforgiving; yamllint turns a silent indentation bug into a clear CI failure.
Run yamllint across the repo with a tuned config so structural and style issues fail the job.
Steps
- Install
yamllintwith pip. - Add a
.yamllintconfig to relax rules like line length where appropriate. - Run
yamllint .and let failures fail the build.
Workflow
.github/workflows/yamllint.yml
name: yamllint
on: [pull_request]
jobs:
yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install yamllint
- run: yamllint -c .yamllint .Notes
- Relax
line-lengthin.yamllintso long URLs in config do not fail the lint. - On Latchkey managed runners YAML lint jobs run cheaper and self-heal if a runner dies.
Related guides
How to Run ShellCheck on Scripts in GitHub ActionsRun ShellCheck over your shell scripts in GitHub Actions so quoting bugs and unsafe patterns fail CI before t…
How to Validate JSON Against Schemas in GitHub ActionsValidate JSON config files against JSON Schema in GitHub Actions with ajv so malformed or out-of-spec config…