Added Github action for generating the dependency graph

This commit is contained in:
Blake Jakopovic 2023-03-25 15:52:27 +01:00
parent 02e9aec1a6
commit 4765fe75ef
2 changed files with 64 additions and 0 deletions

32
.github/workflows/dependency_graph.sh vendored Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
# Create graph dot file
echo "digraph {" > dependency_graph.dot
# Loop over files in current directory starting with two or more numbers and ending in .md
for file in [0-9][0-9]*.md; do
# Check if file exists
if [ -e "$file" ]; then
current_nip=$(echo $file | grep -o "^[0-9]\+")
# Add NIP label for node
title=$(echo "$(head -n 1 "$file"): $(sed '4q;d' "$file" | sed 's/"/\\"/g' | sed 's/\`//g')")
echo -e "\t${current_nip} [label=\"${title}\"]" >> dependency_graph.dot
# Extract NIP dependencies
depends=$(grep -o "depends:[0-9]\+" "$file" | grep -o "[0-9]\+")
if [ -n "$depends" ]; then
# Add graph dependency edge
for dep_nip in $depends; do
echo -e "\t${current_nip}->${dep_nip}" >> dependency_graph.dot
done
fi
fi
done
# Close graph file
echo -n "}" >> dependency_graph.dot
# Generate dependency graph
dot -Tsvg dependency_graph.dot > dependency_graph.svg

32
.github/workflows/dependency_graph.yaml vendored Normal file
View File

@ -0,0 +1,32 @@
# This is a basic workflow to help you get started with GitHub Actions
name: Generate NIPs dependency graph
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-on-ubuntu:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: step 1 - Checkout the main GitHub branch
uses: actions/checkout@v2
- name: Step 2 - Install Graphviz
run: echo "TODO"
# sh ./.github/workflows/dependency_graph.sh
- name: Step 3 - Generate dependency graph svg
run: sh ./.github/workflows/dependency_graph.sh
- name: Step 4 - Do something with image
run: dot -Tsvg dependency_graph.dot > dependency_graph.svg