Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiristseng committed Dec 8, 2023
1 parent 3d35147 commit 6afe499
Showing 1 changed file with 20 additions and 134 deletions.
154 changes: 20 additions & 134 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ concurrency:
cancel-in-progress: true

env:
NJOBS: '4'
TIMEOUT: '-1' # nbconvert timeout
EXTRA_ARGS: '' # Extra arguments for nbconvert
CACHE_NUM: '1'
Expand All @@ -21,11 +22,8 @@ env:
PY_VER: '3.12'

jobs:
setup:
CI:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
hash: ${{ steps.cache-julia.outputs.cache-primary-key }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -76,140 +74,28 @@ jobs:
~/.julia
!~/.julia/registries
key: ${{ steps.cache-julia.outputs.cache-primary-key }}
- name: List notebooks as a JSON array
id: set-matrix
working-directory: docs
run: echo "matrix=$(python -c 'import glob, json; print(json.dumps(glob.glob("**/*.ipynb", recursive=True)))')" >> "$GITHUB_OUTPUT"

execute:
needs: setup
strategy:
max-parallel: 20
fail-fast: false
matrix:
# Notebooks need to be executed
notebook: ${{ fromJSON(needs.setup.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Restore notebook if present
uses: actions/cache/restore@v3
id: cache
with:
path: docs/${{ matrix.notebook }}
key: ${{ runner.os }}-notebook-${{ hashFiles(format('docs/{0}', matrix.notebook)) }}-${{ needs.setup.outputs.hash }}
- name: Setup Python
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
- name: Cache pip
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
- name: Read Julia version
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: SebRollen/[email protected]
id: read_toml
with:
file: 'Manifest.toml'
field: 'julia_version'
- name: Install Julia using jill.sh
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: |
wget -O /tmp/jill.sh https://raw.githubusercontent.com/abelsiqueira/jill/main/jill.sh
bash /tmp/jill.sh --version ${{ steps.read_toml.outputs.value }} -y
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Restore Julia packages
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: actions/cache/restore@v3
with:
path: |
~/.julia
!~/.julia/registries
key: ${{ needs.setup.outputs.hash }}
- name: Install Julia kernel
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: |
julia --color=yes -e 'using IJulia; IJulia.installkernel("Julia", "--project=@.")'
- name: Execute Notebook
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: >
jupyter nbconvert --to notebook --execute --inplace ${{ env.EXTRA_ARGS }}
--ExecutePreprocessor.timeout=${{ env.TIMEOUT }}
--ExecutePreprocessor.kernel_name=julia-1.$(julia -e 'print(VERSION.minor)')
docs/${{ matrix.notebook }}
- name: Cache notebook
uses: actions/cache/save@v3
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
with:
path: docs/${{ matrix.notebook }}
key: ${{ steps.cache.outputs.cache-primary-key }}
- name: Upload Notebook
uses: actions/upload-artifact@v3
with:
name: notebooks
path: docs*/${{ matrix.notebook }} # keep folder structure
retention-days: 1

render:
needs: execute
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download notebooks
uses: actions/download-artifact@v3
with:
name: notebooks
path: out/
- name: Display structure of downloaded files
run: ls -R
working-directory: out
- name: Copy back built notebooks
run: cp --verbose -rf out/docs/* docs/
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
- name: Cache pip
uses: actions/cache@v3
id: cache-pip
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
- name: Build website
run: jupyter-book build docs/
- name: Upload pages artifact
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/upload-pages-artifact@v2
with:
path: docs/_build/html/

# CI conclusion for GitHub status check
# Adaped from https://brunoscheufler.com/blog/2022-04-09-the-required-github-status-check-that-wasnt
CI:
needs: render
if: always()
runs-on: ubuntu-latest
steps:
- run: |
if [[ ${{ needs.render.result }} == "success" ]]; then
echo "Tests passed"
exit 0
else
echo "Tests failed"
exit 1
fi
- name: Install IJulia kernel
run: julia --color=yes -e 'using IJulia; installkernel("Julia", "--project=@.")'
- name: Execute Notebook
run: >
parallel --joblog /tmp/log -j${NJOBS} jupyter nbconvert --to notebook --execute --inplace ${{ env.EXTRA_ARGS }}
--ExecutePreprocessor.timeout=${{ env.TIMEOUT }}
--ExecutePreprocessor.kernel_name=julia-1.$(julia -e 'print(VERSION.minor)')
{} ::: docs/*.ipynb
- name: Show execution stats
run: cat /tmp/log
- name: Build website
run: jupyter-book build docs/
- name: Upload pages artifact
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/upload-pages-artifact@v2
with:
path: docs/_build/html/

# Deployment job
deploy:
name: Deploy to GitHub pages
needs: render
needs: CI
if: ${{ github.ref == 'refs/heads/main' }}
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
Expand Down

0 comments on commit 6afe499

Please sign in to comment.