adding all missing files #35
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: Run Notebooks and Save Outputs | |
on: | |
push: | |
branches: | |
- main # Trigger the action on the main branch | |
jobs: | |
# First job: Clear outputs with nbstripout | |
clear-outputs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install nbstripout | |
run: | | |
pip install nbstripout | |
nbstripout --install | |
- name: Strip notebook outputs | |
run: | | |
find . -name "*.ipynb" -exec nbstripout --force --keep-count {} + | |
- name: Check for changes | |
run: git status | |
- name: Commit cleaned notebooks if needed | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
git add . | |
git commit -m "Auto-strip notebook outputs" || echo "No changes to commit" | |
git push || echo "Nothing to push" | |
# Second job: Run the notebooks | |
run-notebooks: | |
runs-on: ubuntu-latest | |
needs: clear-outputs # Ensure this job runs after 'clear-outputs' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Clear GitHub Action Caches | |
run: | | |
echo "Clearing caches..." | |
sudo rm -rf ~/.cache/pip | |
sudo rm -rf executed_notebooks | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Install SCT | |
run: | | |
git clone --depth 1 https://github.com/spinalcordtoolbox/spinalcordtoolbox.git | |
yes | spinalcordtoolbox/install_sct | |
# NB: install_sct edits ~/.bashrc, but those environment changes don't get passed to subsequent steps in GH Actions. | |
# So, we filter through the .bashrc and pass the values to $GITHUB_ENV and $GITHUB_PATH. | |
# Relevant documentation: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files | |
# This workaround should be replaced by https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/3198#discussion_r568225392 | |
cat ~/.bashrc | grep "export SCT_DIR" | cut -d " " -f 2 >> $GITHUB_ENV | |
cat ~/.bashrc | grep "export PATH" | grep -o "/.*" | cut -d ':' -f 1 >> $GITHUB_PATH | |
- name: Verify SCT installation | |
run: | | |
# Make sure SCT can be called from within the environment | |
sct_check_dependencies | |
- name: Run Jupyter Notebooks | |
continue-on-error: true # Allow workflow to continue even if notebook execution fails | |
run: | | |
echo $PATH | |
mkdir -p executed_notebooks | |
for notebook in $(find . -name "*.ipynb"); do | |
echo "Executing $notebook" | |
jupyter nbconvert --to notebook --execute --allow-errors --inplace \ | |
--output executed_notebooks/$(basename $notebook) $notebook \ | |
2>&1 | tee -a notebook_execution.log || exit 1 | |
done | |
- name: Check Execution Log | |
run: cat notebook_execution.log | |
- name: Upload Executed Notebooks | |
uses: actions/upload-artifact@v3 | |
with: | |
name: executed-notebooks | |
path: executed_notebooks/ | |
# Third job: Deploy to GitHub Pages (depends on run-notebooks) | |
deploy: | |
runs-on: ubuntu-latest | |
needs: run-notebooks # Ensure this job runs after 'run-notebooks' | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Download Executed Notebooks | |
uses: actions/download-artifact@v3 | |
with: | |
name: executed-notebooks | |
path: executed_notebooks/ | |
- name: Copy Executed Notebooks to Pages Directory | |
run: | | |
COMMIT_SHA=$(git rev-parse --short HEAD) | |
mkdir -p gh-pages/$COMMIT_SHA | |
cp executed_notebooks/*.ipynb gh-pages/$COMMIT_SHA/ | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: gh-pages | |
publish_branch: gh-pages |