-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organize github action workflow as multiple dependent jobs
- Loading branch information
1 parent
7b913b9
commit 1382a9d
Showing
1 changed file
with
42 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,43 @@ on: | |
- 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 | ||
|
@@ -42,27 +77,24 @@ jobs: | |
echo "Executing $notebook" | ||
jupyter nbconvert --to notebook --execute --allow-errors --inplace \ | ||
--output executed_notebooks/$(basename $notebook) $notebook \ | ||
2>&1 | tee -a notebook_execution.log || echo "Execution failed for $notebook" | ||
2>&1 | tee -a notebook_execution.log || exit 1 | ||
done | ||
- name: List Executed Notebooks (Debug Step) | ||
run: | | ||
echo "Listing executed notebooks:" | ||
ls -l executed_notebooks || echo "No notebooks found." | ||
# 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: 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/ || echo "No executed notebooks to copy." | ||
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 | ||
|
||
- name: Success or Failure Message | ||
if: failure() | ||
run: echo "Notebooks executed with errors, but pushed to GitHub Pages." |