Skip to main content

Generate GitHub Actions workflow YAML from Python code

Project description

ghagen

Generate GitHub Actions workflows from Python code.

CI PyPI Python License

Install

Homebrew (macOS, Linux)

brew install nathanjordan/tap/ghagen

pip / uv / pipx

pip install ghagen
uv tool install ghagen
pipx install ghagen

Example

from ghagen import App, Job, On, PRTrigger, PushTrigger, Step, Workflow

workflow = Workflow(
    name="CI",
    on=On(
        push=PushTrigger(branches=["main"]),
        pull_request=PRTrigger(branches=["main"]),
    ),
    jobs={
        "test": Job(
            runs_on="ubuntu-latest",
            steps=[
                Step(uses="actions/checkout@v4"),
                Step(name="Run tests", run="python -m pytest"),
            ],
        ),
    },
)

app = App()
app.add_workflow(workflow, "ci.yml")
app.synth()

This generates:

name: CI
on:
  pull_request:
    branches:
    - main
  push:
    branches:
    - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Run tests
      run: python -m pytest

Features

  • Typed models — Pydantic models for workflows, jobs, steps, triggers, and permissions with full IDE autocomplete
  • YAML comments — block, end-of-line, and field-level comments preserved in output
  • DRY helpers — step factories (checkout(), setup_python(), setup_uv()) and expression builder (expr)
  • Escape hatchesRaw[T], extras, post_process, and CommentedMap passthrough for anything the typed API doesn't cover
  • Lintingghagen lint catches common problems (missing permissions, unpinned actions, missing timeout-minutes, duplicate step ids) at the Python level with source-line precision
  • CLIghagen synth generates YAML, ghagen check-synced verifies freshness in CI, ghagen lint runs rule-based checks, ghagen init scaffolds a starter config

Quick Start

# Scaffold a config file
ghagen init

# Generate workflow YAML
ghagen synth

# Verify workflows match Python definitions (for CI)
ghagen check-synced

# Lint workflow definitions
ghagen lint

Documentation

Full documentation: nathanjordan.github.io/ghagen

License

MIT

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

ghagen-0.3.1.tar.gz (253.0 kB view details)

Uploaded Source

Built Distribution

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

ghagen-0.3.1-py3-none-any.whl (107.5 kB view details)

Uploaded Python 3

File details

Details for the file ghagen-0.3.1.tar.gz.

File metadata

  • Download URL: ghagen-0.3.1.tar.gz
  • Upload date:
  • Size: 253.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ghagen-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d8955e29772015f825b2a506feb122395f17eeccd96bd5255842cd5b739b880c
MD5 f591fcb0c52b35bfcbc8469f7eab485f
BLAKE2b-256 254ab5984f787e83f3d72d9d047db20e3e29984e713915b9e90d6e0d457011c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghagen-0.3.1.tar.gz:

Publisher: release.yml on nathanjordan/ghagen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ghagen-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ghagen-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 107.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ghagen-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d885b09eec1742b6def16da01c8205e28bea2f24ce230b2ba393b6bda96d9536
MD5 7496e808954ac754ecb0a899932d9c84
BLAKE2b-256 83b1de0e19d66271a68a4fee88fe0e731834ae9566a34750dcd79adf887ab146

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghagen-0.3.1-py3-none-any.whl:

Publisher: release.yml on nathanjordan/ghagen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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