Manual Full Archive Execute-Store-Generate HTML #10
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: Manual Execute and Merge Notebooks | |
on: [workflow_dispatch] | |
jobs: | |
find_notebooks: | |
runs-on: ubuntu-latest | |
outputs: | |
notebook_list: ${{ steps.find.outputs.notebook_list }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Find notebook files | |
id: find | |
run: | | |
notebook_files=$(find notebooks -name "*.ipynb" | jq -R -s -c 'split("\n")[:-1]') | |
#echo "::set-output name=notebook_list::$notebook_files" | |
echo "notebook_list=$notebook_files" >>$GITHUB_OUTPUT | |
execute_notebooks: | |
needs: find_notebooks | |
runs-on: ubuntu-latest | |
outputs: | |
executed_notebooks: ${{ steps.execute.outputs.executed_notebooks }} | |
strategy: | |
fail-fast: false | |
matrix: | |
notebook: ${{fromJson(needs.find_notebooks.outputs.notebook_list)}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
export PYDEVD_DISABLE_FILE_VALIDATION=1 | |
python -m pip install --upgrade pip | |
pip install -r pre-requirements.txt | |
pip install -r requirements.txt | |
pip install pytest | |
pip install nbval | |
pip install nbconvert | |
- name: Execute notebook | |
id: execute | |
run: | | |
if [ "${{ matrix.notebook }}" != "notebooks/preimaging/preimaging_01_mirage.ipynb" ]; then | |
if ! jupyter nbconvert --to notebook --execute --inplace ${{ matrix.notebook }}; then | |
python .github/scripts/insert_failure_message.py ${{ matrix.notebook }} | |
fi | |
fi | |
- name: Archive executed notebooks | |
run: | | |
if [ "${{ matrix.notebook }}" != "notebooks/preimaging/preimaging_01_mirage.ipynb" ]; then | |
git config pull.rebase false | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git checkout -b gh-storage | |
git add ${{ matrix.notebook }} | |
git commit -m 'Added executed notebook ${{ matrix.notebook }}' | |
ATTEMPTS_LEFT=3 | |
until [ $ATTEMPTS_LEFT -lt 1 ] | |
do | |
git pull origin gh-storage -s recursive -X ours --allow-unrelated-histories | |
git push origin gh-storage 2>&1 | tee output.log | |
if grep -q "Updates were rejected because the remote contains work" output.log; then | |
echo "Push failed due to conflicting remote changes. Remaining attempts: $ATTEMPTS_LEFT" | |
let "ATTEMPTS_LEFT--" | |
sleep 5 | |
else | |
break | |
fi | |
done | |
fi | |
generate_html: | |
needs: execute_notebooks | |
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.x' | |
- name: Install dependencies | |
run: | | |
pip install jupyter-book | |
- name: Build HTML | |
run: | | |
git fetch | |
git checkout origin/gh-storage -- notebooks/ | |
jupyter-book build . | |
#- name: Execute JDAVIZ placeholder substitution | |
# run: | | |
# cp jdaviz_placeholder_new.png _build/html | |
# ./placeholder.sh | |
# Push the book's HTML to github-pages | |
- name: GitHub Pages action | |
uses: peaceiris/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./_build/html |