name: Deploy TinyTorch Jupyter Book # Trigger the workflow on push to main branch (publishing) or manual dispatch on: push: branches: [ main ] paths: - 'book/**' - 'modules/source/**' - '.github/workflows/deploy-book.yml' pull_request: branches: [ main ] paths: - 'book/**' - 'modules/source/**' workflow_dispatch: # Set permissions for GitHub Pages deployment and content modification permissions: contents: write pages: write id-token: write # Allow only one concurrent deployment concurrency: group: "pages" cancel-in-progress: false jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.11' cache: 'pip' - name: Install dependencies run: | pip install --upgrade pip pip install jupyter-book jupytext pip install -r book/requirements.txt - name: Generate notebooks for Binder/Colab run: | python book/convert_modules.py --all - name: Commit generated notebooks run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add modules/source/**/*.ipynb if ! git diff --cached --quiet; then git commit -m "Auto-generate notebooks for Binder/Colab access [skip ci]" git push fi - name: Generate overview pages for book run: | python book/convert_modules.py --overview - name: Build the book run: | cd book jupyter-book build . --all - name: Upload book artifact uses: actions/upload-pages-artifact@v3 with: path: book/_build/html deploy: # Only deploy on main branch pushes (not PRs) if: github.ref == 'refs/heads/main' && github.event_name == 'push' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4