Skip to contents

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).

Usage

nemo_gha_mermaid(
  wf_dir,
  workflows = c("bump.yaml", "deploy.yaml"),
  actions_dir = NULL,
  skip = c("app token", "codeout", "miniforge setup", "qemu setup", "buildx setup",
    "cr login")
)

Arguments

wf_dir

(character(1))
Path to the repo's .github/workflows directory.

workflows

(character())
Workflow file names under wf_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. When NULL (default) they're fetched from raw.githubusercontent.com at the ref pinned in each uses:.

skip

(character())
Case-insensitive regex patterns; matching step names are left out (setup boilerplate repeated across jobs).

Value

A character string containing the Mermaid diagram.

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)