Skip to content

Commit

Permalink
fix: updates argo to mermaid script for new workflow directory struct…
Browse files Browse the repository at this point in the history
…ure and layout
  • Loading branch information
nicholaskuechler committed Nov 13, 2024
1 parent 1eccdab commit 04bf5a4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ docs/workflows/
# devbox's envrc
.envrc
.direnv

# mkdocs site output
site/
2 changes: 1 addition & 1 deletion docs/component-understack-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ execute a Workflow.
Service Account access it needs to run Workflows.
1. An [Argo Events][argo-events] Sensors and Triggers that
execute workflows.
1. [Workflow Templates](./workflows/argo-events.md)
1. [Workflow Templates](./workflows/enroll-server.md)

## Containers and Source Code

Expand Down
76 changes: 54 additions & 22 deletions scripts/argo-workflows-to-mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,60 @@ def main():
)
continue

workflows = {}
for workflow_file in workflow_files:
workflows = {}

w_yaml = parse_yaml(workflow_file)
readme_file = workflow.path + "/docs/README.md"
workflow_readme = load_readme(readme_file)
workflow_name = w_yaml["metadata"]["name"]
workflow_title = (
w_yaml["metadata"]
.get("annotations", {})
.get("workflows.argoproj.io/title", "Title not set in workflow")
)
workflow_description = (
w_yaml["metadata"]
.get("annotations", {})
.get(
"workflows.argoproj.io/description",
"Description not set in workflow",
)
.strip("\n")
)

# replace spaces with dashes because we're using workflow_name
# as the filename in mkdocs
workflow_name.replace(" ", "-")

workflow_readme = f"## {workflow_title} \n\n {workflow_description}"

if not w_yaml:
print(f"Failed to parse {workflow_file}")
continue
w = make_workflow(w_yaml)
workflows[w.name] = w

nodes = {}
for w in workflows.values():
for n in w.nodes:
nodes[n.id] = n
for w in workflows.values():
for n in w.nodes:
for t in n.tasks:
if nodes.get(t.ref_node):
nodes[t.ref_node].incoming_count += 1
for t in n.steps:
if nodes.get(t.ref_node):
nodes[t.ref_node].incoming_count += 1

output_file = output_dir + f"/{workflow.name}.md"

generate_mermaid(
workflows.values(), nodes, workflow.name, output_file, workflow_readme
)
nodes = {}
for w in workflows.values():
for n in w.nodes:
nodes[n.id] = n
for w in workflows.values():
for n in w.nodes:
for t in n.tasks:
if nodes.get(t.ref_node):
nodes[t.ref_node].incoming_count += 1
for t in n.steps:
if nodes.get(t.ref_node):
nodes[t.ref_node].incoming_count += 1

output_file = output_dir + f"/{workflow_name}.md"

generate_mermaid(
workflows.values(),
nodes,
w_yaml["metadata"]["name"],
output_file,
workflow_readme,
)


def make_workflow(w_yaml):
Expand Down Expand Up @@ -616,7 +641,14 @@ def generate_mermaid(workflows, nodes, output_name, output_file, workflow_readme
with open(output_file, "w") as f:
f.write(f"# {output_name}\n")
f.write("\n")
f.write("# Workflow Diagram\n")

if workflow_readme:
f.write(workflow_readme)
else:
f.write("This workflow does not have a `docs/README.md` file! :(\n")

f.write("\n")
f.write("## Workflow Diagram\n")
f.write("\n")
f.write("```mermaid\n")
f.write(mermaid_output)
Expand Down

0 comments on commit 04bf5a4

Please sign in to comment.