This GitHub Actions workflow template (github-workflow-validation.yml) validates GitHub Actions workflow files using actionlint to ensure they follow best practices and are free from common errors.
The workflow validation template helps maintain high-quality GitHub Actions workflows by automatically checking them for syntax errors, deprecated features, invalid step configurations, and other common issues. It uses actionlint, a popular linting tool specifically designed for GitHub Actions workflows.
- Checkout: The repository code is checked out to access workflow files
- Install Go: Sets up the Go programming language environment (required for actionlint)
- Install Actionlint: Downloads and installs the actionlint tool
- Run Actionlint: Validates all workflow files in the specified directory
Create a new workflow file in your repository (e.g. .github/workflows/validate.yml) with the below contents:
name: Validate Workflows
on:
push:
branches:
- main
paths:
- '.github/workflows/**'
pull_request:
branches:
- main
paths:
- '.github/workflows/**'
jobs:
validate:
uses: appvia/appvia-cicd-workflows/.github/workflows/github-workflow-validation.yml@main
name: Validate GitHub Workflowsworkflows-path- Default: ".github/workflows". The path to the GitHub workflows directory to validate
Validate workflows using the default path:
jobs:
validate:
uses: appvia/appvia-cicd-workflows/.github/workflows/github-workflow-validation.yml@mainValidate workflows in a custom directory:
jobs:
validate:
uses: appvia/appvia-cicd-workflows/.github/workflows/github-workflow-validation.yml@main
with:
workflows-path: ".github/custom-workflows"Only run validation when workflow files are modified:
name: Validate Workflows
on:
pull_request:
paths:
- '.github/workflows/**'
jobs:
validate:
uses: appvia/appvia-cicd-workflows/.github/workflows/github-workflow-validation.yml@mainActionlint validates workflows for:
- Syntax errors in YAML
- Invalid workflow syntax and structure
- Undefined or misused contexts (e.g.,
github,env,secrets) - Type mismatches in expressions
- Invalid action inputs and outputs
- Deprecated GitHub Actions features
- Common security issues
- Shell script problems using shellcheck
- Run on Pull Requests: Enable this workflow on pull requests to catch issues before merging
- Pin to a Version: Consider pinning to a specific tagged version instead of
@mainfor stability - Combine with Other Checks: Use alongside other validation workflows for comprehensive CI/CD pipeline quality
Note: This template may change over time, so it is recommended that you point to a tagged version rather than the main branch.