From f64ff4a7a36102303de6cd9fb4575c31c5108bb9 Mon Sep 17 00:00:00 2001 From: Michael Howard Date: Sun, 16 Feb 2025 22:38:29 -0600 Subject: [PATCH 1/3] Enable PR previews --- .github/workflows/deploy-preview.yml | 61 ++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 3 ++ 2 files changed, 64 insertions(+) create mode 100644 .github/workflows/deploy-preview.yml diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 000000000..54358814b --- /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 b18ee4c33..f63b3d772 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,7 @@ jobs: pip install -r requirements.txt - name: Get GitHub Pages URL + id: pages uses: actions/configure-pages@v4 - name: Replace base URL @@ -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 From 9aa403a01d2d44e8d96b670ff1b7eb9aec3b3753 Mon Sep 17 00:00:00 2001 From: Michael Howard Date: Sun, 16 Feb 2025 22:41:03 -0600 Subject: [PATCH 2/3] Don't worry about baseurl for now --- .github/workflows/deploy-preview.yml | 10 ---------- .github/workflows/deploy.yml | 8 -------- 2 files changed, 18 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 54358814b..6dc3d97a5 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -35,16 +35,6 @@ jobs: 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: | diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f63b3d772..afa8a9a55 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,14 +27,6 @@ jobs: run: | 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 - - name: Build book run: | jupyter-book build . From c8475bf208f76443209b76974d1363eced238f21 Mon Sep 17 00:00:00 2001 From: Michael Howard Date: Sun, 16 Feb 2025 22:43:59 -0600 Subject: [PATCH 3/3] Use a different sed separator --- .github/workflows/deploy-preview.yml | 10 ++++++++++ .github/workflows/deploy.yml | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 6dc3d97a5..f6d7a6872 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -35,6 +35,16 @@ jobs: 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: | diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index afa8a9a55..327331632 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,6 +27,14 @@ jobs: run: | 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 + - name: Build book run: | jupyter-book build .