Problem Description
GitHub Actions workflows written in YAML can have syntax errors that only become apparent after pushing to the repository. This can lead to failed workflows and wasted time debugging issues that could have been caught locally.
Recommended Tools
-
yamllint - A linter for YAML files
- Checks for syntax validity
- Enforces consistent formatting
- Detects common mistakes
-
actionlint - Static checker for GitHub Actions workflow files
- Validates workflow syntax
- Checks for common mistakes in GitHub Actions
- Type checks expressions
- Validates job dependencies
Implementation Steps
-
Install validation tools:
# macOS
brew install yamllint actionlint
# Ubuntu/Debian
sudo apt-get install yamllint
# actionlint needs to be installed from releases
-
Create configuration files:
.yamllint.yml for yamllint configuration
- Configure rules for consistent formatting
-
Add pre-commit hooks:
- Use pre-commit framework to run checks automatically
- Prevent commits with invalid YAML
-
Add validation to CI/CD:
- Include validation step in GitHub Actions
- Ensure all PRs pass YAML validation
-
Document the process:
- Update README with validation instructions
- Add troubleshooting guide
Benefits
- Early error detection: Catch syntax errors before pushing
- Consistent formatting: Maintain readable workflow files
- Reduced debugging time: Avoid runtime failures due to syntax issues
- Better collaboration: Ensure all contributors follow the same standards
- Improved reliability: Reduce workflow failures due to configuration errors
Example Configuration
.yamllint.yml:
extends: default
rules:
line-length:
max: 120
level: warning
truthy:
allowed-values: ['true', 'false', 'on', 'off']
Pre-commit hook (.pre-commit-config.yaml):
repos:
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args: [-c=.yamllint.yml]
- repo: https://github.com/rhysd/actionlint
rev: v1.6.26
hooks:
- id: actionlint
Reference Implementation
The latex-template repository has already implemented this validation process and can serve as a reference.
Problem Description
GitHub Actions workflows written in YAML can have syntax errors that only become apparent after pushing to the repository. This can lead to failed workflows and wasted time debugging issues that could have been caught locally.
Recommended Tools
yamllint - A linter for YAML files
actionlint - Static checker for GitHub Actions workflow files
Implementation Steps
Install validation tools:
Create configuration files:
.yamllint.ymlfor yamllint configurationAdd pre-commit hooks:
Add validation to CI/CD:
Document the process:
Benefits
Example Configuration
.yamllint.yml:Pre-commit hook (
.pre-commit-config.yaml):Reference Implementation
The
latex-templaterepository has already implemented this validation process and can serve as a reference.