Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

WorkflowMD

Nice docs with correct examples for your GitHub reusable workflows.

workflowmd demo

WorkflowMD generates Markdown docs for your GitHub reusable workflows, using a metadata file that includes a description and examples which are validated when rendering to ensure your docs are correct.

Note, the screen capture demo shows stylised output using MkDocs Material with a custom CSS. This is just an example usage, and not a requirement.

Requirements

  • Python 3.11+

The GitHub workflow files must have on: workflow_call.

Installation

Requires Python 3.11+.

pip install workflowmd

Or install it as an isolated tool with uv:

uv tool install workflowmd

Usage

Show usage and options:

workflowmd --help

Generate the Markdown file using the following command:

workflowmd <workflow-file> -o <output-file>

If you want to include a description and examples, specify a metadata file with -m:

workflowmd <workflow-file> -m <metadata-file> -o <output-file>

An example metadata file:

description: |
  Deploys the application to the chosen environment.
  Runs the test suite first unless run-tests is false.

examples:
  - title: Deploy to staging
    description: Skips tests for a quick staging deploy.
    with:
      environment: staging
      run-tests: false
    secrets:
      deploy-token: ${{ secrets.STAGING_TOKEN }}

  - title: Deploy to production
    description: Runs the full test suite and sends a Slack notification.
    with:
      environment: production
      python-version: "3.12"
    secrets:
      deploy-token: ${{ secrets.PROD_TOKEN }}
      slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

Both description and examples are optional. The with and secrets values in each example are validated against the workflow's declared inputs and secrets when rendering.

Advanced: Custom template

If you would like to use a custom template, for example to reorder/exclude sections, change headings, etc. this can be done using -t:

workflowmd <workflow-file> -t <template-file> -o <output-file>

We're using Jinja2 templates. The context includes a WorkflowDefinition instance as workflow and a WorkflowMetadata instance as docs. Feel free to use the existing partials here.

Advanced: Custom metadata model

If you would like to extend the WorkflowMetadata model to include your own fields which can be read in from the metadata file, you can call the render function directly and specify a metadata_model.

from pathlib import Path

from workflowmd import WorkflowMetadata, render


class TeamMetadata(WorkflowMetadata):
    owner: str
    tags: list[str] = []


render(
    Path("my_workflow.yaml"),
    Path("output/my_workflow.md"),
    metadata_path=Path("my_workflow.docs.yaml"),
    template_path=Path(
        "my_template.md.j2"
    ),  # note: a custom template is required to access custom fields
    metadata_model=TeamMetadata,
)

A corresponding metadata file could be as follows:

owner: platform
tags: [ci, deploy]

The custom fields can be accessed in the template via docs:

## Owner
{{ docs.owner }}

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages