test_changed_notebooks #82
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
# This workflows executes new or modified example notebooks. | |
name: test_changed_notebooks | |
defaults: | |
run: | |
shell: bash # To override PowerShell on Windows | |
on: | |
# Trigger the workflow on push or PR to any branch | |
push: | |
paths: | |
- '**/*.ipynb' | |
pull_request: | |
paths: | |
- '**/*.ipynb' | |
# don't trigger for draft PRs | |
types: [ opened, synchronize, reopened, ready_for_review ] | |
# Trigger the workflow on manual dispatch | |
workflow_dispatch: | |
jobs: | |
select-runner: | |
runs-on: ubuntu-22.04 | |
outputs: | |
runner: ${{ steps.select_runner.outputs.runner }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Select runner | |
id: select_runner | |
run: | | |
if [ "${{ github.repository }}" = "NeuroDesk/example-notebooks" ]; then | |
echo "runner=cirun-oracle--${{ github.run_id }}" >> $GITHUB_OUTPUT | |
else | |
echo "runner=ubuntu-22.04" >> $GITHUB_OUTPUT | |
fi | |
test-notebooks: | |
needs: select-runner | |
runs-on: ${{ needs.select-runner.outputs.runner }} | |
strategy: | |
fail-fast: false | |
matrix: | |
notebooks: ["structural_imaging/nipype_module_example.ipynb"] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Test singularity and cvmfs before pushing to neurocommand | |
run: | |
/bin/bash .github/workflows/setup_cvmfs.sh | |
- name: Install dependencies | |
shell: bash | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install jupyter-book ghp-import graphviz ipyniivue | |
- name: Run ${{ matrix.notebooks }} | |
shell: bash | |
working-directory: ./books | |
run: | | |
echo ${{ github.workspace }} | |
echo $GITHUB_WORKSPACE | |
export PATH=$HOME/.local/bin:$PATH | |
echo "PATH=$PATH" | |
export LD_PRELOAD= | |
echo "LD_PRELOAD=$LD_PRELOAD" | |
export APPTAINER_BINDPATH=${{ github.workspace }},/cvmfs | |
echo "APPTAINER_BINDPATH=$APPTAINER_BINDPATH" | |
export LMOD_CMD=/usr/share/lmod/lmod/libexec/lmod | |
export MPLCONFIGDIR=${{ github.workspace }}/matplotlib-mpldir | |
export MODULEPATH=$(find /cvmfs/neurodesk.ardc.edu.au/neurodesk-modules/ -maxdepth 1 -mindepth 1 -type d -exec realpath {} \; | tr '\n' ':') | |
echo "MODULEPATH=$MODULEPATH" | |
sed -i 's/timeout:.*/timeout: 200/' _config.yml | |
echo "NOTEBOOK=$(basename -s .ipynb ${{ matrix.notebooks }})" >> $GITHUB_ENV | |
echo "DIRNAME=$(dirname ${{ matrix.notebooks }})" >> $GITHUB_ENV | |
jb build ${{ matrix.notebooks }} | |
- name: Restructure | |
shell: bash | |
run: | | |
tree ./books/_build/**/**/html | |
mkdir -p ./books/_build/**/**/html/$DIRNAME | |
cp -R ./books/_build/**/**/html/_static ./books/_build/**/**/html/$DIRNAME | |
if [ -d ./books/_build/**/**/html/_images ]; then | |
cp -R ./books/_build/**/**/html/_images ./books/_build/**/**/html/$DIRNAME | |
fi | |
cp ./books/_build/**/**/html/$NOTEBOOK.html ./books/_build/**/**/html/$DIRNAME | |
- name: Push to GitHub Pages | |
uses: peaceiris/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./books/_build/**/**/html | |
keep_files: true | |
cname: www.neurodesk.org | |
build-structure: | |
needs: [ select-runner, test-notebooks ] | |
runs-on: ${{ needs.select-runner.outputs.runner }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install dependencies | |
shell: bash | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install jupyter-book ghp-import graphviz ipyniivue | |
- name: Run all | |
shell: bash | |
working-directory: ./books | |
run: | | |
export PATH=$HOME/.local/bin:$PATH | |
sed -i 's/timeout:.*/timeout: 1/' _config.yml | |
jb build . | |
- name: Ignore changes | |
shell: bash | |
run: | | |
git diff gh-pages main >./my_config.patch | |
cat ./my_config.patch | |
echo "git diff any line that does not start with space and does not start with <div or contains action" | |
git diff -w -G'(^<([^d]|d($|[^i]|i($|[^v]|v[^>]))|[^>]).*)|(\baction\b)'>./my_config.patch | |
echo "check changes" | |
cat ./my_config.patch | |
echo "git apply patch" | |
git apply --check --ignore-space-change --ignore-whitespace --reject ./my_config.patch | |
- name: Push to GitHub Pages | |
uses: peaceiris/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./books/_build/html | |
keep_files: true | |
cname: www.neurodesk.org |