diff --git a/.github/workflows/dependency_graph.sh b/.github/workflows/dependency_graph.sh new file mode 100755 index 0000000..ffd17c2 --- /dev/null +++ b/.github/workflows/dependency_graph.sh @@ -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 diff --git a/.github/workflows/dependency_graph.yaml b/.github/workflows/dependency_graph.yaml new file mode 100644 index 0000000..1b7a2e0 --- /dev/null +++ b/.github/workflows/dependency_graph.yaml @@ -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