Skip to content

Commit

Permalink
Enable PR previews (#3)
Browse files Browse the repository at this point in the history
* Enable PR previews

* Don't worry about baseurl for now

* Use a different sed separator
  • Loading branch information
mphoward authored Feb 17, 2025
1 parent cda46ec commit fed8d5d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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

0 comments on commit fed8d5d

Please sign in to comment.