Skip to content

Adversarial mempool simulations w/ Leios #599

Adversarial mempool simulations w/ Leios

Adversarial mempool simulations w/ Leios #599

Workflow file for this run

name: "docs"
on:
pull_request:
paths:
- "**/*.d2"
- "site/**"
- "ui/**"
- "post-cip/mempool-sim-viz/**"
- "post-cip/mempool-sim-web/**"
- ".github/workflows/docs.yaml"
push:
branches:
- main
paths:
- "**/*.d2"
- "site/**"
- "ui/**"
- "post-cip/mempool-sim-viz/**"
- "post-cip/mempool-sim-web/**"
workflow_dispatch: # Allow manual triggering for formal spec updates
permissions:
contents: write
pages: write
actions: read
# Prevent redundant workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docs-generate-d2-diagrams:
name: "Generate D2 Diagrams"
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
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: Cache D2
uses: actions/cache@v4
with:
path: ~/.d2
key: ${{ runner.os }}-d2-${{ hashFiles('**/install.sh') }}
restore-keys: |
${{ runner.os }}-d2-
- name: Install D2
run: |
if ! command -v d2 &> /dev/null; then
curl -fsSL https://d2lang.com/install.sh | sh -s --
fi
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"
else
echo "File $file does not exist, skipping"
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 }}
viz-build:
name: "Build Visualizer"
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
# LFS disabled: trace files are now stored as regular git files (not LFS)
# to avoid exceeding GitHub's LFS bandwidth quota
lfs: false
fetch-depth: 2
- name: 🛠️ Setup Node.js
uses: actions/setup-node@v6
- name: 📦 Install dependencies
working-directory: ui
run: npm install
- name: 🏗️ Build visualizer
working-directory: ui
run: npm run build
- name: 🚢 Upload visualizer static site
id: upload_viz
uses: actions/upload-artifact@v4
with:
name: visualizer
path: ui/dist
mempool-viz-build:
name: "Build Mempool Visualizer"
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install mempool-sim-web dependencies
working-directory: post-cip/mempool-sim-web
run: npm install
- name: Install mempool-sim-viz dependencies
working-directory: post-cip/mempool-sim-viz
run: npm install
- name: Build mempool visualizer
working-directory: post-cip/mempool-sim-viz
run: npm run build
- name: Upload mempool visualizer
uses: actions/upload-artifact@v4
with:
name: mempool-visualizer
path: post-cip/mempool-sim-viz/dist
build-docusaurus-site:
name: "Build Docusaurus Site"
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [viz-build, mempool-viz-build]
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 🛠️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "npm"
cache-dependency-path: ./site/package-lock.json
- name: 📦 Install dependencies
working-directory: site
run: npm ci
- name: 👁️ Unpack visualizer
uses: actions/download-artifact@v4
with:
name: visualizer
path: site/static/visualizer
- name: Unpack mempool visualizer
uses: actions/download-artifact@v4
with:
name: mempool-visualizer
path: site/static/mempool-viz
- name: 🔧 Setup Nix
uses: cachix/install-nix-action@v24
with:
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
- name: 🏗️ Build leios design pdf
run: |
nix build .#leiosDesignPdf -L
cp result/leios-design.pdf site/static/
ls -la site/static/leios-design.pdf
- name: 📚 Build formal-spec HTML documentation
run: |
nix build .#leiosDocs
mkdir -p formal-spec-html
cp -r result/html/* formal-spec-html/
chmod -R +w formal-spec-html/
ls -la formal-spec-html/
- name: 🔄 Enhance formal-spec with interactive features
uses: will-break-it/agda-web-docs-lib@v1
with:
input-dir: formal-spec-html
config-file: site/agda-docs.config.json
cache-dependency-path: site/package-lock.json
node-options: "--max-old-space-size=8192 --expose-gc"
- name: 📦 Copy enhanced formal-spec to site
run: |
mkdir -p site/static/formal-spec
cp -r formal-spec-html/* site/static/formal-spec/
echo "Formal spec files copied:"
ls -la site/static/formal-spec/ | head -20
- name: 🏗️ Build Docusaurus site
working-directory: site
run: |
find static
npm run build
- name: Verify Docusaurus build
working-directory: site
run: |
if [ -z "$(ls -A build/)" ]; then
echo "Error: Docusaurus build directory is empty"
exit 1
fi
ls -la build/
- name: 🚀 Upload Docusaurus build
uses: actions/upload-artifact@v4
with:
name: docusaurus-build
if-no-files-found: error
path: |
site/build/*
docs-publish:
name: "Publish Docs"
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
needs: [build-docusaurus-site]
runs-on: ubuntu-latest
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