Overview
The Sphinx domain gha documents GitHub Actions workflows - above all reusable workflows, whose inputs, outputs
and secrets are the interface a caller uses. What the workflow file states - an input’s type, whether it is required,
its default - is read from the file with pyTooling.GitHub.WorkflowFile, so a page doesn’t copy it and can’t
drift from it. What the file can’t say stays hand-written, as the content of a directive.
The domain is the Sphinx extension pyTooling.GitHub.Sphinx. It builds on
pyTooling.Sphinx, which it sets up itself, and is
installed with the extra sphinx: pyTooling.GitHub[sphinx].
# doc/conf.py
extensions = [
...,
"pyTooling.GitHub.Sphinx",
]
The domain’s directives are described on three pages:
- Workflows and Parameters
→
gha:workflowand the entries of its inputs, outputs and secrets, and the roles referring to them.- Summaries
→ Tables, the interface, the dependencies and YAML excerpts of a workflow.
- Pipeline Graph
→
gha:pipeline-graphdraws a workflow’s jobs and theirneeds.
Configuration
# doc/conf.py
gha_repository = "pyTooling/Actions" # the documented repository
gha_workflow_directory = "../.github/workflows" # relative to the Sphinx source directory
gha_ref = "r8" # the ref the documentation describes
- gha_workflow_directory
The directory holding the workflow files, relative to the Sphinx source directory. A
gha:workflowwithout:file:reads<name>.ymlfrom it. Default:None.
- gha_repository
The documented repository, as
owner/repo. A job callingowner/repo/.github/workflows/X.yml@<ref>is resolved toX.ymlingha_workflow_directory, whatever the ref. Default:None.
- gha_ref
The ref - a branch or tag - of the documented repository the documentation describes, as
r8. A job calling a workflow of the documented repository at another ref is a warning.Nonechecks nothing. Default:None.
- gha_server
The URL of the GitHub server the links of
gha:yaml,gha:interfaceandgha:dependenciespoint to:https://github.com, or a GitHub Enterprise Server’s, ashttps://github.example.com. Default:"https://github.com".
- gha_label_prefix
The root of the
:ref:labels the directives register besides their targets - see Labels of Existing Pages.Noneregisters none. Default:"JOBTMPL".
Labels of Existing Pages
Besides its target, each directive registers the :ref: label a page would have declared by hand, so existing
references keep working when a page is converted - gha_label_prefix is their root:
JOBTMPL/Parameters .. gha:workflow:: Parameters
JOBTMPL/Parameters/Input/package_name .. gha:input:: package_name
JOBTMPL/Parameters/Output/python_jobs .. gha:output:: python_jobs
JOBTMPL/PublishOnPyPI/Secret/PYPI_TOKEN .. gha:secret:: PYPI_TOKEN
A parameter’s section carries the anchor of its label, and the anchor docutils derives from its title, so a link into the hand-written page lands on the same entry. A label still declared by hand next to the directive is a duplicate.
Warnings
The page and the workflow file are compared while the page is read. A difference is a warning of type
gha.drift, so -W fails the build, and suppress_warnings = ["gha.drift"] silences it. Where the problem is
in the file, the warning names the place in the file, as Package.yml:8.
An input is required and has a default, which is never used - named in the workflow file.
A
gha:input,gha:outputorgha:secretnames a parameter the workflow doesn’t have.A hand-written Type, Required or Default Value of an input or a secret repeats a fact of the workflow file. It is not shown; the file’s value is.
An input has no entry in the document - neither a
gha:inputnor agha:autoinputs- reported at thegha:workflowwhen the whole document was read.A
gha:yamlnames a job the workflow doesn’t have, or a section the workflow has nothing in.
A workflow file that can’t be found or read is a warning of type gha.workflow, as is a gha:input or a summary
directive without a preceding gha:workflow.
Extending the Domain
A directive of another module reaches the domain with self.env.get_domain("gha"), a
GitHubActionsDomain:
GetCurrentWorkflow()returns the model of the document’s current workflow, apyTooling.GitHub.WorkflowFile.Workflow;Resolverreads the workflows a job calls, every file once;ResolveWorkflow()says where a workflow is documented;ParameterDirective.CreateEntrycreates a parameter’s entry and registers it, asgha:autoinputsdoes.
A directive is added to the domain with
Sphinx.add_directive_to_domain.