1+ name : Sync Notebooks
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ paths :
7+ - ' QuantumToolbox.jl/**/*.qmd'
8+ - ' HierarchicalEOM.jl/**/*.qmd'
9+ - ' Project.toml'
10+ - ' apt.txt'
11+ - ' postBuild'
12+ - ' .jupyter/**'
13+ - ' .github/workflows/build-notebooks.yml'
14+ - ' .github/workflows/build-notebooks-container.yml'
15+ workflow_dispatch :
16+
17+ permissions :
18+ contents : write
19+
20+ jobs :
21+ build :
22+ runs-on : ubuntu-latest
23+ steps :
24+ - name : Checkout main
25+ uses : actions/checkout@v4
26+ with :
27+ fetch-depth : 0
28+
29+ - name : Setup Quarto
30+ uses : quarto-dev/quarto-actions/setup@v2
31+
32+ - name : Render QMD → IPYNB
33+ run : |
34+ set -euo pipefail
35+ shopt -s globstar nullglob
36+ for src in QuantumToolbox.jl/**/*.qmd; do
37+ quarto render "$src" --to ipynb
38+ done
39+ for src in HierarchicalEOM.jl/**/*.qmd; do
40+ quarto render "$src" --to ipynb
41+ done
42+
43+ - name : Checkout notebooks branch
44+ uses : actions/checkout@v4
45+ with :
46+ ref : notebooks
47+ path : branch-out
48+ fetch-depth : 0
49+
50+ # Prune stale files
51+ # This looks at every tracked *.ipynb, checks whether *.qmd still exists in main, and removes it from the index if not.
52+ - name : Remove stale notebooks
53+ run : |
54+ cd branch-out
55+ git ls-files "*.ipynb" | while read ipynb; do
56+ src="../${ipynb%.ipynb}.qmd"
57+ if [ ! -f "$src" ]; then
58+ git rm --ignore-unmatch "$ipynb"
59+ fi
60+ done
61+ cd ..
62+
63+ - name : Copy artifacts
64+ run : |
65+ # helper files at root
66+ cp Project.toml runtime.txt apt.txt postBuild branch-out/ 2>/dev/null || true
67+ cp -r .jupyter branch-out/ 2>/dev/null || true
68+
69+ rsync -avc --exclude='branch-out/' --include='*/' --include='*.ipynb' --exclude='*' --prune-empty-dirs ./ branch-out/
70+
71+ - name : Commit & Push
72+ env :
73+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
74+ run : |
75+ cd branch-out
76+ git config user.name "github-actions"
77+ git config user.email "[email protected] " 78+ git add .
79+ if git diff --cached --quiet; then
80+ echo "✅ No changes to push"
81+ else
82+ git commit -m "Update notebooks from ${{ github.sha }}"
83+ git push origin notebooks
84+ fi
0 commit comments