Created
July 21, 2023 03:10
-
-
Save creasty/4bdf29c672deecf7587baae3a3bfb9f6 to your computer and use it in GitHub Desktop.
Visualize circleci.yml workflow in mermaid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
CONFIG_FILE = ARGV[0] | |
config = YAML.load_file(CONFIG_FILE) | |
config['workflows'].each do |workflow_name, workflow| | |
next unless workflow.is_a?(Hash) | |
puts "### #{workflow_name}" | |
puts '```mermaid' | |
puts 'flowchart LR' | |
node_id_map = Hash.new { |h, k| h[k] = "N#{h.size}" } | |
job_name_alias_map = {} | |
workflow['jobs'].each do |job_bare| | |
case job_bare | |
when Hash | |
job_name = job_bare.keys.first | |
job = job_bare[job_name] | |
else | |
job_name = job_bare | |
job = {} | |
end | |
# Renaming | |
if job['name'] | |
job_name_alias_map[job['name']] = job_name | |
job_name = job['name'] | |
end | |
# Add node | |
node_id_map[job_name] | |
# Path | |
job['requires']&.each do |dependency| | |
puts "#{node_id_map[dependency]} --> #{node_id_map[job_name]}" | |
end | |
end | |
node_id_map.each do |name, id| | |
org_name = job_name_alias_map[name] | |
&.tap { |v| break " (#{v})" } | |
puts "#{id}[\"#{name}#{org_name}\"]" | |
end | |
puts '```' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment