mirror of
https://github.com/TeachBooks/template.git
synced 2026-11-12 22:25:52 +00:00
135 lines
No EOL
3.6 KiB
YAML
135 lines
No EOL
3.6 KiB
YAML
name: deploy-book
|
|
|
|
# Based on:
|
|
# https://jupyterbook.org/en/stable/publish/gh-pages.html
|
|
|
|
# Run on a push to any branch, then deploy books from all branches.
|
|
on:
|
|
push:
|
|
branches:
|
|
- '*'
|
|
# If your git repository has the Jupyter Book within some-subfolder next to
|
|
# unrelated files, you can make this run only if a file within that specific
|
|
# folder has been modified.
|
|
#
|
|
# paths:
|
|
# - some-subfolder/**
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
get-branches:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
branches: ${{ steps.set-branches.outputs.branches }}
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- id: set-branches
|
|
name: Collect all remote branch names for the matrix
|
|
run: |
|
|
branches=$(git branch -r | sed 's,\s*origin/,,g' | jq -Rn '[inputs]')
|
|
echo "branches=$(echo $branches)" >> $GITHUB_OUTPUT
|
|
|
|
build-books:
|
|
runs-on: ubuntu-latest
|
|
needs: get-branches
|
|
permissions:
|
|
pages: write
|
|
id-token: write
|
|
strategy:
|
|
# If one branch fails, we may still want to deploy the other
|
|
fail-fast: false
|
|
matrix:
|
|
branch: ${{ fromJson(needs.get-branches.outputs.branches) }}
|
|
steps:
|
|
- name: Checkout to branch
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ matrix.branch }}
|
|
|
|
- name: Cache page build
|
|
id: cache-html
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: "book/_build/html"
|
|
key: html-build-${{ hashFiles('book/**', 'figures/**', 'requirements.txt') }}
|
|
|
|
- if: ${{ steps.cache-html.outputs.cache-hit != 'true' }}
|
|
name: Set up Python 3.11
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: 3.11
|
|
cache: 'pip'
|
|
|
|
- if: ${{ steps.cache-html.outputs.cache-hit != 'true' }}
|
|
name: Install dependencies
|
|
run: |
|
|
pip install -r requirements.txt
|
|
|
|
- if: ${{ steps.cache-html.outputs.cache-hit != 'true' }}
|
|
name: Preprocess & build the book from branch
|
|
run: |
|
|
echo $PATH
|
|
pip install --user teachbooks --extra-index-url https://gitlab.tudelft.nl/api/v4/projects/13957/packages/pypi/simple
|
|
cat book/_toc.yml
|
|
teachbooks build --publish --process-only book/
|
|
mv book/.psorbooks/publish/_toc.yml book/.psorbooks/publish/_config.yml book/
|
|
cat book/_toc.yml
|
|
jupyter-book build book/
|
|
|
|
- name: Upload the built book HTML as an artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ matrix.branch }}
|
|
path: "book/_build/html"
|
|
|
|
deploy-books:
|
|
# Run after build-books, even if it failed
|
|
if: always()
|
|
needs: build-books
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pages: write
|
|
id-token: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- run: |
|
|
mkdir final/
|
|
|
|
- name: Download all book artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: "final/"
|
|
|
|
- name: Copy primary book to root, fail if names conflict
|
|
timeout-minutes: 1
|
|
run: |
|
|
GLOBIGNORE=".:.."
|
|
# -i leads to a prompt in case of conflict, => a timeout
|
|
if [ -d final/$PRIMARY_BRANCH ]; then
|
|
cp -irv final/$PRIMARY_BRANCH/* final/
|
|
fi
|
|
ls -a final/
|
|
|
|
- name: Load root page to redirect to `book/`
|
|
run: |
|
|
cp redirect.html final/index.html
|
|
|
|
- name: Upload final Pages artifact
|
|
uses: actions/upload-pages-artifact@v3
|
|
with:
|
|
path: "final/"
|
|
|
|
- name: Deploy to GitHub Pages
|
|
id: deployment
|
|
uses: actions/deploy-pages@v4
|
|
|
|
|
|
permissions:
|
|
contents: read
|
|
pages: write
|
|
id-token: write |