new exercise notebooks #39
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: Jupyter book | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: true | |
matrix: | |
include: | |
- os: ubuntu-24.04 | |
python-version: '3.12' | |
- os: macos-15 | |
python-version: '3.12' | |
name: build / ${{ matrix.os }} / python${{ matrix.python-version }} | |
env: | |
FC: gfortran-14 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'pip' | |
cache-dependency-path: requirements.txt | |
- name: Install non-Python dependencies on Ubuntu | |
if: startsWith(matrix.os, 'ubuntu') | |
uses: awalsh128/cache-apt-pkgs-action@latest | |
with: | |
packages: gfortran openmpi-bin libopenmpi-dev libhdf5-openmpi-dev | |
version: 1.0 | |
execute_install_scripts: true | |
# When loading cached apt packages, the default MPI compiler isn't set. | |
# Workaround is to 'reinstall' openmpi-bin, which doesn't actually perform | |
# installation (since openmpi-bin already exists), but instead reruns | |
# `update-alternatives` which fixes the symlinks to mpicc/mpif90. | |
- name: Reconfigure non-Python dependencies on Ubuntu | |
if: startsWith(matrix.os, 'ubuntu') | |
run: | | |
sudo apt-get update | |
sudo apt-get install --reinstall openmpi-bin libhdf5-openmpi-dev | |
- name: Install non-Python dependencies on macOS | |
if: startsWith(matrix.os, 'macos') | |
run: | | |
brew install open-mpi hdf5-mpi libomp | |
- name: Check gfortran version | |
run: | | |
if [[ "${{ matrix.os }}" == *"macos"* ]]; then | |
# pyccel searches for a Fortran compiler exactly named 'gfortran' | |
# which the macos runner doesn't have. A simple workaround is to | |
# create a symlink named 'gfortran'. | |
FC_path=$(which $FC) | |
FC_dir=$(dirname ${FC_path}) | |
ln -sv ${FC_path} ${FC_dir}/gfortran | |
fi | |
gfortran --version | |
- name: Install Jupyter Book and Psydac | |
run: | | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Get list of changed Python notebooks | |
id: changed-ipynb-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
**.ipynb | |
- name: Check for dirty Python notebooks | |
if: steps.changed-ipynb-files.outputs.any_changed == 'true' | |
env: | |
ALL_CHANGED_FILES: ${{ steps.changed-ipynb-files.outputs.all_changed_files }} | |
run: | | |
# Check if there are dirty notebooks | |
dirty_ipynb=() | |
for file in ${ALL_CHANGED_FILES[*]}; do | |
echo "Checking $file..." | |
if ! nb-clean check $file >/dev/null 2>&1; then | |
dirty_ipynb+=($file) | |
fi | |
done | |
# Trigger failure if dirty notebooks were found | |
if [[ ! -z "${dirty_ipynb[@]}" ]]; then | |
echo "ERROR: Found dirty Python notebooks. Please clean the notebooks by running" | |
echo "" | |
echo "nb-clean clean --remove-empty-cells --remove-all-notebook-metadata ${dirty_ipynb[*]}" | |
echo "" | |
exit 1 | |
else | |
echo "SUCCESS: All changed notebooks are clean." | |
fi | |
- name: Build Jupyter Book | |
run: make docs | |
- name: Upload artifact | |
id: deployment | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: _build/html | |
name: github-pages_${{ matrix.os }}_python${{ matrix.python-version }} | |
deploy: | |
if: github.event_name != 'pull_request' | |
needs: build | |
runs-on: ubuntu-24.04 | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
with: | |
artifact_name: github-pages_ubuntu-24.04_python3.12 |