Website update #298
This file contains 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: "Website update" | |
on: | |
push: | |
branches: | |
- "**" | |
- "!gh-pages" | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: "0 3 * * MON" | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: "Branch on FEMlium repository" | |
type: string | |
reset_github_pages: | |
description: "Reset the gh-pages branch (yes or no; default: no). Remember to set the gh-pages branch back in Settings -> Pages!" | |
type: string | |
jobs: | |
convert_notebooks: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- backend: none | |
container: debian:testing | |
setup_git: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq git | |
setup_container: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq python3-mpi4py python3-numpy python3-pip xorg xvfb | |
rm /usr/lib/python3.*/EXTERNALLY-MANAGED | |
notebook_pattern: | | |
"**/generate_mesh*.ipynb" | |
"**/tutorial_*_meshio.ipynb" | |
- backend: dolfin | |
container: numericalpdes/base_images:fenics-real | |
setup_git: "" | |
setup_container: | | |
apt update -y -q | |
apt install -y -qq xvfb | |
notebook_pattern: | | |
"**/tutorial_*_dolfin.ipynb" | |
- backend: dolfinx | |
container: ghcr.io/fenics/dolfinx/dolfinx:nightly | |
setup_git: "" | |
setup_container: | | |
apt update -y -q | |
apt install -y -qq xvfb | |
notebook_pattern: | | |
"**/tutorial_*_dolfinx.ipynb" | |
- backend: firedrake | |
container: firedrakeproject/firedrake | |
setup_git: "" | |
setup_container: | | |
apt update -y -q | |
apt install -y -qq xvfb | |
echo "/home/firedrake/firedrake/bin" >> $GITHUB_PATH | |
notebook_pattern: | | |
"**/tutorial_*_firedrake.ipynb" | |
fail-fast: false | |
container: | |
image: ${{ matrix.container }} | |
options: --user root | |
steps: | |
- name: Setup git | |
run: ${{ matrix.setup_git }} | |
- name: Determine which branch to checkout when cloning source repository | |
id: source_branch | |
run: | | |
if [ -n "${{ (inputs || github.event.inputs).branch }}" ]; then | |
echo "branch=${{ (inputs || github.event.inputs).branch }}" >> ${GITHUB_OUTPUT} | |
else | |
echo "branch=main" >> ${GITHUB_OUTPUT} | |
fi | |
shell: bash | |
- name: Clone source repository on the previously computed branch | |
uses: actions/checkout@v4 | |
with: | |
repository: FEMlium/FEMlium | |
ref: ${{ steps.source_branch.outputs.branch }} | |
fetch-depth: 0 | |
- name: Clone website repository on current branch | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
path: _website | |
- name: Setup container | |
run: ${{ matrix.setup_container }} | |
- name: Install FEMlium | |
run: | | |
BACKEND=backend_${{ matrix.backend }} | |
python3 -m pip install .[${BACKEND},tutorials] | |
- name: Install nbconvert | |
run: | | |
python3 -m pip -q install nbconvert | |
- name: Copy jupyter template from website repository | |
run: | | |
jupyter --paths --json > /tmp/jupyter-paths | |
JUPYTER_SHARE=$(python3 -c 'import json; data = json.loads(open("/tmp/jupyter-paths", "r").read()); print(data["data"][-1])') | |
mkdir -p ${JUPYTER_SHARE}/nbconvert/templates | |
cp -rf _website/share/jupyter/nbconvert/templates/html/femlium ${JUPYTER_SHARE}/nbconvert/templates/ | |
rm /tmp/jupyter-paths | |
- name: Convert notebooks to html | |
run: | | |
NOTEBOOKS_TO_RUN=() | |
while read -r PATTERN; do | |
NOTEBOOKS_TO_RUN+=($(find tutorials -wholename $(echo ${PATTERN} | sed 's|\"||g'))) | |
done <<< $(printf "%s" "${{ matrix.notebook_pattern }}") | |
mkdir -p _converted | |
export DISPLAY=":99" | |
Xvfb $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 & | |
for NOTEBOOK in "${NOTEBOOKS_TO_RUN[@]}"; do | |
NOTEBOOK_DIRNAME=$(dirname "${NOTEBOOK}") | |
NOTEBOOK_OUTPUT_DIRNAME=${GITHUB_WORKSPACE}/_converted/${NOTEBOOK_DIRNAME} | |
NOTEBOOK_BASENAME=$(basename "${NOTEBOOK}") | |
NOTEBOOK_OUTPUT_BASENAME=${NOTEBOOK_BASENAME/.ipynb/.html} | |
pushd ${NOTEBOOK_DIRNAME} | |
VISKEX_PYVISTA_BACKEND="html" jupyter nbconvert --to html --template femlium --execute --output-dir ${NOTEBOOK_OUTPUT_DIRNAME} ${NOTEBOOK_BASENAME} | |
popd | |
pushd ${NOTEBOOK_OUTPUT_DIRNAME} | |
sed -i "s|\"https://colab.research.google.com\"|\"https://colab.research.google.com/github/FEMlium/femlium.github.io/blob/open-in-colab/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" ${NOTEBOOK_OUTPUT_BASENAME} | |
sed -i "s|\"https://kaggle.com\"|\"https://kaggle.com/kernels/welcome?src=https://github.com/FEMlium/femlium.github.io/blob/open-in-kaggle/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" ${NOTEBOOK_OUTPUT_BASENAME} | |
sed -i "s|\"https://github.com\"|\"https://github.com/FEMlium/FEMlium/blob/main/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" ${NOTEBOOK_OUTPUT_BASENAME} | |
popd | |
done | |
shell: bash | |
- name: Store converted notebooks as artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: converted-notebooks-${{ matrix.backend }} | |
path: _converted | |
retention-days: 1 | |
website: | |
runs-on: ubuntu-latest | |
needs: [convert_notebooks] | |
steps: | |
- name: Clone website repository on current branch | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Clone website repository on gh-pages branch | |
uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
fetch-depth: 0 | |
path: _build/html | |
- name: Install dependencies | |
run: | | |
pip3 -q install sphinx-material | |
- name: Download converted notebooks from artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: _converted | |
- name: Generate sphinx website | |
run: | | |
rm -rf _build/html/* | |
rsync -avh --remove-source-files _converted/converted-notebooks-*/ _build/html/ | |
rm -rf _converted | |
python3 -m sphinx -W -b html . _build/html | |
- name: Fix permissions | |
run: | | |
sudo chown $USER _build -R | |
- name: Remove unnecessary .doctrees folder | |
run: | | |
rm -rf _build/html/.doctrees | |
- name: Clean up old Github pages branch | |
if: github.repository == 'FEMlium/femlium.github.io' && github.event.inputs.reset_github_pages == 'yes' | |
run: | | |
if git ls-remote origin | grep -sw gh-pages 2>&1 >/dev/null; then git push origin --delete gh-pages; fi | |
- name: Check that no tutorials have been deleted | |
run: | | |
pushd _build/html | |
if [[ $(git ls-files --deleted tutorials | wc -l) -gt 0 ]]; then | |
echo "The following tutorials have been deleted:" | |
git ls-files --deleted tutorials | |
exit 1 | |
fi | |
popd | |
- name: Deploy to GitHub pages | |
if: github.repository == 'FEMlium/femlium.github.io' && github.ref == 'refs/heads/main' | |
run: | | |
SHA_SHORT=$(git rev-parse --short HEAD) | |
pushd _build/html | |
git config user.name "GitHub Actions" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add . | |
git pull origin gh-pages | |
[ -n "$(git status --porcelain=v1 2>/dev/null)" ] && git commit -m "deploy: ${SHA_SHORT}" | |
git push origin gh-pages | |
popd | |
shell: bash | |
- name: Deploy to GitHub artifacts | |
if: github.repository == 'FEMlium/femlium.github.io' && github.ref != 'refs/heads/main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: website | |
path: | | |
_build/html | |
!_build/html/.git | |
retention-days: 1 | |
warn: | |
runs-on: ubuntu-latest | |
if: github.repository == 'FEMlium/femlium.github.io' && github.ref == 'refs/heads/main' && github.event_name == 'schedule' | |
steps: | |
- name: Warn if scheduled workflow is about to be disabled | |
uses: fem-on-colab/warn-workflow-about-to-be-disabled-action@main | |
with: | |
workflow-filename: website.yml | |
days-elapsed: 50 |