Skip to content

Merge branch 'main' of github.com:Systemik-Solutions/Glycerine_API #73

Merge branch 'main' of github.com:Systemik-Solutions/Glycerine_API

Merge branch 'main' of github.com:Systemik-Solutions/Glycerine_API #73

Workflow file for this run

name: Build and Deploy Jupyter Book
on:
push:
paths:
- 'Markdowns/**.md'
- 'Markdowns/**.ipynb'
- 'FrontPage/*.md'
- '!JupyterBook/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install Jupyter Book and dependencies
run: |
python -m pip install --upgrade pip
# Check if jupyter-book is installed
if ! command -v jupyter-book &> /dev/null; then
pip install jupyter-book
fi
- name: Install Dependencies from requirements.txt
run: |
pip install -r .github/workflows/requirements.txt
- name: Prepare files for Jupyter Book, Clean old build
run: |
rm -rf JupyterBook/_build
rm -f JupyterBook/*.md
rm -f JupyterBook/*.ipynb
rm -f JupyterBook/_toc.yml
cp FrontPage/intro.md JupyterBook/
rsync -av --include='*.md' --include='*.ipynb' --include='*/' --exclude='*' Markdowns/ JupyterBook/
- name: Generate TOC
run: |
echo "format: jb-book" > JupyterBook/_toc.yml
echo "root: intro" >> JupyterBook/_toc.yml
echo "parts:" >> JupyterBook/_toc.yml
# Loop through each folder in /Markdowns
for dir in Markdowns/*; do
if [ -d "$dir" ]; then
heading=$(basename -- "$dir")
echo " - caption: $heading" >> JupyterBook/_toc.yml
echo " chapters:" >> JupyterBook/_toc.yml
# Check for nested directories with overview.md
for sub_dir in "$dir"/*; do
if [ -d "$sub_dir" ] && [ -f "$sub_dir/overview.md" ]; then
sub_heading=$(basename -- "$sub_dir")
echo " - file: $heading/$sub_heading/overview" >> JupyterBook/_toc.yml
echo " sections:" >> JupyterBook/_toc.yml
# Loop through other markdown files in the sub-directory excluding overview.md
for file in "$sub_dir"/*.{md,ipynb}; do
if [[ "$file" != "$sub_dir/overview.md" ]]; then
baseName=$(basename -- "$file")
noExtName="${baseName%.*}"
echo " - file: $heading/$sub_heading/$noExtName" >> JupyterBook/_toc.yml
fi
done
fi
done
# Add markdown files from the first directory layer
for file in "$dir"/*.{md,ipynb}; do
baseName=$(basename -- "$file")
noExtName="${baseName%.*}"
echo " - file: $heading/$noExtName" >> JupyterBook/_toc.yml
done
fi
done
- name: Check JupyterBook file structure
run: |
echo "Checking the file structure in JupyterBook:"
if command -v tree &> /dev/null; then
tree JupyterBook
else
echo "The 'tree' command isn't available. Using 'find' instead."
find JupyterBook -print
fi
- name: Print TOC for Debugging
run: |
echo "Content of _toc.yml:"
cat JupyterBook/_toc.yml
# Build the Jupyter Book
- name: Build Jupyter Book
run: |
jupyter-book build JupyterBook
# Commit and push changes if any exist
- name: Commit and push changes
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add .
git commit -m "Automated updates from GitHub Actions"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_GITHUB_TOKEN }}
branch: ${{ github.main }}
# Deploy to GitHub Pages (push to the gh-pages branch)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.MY_GITHUB_TOKEN }}
publish_dir: ./JupyterBook/_build/html
publish_branch: gh-pages