Generate D2 Diagrams #11
This file contains hidden or 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
name: Generate D2 Diagrams | |
on: | |
workflow_dispatch: | |
jobs: | |
generate-diagram: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
CI_COMMIT_MESSAGE: Update generated diagrams with D2 | |
CI_COMMIT_AUTHOR: D2 Diagram Creator | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Git Global Config | |
run: | | |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}" | |
git config --global user.email "actions@github.com" | |
- name: Download and install D2 using the official installer | |
run: | | |
# Install D2 using the provided installer script | |
curl -fsSL https://d2lang.com/install.sh | sh -s -- | |
- name: Create output directory | |
run: mkdir -p output/d2-diagrams/ | |
- name: Generate Diagrams with D2 | |
run: | | |
# Get current timestamp | |
timestamp=$(date +"%Y-%m-%d-%H-%M-%S") | |
# Find all .d2 files in the repo and generate corresponding .svg files | |
for file in $(find . -name '*.d2'); do | |
# Extract the base file name without the extension | |
base_name=$(basename "$file" .d2) | |
# Generate the diagram in SVG format and store it in the output directory | |
d2 "$file" "output/d2-diagrams/${base_name}-$timestamp.svg" | |
done | |
- name: List generated files (for debugging) | |
run: ls -al output/d2-diagrams/ | |
- name: Add output files & Status | |
run: | | |
git add output/ | |
git status | |
- name: Commit and Push generated diagrams to repository | |
run: | | |
git commit --verbose -a -m "${{ env.CI_COMMIT_MESSAGE }}" || echo "No changes to commit" | |
git push origin main --force --verbose | |
- name: Upload generated diagrams as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: generated-diagrams | |
path: output/d2-diagrams/ |