Add links to Binder (#42) #1
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: Sync Notebooks | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - 'QuantumToolbox.jl/**/*.qmd' | |
| - 'HierarchicalEOM.jl/**/*.qmd' | |
| - 'Project.toml' | |
| - 'apt.txt' | |
| - 'postBuild' | |
| - '.jupyter/**' | |
| - '.github/workflows/build-notebooks.yml' | |
| - '.github/workflows/build-notebooks-container.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Quarto | |
| uses: quarto-dev/quarto-actions/setup@v2 | |
| - name: Render QMD → IPYNB | |
| run: | | |
| set -euo pipefail | |
| shopt -s globstar nullglob | |
| for src in QuantumToolbox.jl/**/*.qmd; do | |
| quarto render "$src" --to ipynb | |
| done | |
| for src in HierarchicalEOM.jl/**/*.qmd; do | |
| quarto render "$src" --to ipynb | |
| done | |
| - name: Checkout notebooks branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: notebooks | |
| path: branch-out | |
| fetch-depth: 0 | |
| # Prune stale files | |
| # This looks at every tracked *.ipynb, checks whether *.qmd still exists in main, and removes it from the index if not. | |
| - name: Remove stale notebooks | |
| run: | | |
| cd branch-out | |
| git ls-files "*.ipynb" | while read ipynb; do | |
| src="../${ipynb%.ipynb}.qmd" | |
| if [ ! -f "$src" ]; then | |
| git rm --ignore-unmatch "$ipynb" | |
| fi | |
| done | |
| cd .. | |
| - name: Copy artifacts | |
| run: | | |
| # helper files at root | |
| cp Project.toml runtime.txt apt.txt postBuild branch-out/ 2>/dev/null || true | |
| cp -r .jupyter branch-out/ 2>/dev/null || true | |
| rsync -avc --exclude='branch-out/' --include='*/' --include='*.ipynb' --exclude='*' --prune-empty-dirs ./ branch-out/ | |
| - name: Commit & Push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| cd branch-out | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git add . | |
| if git diff --cached --quiet; then | |
| echo "✅ No changes to push" | |
| else | |
| git commit -m "Update notebooks from ${{ github.sha }}" | |
| git push origin notebooks | |
| fi |