Migrate GH Pages deploy to artifact-based deployment (#783) #87
Workflow file for this run
This file contains hidden or 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: Build & Publish to GH Pages | |
| on: | |
| push: | |
| tags: | |
| - 'publish*' | |
| permissions: | |
| contents: write # upload release assets; Netlify commit comment | |
| actions: read # dawidd6 download-artifact reads cache.yml's build-cache | |
| statuses: write # Netlify commit status | |
| pages: write # deploy to GitHub Pages | |
| id-token: write # OIDC token for actions/deploy-pages | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Anaconda | |
| uses: conda-incubator/setup-miniconda@v4 | |
| with: | |
| auto-update-conda: true | |
| auto-activate-base: true | |
| miniconda-version: 'latest' | |
| python-version: "3.13" | |
| environment-file: environment.yml | |
| activate-environment: quantecon | |
| - name: Install latex dependencies | |
| run: | | |
| sudo apt-get -qq update | |
| sudo apt-get install -y \ | |
| texlive-latex-recommended \ | |
| texlive-latex-extra \ | |
| texlive-fonts-recommended \ | |
| texlive-fonts-extra \ | |
| texlive-xetex \ | |
| latexmk \ | |
| xindy \ | |
| dvipng \ | |
| cm-super | |
| - name: Display Conda Environment Versions | |
| shell: bash -l {0} | |
| run: conda list | |
| - name: Display Pip Versions | |
| shell: bash -l {0} | |
| run: pip list | |
| - name: Download "build" folder (cache) | |
| uses: dawidd6/action-download-artifact@v21 | |
| with: | |
| workflow: cache.yml | |
| branch: main | |
| name: build-cache | |
| path: _build | |
| # Build Assets (Download Notebooks and PDF via LaTeX) | |
| - name: Build PDF from LaTeX | |
| shell: bash -l {0} | |
| run: | | |
| jb build lectures --builder pdflatex --path-output ./ -n --keep-going | |
| - name: Copy LaTeX PDF for GH-PAGES | |
| shell: bash -l {0} | |
| run: | | |
| mkdir -p _build/html/_pdf | |
| cp -u _build/latex/*.pdf _build/html/_pdf | |
| - name: Build Download Notebooks (sphinx-tojupyter) | |
| shell: bash -l {0} | |
| run: | | |
| jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter | |
| - name: Copy Download Notebooks for GH-PAGES | |
| shell: bash -l {0} | |
| run: | | |
| mkdir -p _build/html/_notebooks | |
| cp -u _build/jupyter/*.ipynb _build/html/_notebooks | |
| # Build HTML (Website) | |
| # BUG: rm .doctress to remove `sphinx` rendering issues for ipywidget mimetypes | |
| # and clear the sphinx cache for building final HTML documents. | |
| - name: Build HTML | |
| shell: bash -l {0} | |
| run: | | |
| rm -r _build/.doctrees | |
| jb build lectures --path-output ./ | |
| # Create HTML archive for release assets | |
| - name: Create HTML archive | |
| shell: bash -l {0} | |
| run: | | |
| tar -czf lecture-python-intro-html-${{ github.ref_name }}.tar.gz -C _build/html . | |
| sha256sum lecture-python-intro-html-${{ github.ref_name }}.tar.gz > html-checksum.txt | |
| # Create metadata manifest | |
| cat > html-manifest.json << EOF | |
| { | |
| "tag": "${{ github.ref_name }}", | |
| "commit": "${{ github.sha }}", | |
| "timestamp": "$(date -Iseconds)", | |
| "size_mb": $(du -sm _build/html | cut -f1), | |
| "file_count": $(find _build/html -type f | wc -l) | |
| } | |
| EOF | |
| - name: Upload archives to release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| files: | | |
| lecture-python-intro-html-${{ github.ref_name }}.tar.gz | |
| html-checksum.txt | |
| html-manifest.json | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Deploy to Netlify | |
| uses: nwtgck/actions-netlify@v4.0 | |
| with: | |
| publish-dir: '_build/html/' | |
| production-branch: main | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy-message: "Deploy from GitHub Actions" | |
| env: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
| - name: Add CNAME for custom domain | |
| run: echo "intro.quantecon.org" > _build/html/CNAME | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v6 | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v5 | |
| with: | |
| path: _build/html/ | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v5 | |
| - name: Upload "_build" folder (cache) | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: build-publish | |
| path: _build | |
| # Sync notebooks | |
| - name: Prepare lecture-python-intro.notebooks sync | |
| shell: bash -l {0} | |
| run: | | |
| mkdir -p _build/lecture-python-intro.notebooks | |
| cp -a _notebook_repo/. _build/lecture-python-intro.notebooks | |
| cp _build/jupyter/*.ipynb _build/lecture-python-intro.notebooks | |
| ls -a _build/lecture-python-intro.notebooks | |
| - name: Commit latest notebooks to lecture-python-intro.notebooks | |
| uses: cpina/github-action-push-to-another-repository@main | |
| env: | |
| API_TOKEN_GITHUB: ${{ secrets.QUANTECON_SERVICES_PAT }} | |
| with: | |
| source-directory: '_build/lecture-python-intro.notebooks/' | |
| destination-repository-username: 'QuantEcon' | |
| destination-repository-name: 'lecture-python-intro.notebooks' | |
| commit-message: 'auto publishing updates to notebooks' | |
| destination-github-username: 'quantecon-services' | |
| user-email: services@quantecon.org |