diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 0000000..f6d7a68 --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,61 @@ +name: deploy-book-preview + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - closed + +concurrency: preview-${{ github.ref }} + +permissions: + contents: write + pull-requests: write + +jobs: + deploy: + runs-on: ubuntu-latest + + concurrency: pages-main + + steps: + - name: Checkout book + uses: actions/checkout@v4 + + - name: Setup Python 3.12 + if: github.event.action != 'closed' + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Install dependencies + if: github.event.action != 'closed' + run: | + pip install -r requirements.txt + + - name: Get GitHub Pages URL + id: pages + if: github.event.action != 'closed' + uses: actions/configure-pages@v4 + + - name: Replace base URL + if: github.event.action != 'closed' + run: | + sed -i 's~baseurl: ""~baseurl: "${{ steps.pages.outputs.base_url }}/preview/pr-${{ github.event.number }}"~g' _config.yml + + - name: Build book + if: github.event.action != 'closed' + run: | + jupyter-book build . + + - name: Disable Jekyll to serve static HTML + run: | + touch _build/html/.nojekyll + + - name: Commit preview to Pages branch + uses: rossjrw/pr-preview-action@v1.4.7 + with: + source-dir: "_build/html" + umbrella-dir: preview diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b18ee4c..3273316 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,11 +28,12 @@ jobs: pip install -r requirements.txt - name: Get GitHub Pages URL + id: pages uses: actions/configure-pages@v4 - name: Replace base URL run: | - sed -i 's/baseurl: ""/baseurl: "${{ steps.pages.outputs.base_url }}"/g' _config.yml + sed -i 's~baseurl: ""~baseurl: "${{ steps.pages.outputs.base_url }}"~g' _config.yml - name: Build book run: | @@ -45,4 +46,6 @@ jobs: - name: Deploy book to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4 with: + clean-exclude: preview folder: "_build/html" + force: false