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

pip install ghagen

Example

from ghagen import Workflow, Job, Step, On, App
from ghagen.models.trigger import PushTrigger, PRTrigger

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(outdir=".github/workflows")
app.add(workflow, filename="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
  • CLIghagen synth generates YAML, ghagen check verifies freshness in CI, 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

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.2.1.tar.gz (67.3 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.2.1-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ghagen-0.2.1.tar.gz
Algorithm Hash digest
SHA256 799c5947a2d2f321cf25754ea737d8d5e42a19c8c47fb93c970f8e5dcb94ff17
MD5 3cbb7cefa81bf3a0e1b23ac432ac16de
BLAKE2b-256 aa33cefc4598f857278ff9dfae762bdcbf92a830ad556340a1cad5c332b3bca5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghagen-0.2.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.2.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for ghagen-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ca00db3d46f9f33f11b19f8535689fe2676d405795b8a74fbc506db6eb1ca53
MD5 fe4bdbd3012b5047c266a227f98c79d4
BLAKE2b-256 b2b896046bba7f9318dc573bfad77619944c5a501f8f4b58a1c9669e3c6b0f75

See more details on using hashes here.

Provenance

The following attestation bundles were made for ghagen-0.2.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