Skip to main content

CLI for github actions workflow validation

Project description

validate-actions

Professional GitHub Actions workflow validation and linting from the CLI.

Catch configuration errors, typos, and best practice violations in your GitHub Actions workflows before you push to production. Built for developers who want bulletproof CI/CD.

Python 3.12+ PyPI version License: MIT


🚀 Quick Start

Installation

# Install from PyPI (coming soon)
pip install validate-actions

# Or install from test PyPI
pip install -i https://test.pypi.org/simple/ validate-actions

Basic Usage

# Validate all workflows in your repository
validate-actions

# Validate a specific workflow file
validate-actions .github/workflows/ci.yml

# Auto-fix issues where possible
validate-actions --fix

# Suppress warnings, show only errors
validate-actions --quiet

# Limit maximum warnings before exit code 1
validate-actions --max-warnings 10

Library Usage

from validate_actions import validate_workflow

# Validate a workflow file
problems = validate_workflow('path/to/workflow.yml')

# Check for issues
for problem in problems.problems:
    print(f"{problem.level.name}: {problem.desc} at line {problem.pos.line}")

# Auto-fix issues
problems = validate_workflow('path/to/workflow.yml', fix=True)

🏗️ What Gets Validated

GitHub Actions Contexts

# ✅ Valid context references
runs-on: ubuntu-latest
if: github.event_name == 'push'
env:
  BRANCH: ${{ github.ref_name }}

# ❌ Invalid context references (caught by validate-actions)
if: github.event.invalid_property  # Unknown property
env:
  USER: ${{ github.actor_name }}   # Should be github.actor

Action Usage & Versions

# ✅ Current action versions
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
  with:
    node-version: '18'

# ❌ Outdated or incorrect usage (caught by validate-actions)  
- uses: actions/checkout@v2        # Outdated version
- uses: actions/setup-node@v4
  with:
    node_version: '18'             # Wrong input name

Step Input/Output Dependencies

# ✅ Proper step references
- id: build
  run: echo "artifact=my-app.zip" >> $GITHUB_OUTPUT
- name: Deploy
  run: deploy ${{ steps.build.outputs.artifact }}

# ❌ Invalid step references (caught by validate-actions)
- name: Deploy  
  run: deploy ${{ steps.invalid.outputs.artifact }}  # Step doesn't exist

🔧 Configuration

Environment Variables

Variable Description Required
GH_TOKEN GitHub token for enhanced API rate limits Optional

GitHub Token Setup

# For higher rate limits (heavy use)
export GH_TOKEN=ghp_your_token_here
validate-actions

A GitHub token enables:

  • Higher API rate limits for action metadata fetching

Extending Rules

validate-actions supports custom. You can extend the tool with your own rules without modifying the core codebase.

See validate_actions/rules/rules.yml for configuration format and examples of creating custom rules.


🚦 Exit Codes

  • 0: Success (no errors, warnings under limit)
  • 1: Errors found OR warnings exceed --max-warnings limit

By default, warnings don't cause exit code 1 (non-blocking):

validate-actions              # Exit 0 even with warnings
validate-actions --quiet      # Exit 0, suppress warning output  

Use --max-warnings to fail builds when warnings exceed a threshold:

validate-actions --max-warnings 0    # Exit 1 on any warnings (strict)
validate-actions --max-warnings 5    # Exit 1 if more than 5 warnings

Perfect for CI/CD integration:

# .github/workflows/validate.yml
- name: Validate Workflows (Allow Warnings)
  run: validate-actions
  # Will only fail on errors, not warnings

🏃‍♂️ Integration Examples

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: validate-actions
        name: Validate GitHub Actions
        entry: validate-actions
        language: system
        files: ^\.github/workflows/.*\.ya?ml$

Note: Requires validate-actions to be installed globally or available in your PATH. For poetry projects, consider using entry: poetry run validate-actions.

VS Code Task

// .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Validate Actions",
      "type": "shell", 
      "command": "validate-actions",
      "group": "build",
      "presentation": {
        "echo": true,
        "reveal": "always"
      }
    }
  ]
}

Note: Assumes global installation (pip install validate-actions). For other setups, replace command with:

  • Poetry: "poetry run validate-actions"
  • Pipx: "pipx run validate-actions"
  • ...

GitHub Actions Workflow

# .github/workflows/validate.yml
name: Validate Workflows
on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        with:
          python-version: '3.12'
      - run: pip install validate-actions
      - name: Validate with warning limit
        run: validate-actions
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Note: Use --max-warnings N to set warning limits, or --quiet to suppress warning output entirely.


🛠️ Development

See DEV_README.md for detailed development setup, architecture overview, and contribution guidelines.

Quick Dev Setup with poetry

git clone https://github.com/konradhorber/validate-actions
cd validate-actions
poetry install --with dev
poetry run validate-actions

🤝 Contributing

We welcome contributions! Please see DEV_README.md for development setup and guidelines.


📄 License

MIT License - see LICENSE file for details.


🙏 Acknowledgments

Built with:

  • PyYAML for robust YAML parsing
  • Typer for the CLI interface
  • Rich for beautiful terminal output
  • python-dotenv for environment variable management

Inspired by tools like ESLint and the GitHub Actions community's need for better workflow validation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

validate_actions-1.0.0.tar.gz (60.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validate_actions-1.0.0-py3-none-any.whl (76.9 kB view details)

Uploaded Python 3

File details

Details for the file validate_actions-1.0.0.tar.gz.

File metadata

  • Download URL: validate_actions-1.0.0.tar.gz
  • Upload date:
  • Size: 60.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.9 Darwin/24.5.0

File hashes

Hashes for validate_actions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5a84bc9a67e63031856f1b6ed8a900a7e833b422d512a793419f3e32ee9596bf
MD5 098b5842747cacae409e86a162eb2e45
BLAKE2b-256 a9fbe7b8c2f442316bbff9542b35063541a3df6bd10d9494ad59bbb6f34c92ad

See more details on using hashes here.

File details

Details for the file validate_actions-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: validate_actions-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 76.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.9 Darwin/24.5.0

File hashes

Hashes for validate_actions-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08d0a6887711ab0d7be1d51065f706ed1885b858597a286a8b596068bb0a4ae9
MD5 8c64145e670705d47009e1b2bc19b572
BLAKE2b-256 69030cd25b5678ad04f5085fd0c7b42f5c1d6eb4717d2c6c25c301d350b9e8c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page