Skip to content

docs(sim-ui): added d2 #3

docs(sim-ui): added d2

docs(sim-ui): added d2 #3

Workflow file for this run

name: "docs"
on:
pull_request:
paths:
- "**/*.d2"
- "site/**"
push:
branches:
- main
paths:
- "**/*.d2"
- "site/**"
jobs:
docs-generate-d2-diagrams:
name: "Generate D2 Diagrams"
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 2 # Needed to get previous commit for comparison
- name: Install D2
run: |
curl -fsSL https://d2lang.com/install.sh | sh -s --
d2 --version
- name: Generate PNG files for changed D2 files
run: |
# Get list of changed .d2 files
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD | grep '\.d2$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No .d2 files were changed"
exit 0
fi
echo "Changed .d2 files:"
echo "$CHANGED_FILES"
# Process each changed file
echo "$CHANGED_FILES" | while read -r file; do
if [ -f "$file" ]; then
output_file="${file%.d2}.png"
echo "Converting $file to $output_file"
d2 "$file" "$output_file"
fi
done
- name: Check for changes
id: changes
run: |
git add *.png
if git diff --staged --quiet; then
echo "No changes to commit"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -m "Auto-generate diagram PNGs [skip ci]"
git push origin HEAD:${{ github.head_ref || github.ref_name }}
docs-build:
name: "Build"
runs-on: ubuntu-22.04
outputs:
has_changes: ${{ steps.check_changes.outputs.has_changes }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for site changes
id: check_changes
run: |
SITE_CHANGES=$(git diff --name-only HEAD^ HEAD -- site/ || true)
if [ -z "$SITE_CHANGES" ]; then
echo "No changes in site directory"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in site directory:"
echo "$SITE_CHANGES"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
shell: "bash"
- name: 🛠️ Setup Node.js
if: steps.check_changes.outputs.has_changes == 'true'
uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"
cache-dependency-path: site/yarn.lock
- name: 📦 Install dependencies
if: steps.check_changes.outputs.has_changes == 'true'
working-directory: site
run: yarn install
- name: 🏗️ Build Docusaurus site
if: steps.check_changes.outputs.has_changes == 'true'
working-directory: site
run: |
yarn build
- name: 🚀 Publish Docusaurus build
if: steps.check_changes.outputs.has_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: docusaurus-build
if-no-files-found: error
path: |
site/build/*
docs-publish:
name: "Publish"
if:
${{ github.ref == 'refs/heads/main' &&
needs.docs-build.outputs.has_changes == 'true' }}
runs-on: ubuntu-22.04
needs: docs-build
steps:
- name: 📥 Download Docusaurus build
uses: actions/download-artifact@v4
with:
name: docusaurus-build
path: ./github-pages
- name: 🚀 Publish GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN || github.token }}
publish_dir: ./github-pages
cname: leios.cardano-scaling.org