Builds a Mermaid flowchart of a repo's CI/CD pipeline from its local GHA
workflow files, laid out top to bottom. Each workflow is a subgraph headed by
its trigger, each job a single node listing its steps, and job edges follow
needs: (with redundant transitive edges removed). Jobs calling a reusable workflow (uses:) have
its steps fetched from the pinned @ref. Simple step conditions of the form
inputs.x, !inputs.x or inputs.x == true|false are evaluated against the
caller's with: and the reusable workflow's input defaults: steps that won't
run are dropped, steps whose condition can't be decided are marked (if).
Arguments
- wf_dir
(
character(1))
Path to the repo's.github/workflowsdirectory.- workflows
(
character())
Workflow file names underwf_dir, in pipeline order. Consecutive workflows are linked (e.g. bump pushes the tag that triggers deploy).- actions_dir
(
character(1))
Optional local directory holding the reusable workflow files. WhenNULL(default) they're fetched fromraw.githubusercontent.comat the ref pinned in eachuses:.- skip
(
character())
Case-insensitive regex patterns; matching step names are left out (setup boilerplate repeated across jobs).
Examples
# Real usage (requires network):
# nemo_gha_mermaid(here::here(".github/workflows"))
wf <- tempfile() |> fs::dir_create()
act <- tempfile() |> fs::dir_create()
ru <- function(f) paste0("org/actions/.github/workflows/", f, "@v1")
yaml::write_yaml(
list(name = "Bump", on = list(workflow_dispatch = NULL), jobs = list(
bump = list(uses = ru("bump.yaml"))
)),
file.path(wf, "bump.yaml")
)
yaml::write_yaml(
list(name = "Deploy", on = list(push = list(tags = "v*")), jobs = list(
prep = list(name = "Version", steps = list(list(run = "echo"))),
build = list(name = "Build", needs = "prep", uses = ru("build.yaml")),
docs = list(
name = "Docs", needs = c("prep", "build"),
uses = ru("docs.yaml"), with = list(extra = FALSE)
),
img = list(name = "Image", needs = c("prep", "build"), uses = ru("img.yaml"))
)),
file.path(wf, "deploy.yaml")
)
steps <- function(...) list(jobs = list(j = list(steps = list(...))))
yaml::write_yaml(
steps(list(name = "Codeout"), list(name = "Bump version"), list(name = "Push tag")),
file.path(act, "bump.yaml")
)
yaml::write_yaml(steps(list(name = "Build pkg")), file.path(act, "build.yaml"))
yaml::write_yaml(steps(list(name = "Build image")), file.path(act, "img.yaml"))
docs <- steps(
list(name = "Extra step", `if` = "inputs.extra == true"),
list(name = "Maybe step", `if` = "github.event_name == 'push'"),
list(name = "Build site")
)
docs$on <- list(workflow_call = list(inputs = list(extra = list(default = TRUE))))
yaml::write_yaml(docs, file.path(act, "docs.yaml"))
diagram <- nemo_gha_mermaid(wf, actions_dir = act)
