|
| 1 | +name: Build & Publish to GH-PAGES |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - 'publish*' |
| 6 | +jobs: |
| 7 | + publish: |
| 8 | + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout |
| 12 | + uses: actions/checkout@v5 |
| 13 | + - name: Setup Anaconda |
| 14 | + uses: conda-incubator/setup-miniconda@v3 |
| 15 | + with: |
| 16 | + auto-update-conda: true |
| 17 | + auto-activate-base: true |
| 18 | + miniconda-version: 'latest' |
| 19 | + python-version: "3.13" |
| 20 | + environment-file: environment.yml |
| 21 | + activate-environment: quantecon |
| 22 | + - name: Install latex dependencies |
| 23 | + run: | |
| 24 | + sudo apt-get -qq update |
| 25 | + sudo apt-get install -y \ |
| 26 | + texlive-latex-recommended \ |
| 27 | + texlive-latex-extra \ |
| 28 | + texlive-fonts-recommended \ |
| 29 | + texlive-fonts-extra \ |
| 30 | + texlive-xetex \ |
| 31 | + latexmk \ |
| 32 | + xindy \ |
| 33 | + dvipng \ |
| 34 | + cm-super |
| 35 | + - name: Display Conda Environment Versions |
| 36 | + shell: bash -l {0} |
| 37 | + run: conda list |
| 38 | + - name: Display Pip Versions |
| 39 | + shell: bash -l {0} |
| 40 | + run: pip list |
| 41 | + - name: Download "build" folder (cache) |
| 42 | + uses: dawidd6/action-download-artifact@v11 |
| 43 | + with: |
| 44 | + workflow: cache.yml |
| 45 | + branch: main |
| 46 | + name: build-cache |
| 47 | + path: _build |
| 48 | + # Build Assets (Download Notebooks and PDF via LaTeX) |
| 49 | + - name: Build PDF from LaTeX |
| 50 | + shell: bash -l {0} |
| 51 | + run: | |
| 52 | + jb build lectures --builder pdflatex --path-output ./ -n --keep-going |
| 53 | + - name: Copy LaTeX PDF for GH-PAGES |
| 54 | + shell: bash -l {0} |
| 55 | + run: | |
| 56 | + mkdir -p _build/html/_pdf |
| 57 | + cp -u _build/latex/*.pdf _build/html/_pdf |
| 58 | + - name: Build Download Notebooks (sphinx-tojupyter) |
| 59 | + shell: bash -l {0} |
| 60 | + run: | |
| 61 | + jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter |
| 62 | + - name: Copy Download Notebooks for GH-PAGES |
| 63 | + shell: bash -l {0} |
| 64 | + run: | |
| 65 | + mkdir -p _build/html/_notebooks |
| 66 | + cp -u _build/jupyter/*.ipynb _build/html/_notebooks |
| 67 | + # Build HTML (Website) |
| 68 | + # BUG: rm .doctress to remove `sphinx` rendering issues for ipywidget mimetypes |
| 69 | + # and clear the sphinx cache for building final HTML documents. |
| 70 | + - name: Build HTML |
| 71 | + shell: bash -l {0} |
| 72 | + run: | |
| 73 | + rm -r _build/.doctrees |
| 74 | + jb build lectures --path-output ./ |
| 75 | + # Create HTML archive for release assets |
| 76 | + - name: Create HTML archive |
| 77 | + shell: bash -l {0} |
| 78 | + run: | |
| 79 | + tar -czf lecture-python-intro-html-${{ github.ref_name }}.tar.gz -C _build/html . |
| 80 | + sha256sum lecture-python-intro-html-${{ github.ref_name }}.tar.gz > html-checksum.txt |
| 81 | +
|
| 82 | + # Create metadata manifest |
| 83 | + cat > html-manifest.json << EOF |
| 84 | + { |
| 85 | + "tag": "${{ github.ref_name }}", |
| 86 | + "commit": "${{ github.sha }}", |
| 87 | + "timestamp": "$(date -Iseconds)", |
| 88 | + "size_mb": $(du -sm _build/html | cut -f1), |
| 89 | + "file_count": $(find _build/html -type f | wc -l) |
| 90 | + } |
| 91 | + EOF |
| 92 | + - name: Upload archives to release |
| 93 | + uses: softprops/action-gh-release@v1 |
| 94 | + with: |
| 95 | + files: | |
| 96 | + lecture-python-intro-html-${{ github.ref_name }}.tar.gz |
| 97 | + html-checksum.txt |
| 98 | + html-manifest.json |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + - name: Deploy to Netlify |
| 102 | + uses: nwtgck/actions-netlify@v3.0 |
| 103 | + with: |
| 104 | + publish-dir: '_build/html/' |
| 105 | + production-branch: main |
| 106 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + deploy-message: "Deploy from GitHub Actions" |
| 108 | + env: |
| 109 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 110 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 111 | + - name: Deploy website to gh-pages |
| 112 | + uses: peaceiris/actions-gh-pages@v4 |
| 113 | + with: |
| 114 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + publish_dir: _build/html/ |
| 116 | + cname: intro.quantecon.org |
| 117 | + - name: Upload "_build" folder (cache) |
| 118 | + uses: actions/upload-artifact@v5 |
| 119 | + with: |
| 120 | + name: build-publish |
| 121 | + path: _build |
| 122 | + # Sync notebooks |
| 123 | + - name: Prepare lecture-python-intro.notebooks sync |
| 124 | + shell: bash -l {0} |
| 125 | + run: | |
| 126 | + mkdir -p _build/lecture-python-intro.notebooks |
| 127 | + cp -a _notebook_repo/. _build/lecture-python-intro.notebooks |
| 128 | + cp _build/jupyter/*.ipynb _build/lecture-python-intro.notebooks |
| 129 | + ls -a _build/lecture-python-intro.notebooks |
| 130 | + - name: Commit latest notebooks to lecture-python-intro.notebooks |
| 131 | + uses: cpina/github-action-push-to-another-repository@main |
| 132 | + env: |
| 133 | + API_TOKEN_GITHUB: ${{ secrets.QUANTECON_SERVICES_PAT }} |
| 134 | + with: |
| 135 | + source-directory: '_build/lecture-python-intro.notebooks/' |
| 136 | + destination-repository-username: 'QuantEcon' |
| 137 | + destination-repository-name: 'lecture-python-intro.notebooks' |
| 138 | + commit-message: 'auto publishing updates to notebooks' |
| 139 | + destination-github-username: 'quantecon-services' |
| 140 | + user-email: services@quantecon.org |
0 commit comments