mirror of
https://github.com/TeachBooks/template.git
synced 2026-11-13 22:55:51 +00:00
build: Build books for multiple branches
This commit is contained in:
parent
70819bfbad
commit
409750bb36
2 changed files with 85 additions and 24 deletions
94
.github/workflows/deploy-book-ghpages.yml
vendored
94
.github/workflows/deploy-book-ghpages.yml
vendored
|
|
@ -3,12 +3,11 @@ name: deploy-book
|
||||||
# Based on:
|
# Based on:
|
||||||
# https://jupyterbook.org/en/stable/publish/gh-pages.html
|
# https://jupyterbook.org/en/stable/publish/gh-pages.html
|
||||||
|
|
||||||
# Run this when the master or main branch changes, or when dispatched
|
# Run on a push to any branch, then deploy books from all branches.
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- '*'
|
||||||
- main
|
|
||||||
# If your git repository has the Jupyter Book within some-subfolder next to
|
# 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
|
# unrelated files, you can make this run only if a file within that specific
|
||||||
# folder has been modified.
|
# folder has been modified.
|
||||||
|
|
@ -17,19 +16,43 @@ on:
|
||||||
# - some-subfolder/**
|
# - some-subfolder/**
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# This job installs dependencies, builds the book, and pushes it to `gh-pages`
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy-book:
|
get-branches:
|
||||||
runs-on: ubuntu-latest
|
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:
|
permissions:
|
||||||
pages: write
|
pages: write
|
||||||
id-token: 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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout to branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ matrix.branch }}
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
- name: Set up Python 3.11
|
- name: Set up Python 3.11
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: 3.11
|
python-version: 3.11
|
||||||
|
|
||||||
|
|
@ -37,31 +60,54 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
# (optional) Cache your executed notebooks between runs
|
- name: Build the book from branch
|
||||||
# if you have config:
|
|
||||||
# execute:
|
|
||||||
# execute_notebooks: cache
|
|
||||||
- name: cache executed notebooks
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: _build/.jupyter_cache
|
|
||||||
key: jupyter-book-cache-${{ hashFiles('requirements.txt') }}
|
|
||||||
|
|
||||||
# Build the book
|
|
||||||
- name: Build the book
|
|
||||||
run: |
|
run: |
|
||||||
jupyter-book build book/
|
jupyter-book build book/
|
||||||
|
|
||||||
# Upload the book's HTML as an artifact
|
- name: Upload the built book HTML as an artifact
|
||||||
- name: Upload artifact
|
uses: actions/upload-artifact@v4
|
||||||
uses: actions/upload-pages-artifact@v2
|
|
||||||
with:
|
with:
|
||||||
|
name: ${{ matrix.branch }}
|
||||||
path: "book/_build/html"
|
path: "book/_build/html"
|
||||||
|
|
||||||
# Deploy the book's HTML to GitHub Pages
|
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: Symlink `book` to `main`
|
||||||
|
run: |
|
||||||
|
if test -d final/main; then
|
||||||
|
ln -s main final/book
|
||||||
|
fi
|
||||||
|
|
||||||
|
- 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
|
- name: Deploy to GitHub Pages
|
||||||
id: deployment
|
id: deployment
|
||||||
uses: actions/deploy-pages@v2
|
uses: actions/deploy-pages@v4
|
||||||
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
|
||||||
15
redirect.html
Normal file
15
redirect.html
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
pattern = /^https?:\/\/[\w-\.]+\.github\.io\/[\w-\.]+\/?$/
|
||||||
|
if (pattern.test(window.location.href)) {
|
||||||
|
window.location.href = window.location.href + "book/";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue