-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
40 changes: 18 additions & 22 deletions
40
.github/workflows/preview.yaml → .github/workflows/pull_request.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,53 @@ | ||
name: PR Preview | ||
name: Pull Request Build | ||
|
||
on: [pull_request_target] | ||
|
||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened, closed] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
preview: | ||
env: | ||
PREVIEW_URL: https://{{repository.owner}}-{{repository.name}}-{{job.name}}-pr-{{pr.number}}.surge.sh | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash -el {0} | ||
steps: | ||
- name: Checkout repository | ||
if: github.event.action != 'closed' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup JupyterBook Cache | ||
if: github.event.action != 'closed' | ||
uses: actions/cache@v4 | ||
with: | ||
path: _build | ||
# NOTE: change key to "jupyterbook-DATE" to force rebuilding cache | ||
key: jupyterbook-20240517 | ||
|
||
- name: Install Conda environment with Micromamba | ||
if: github.event.action != 'closed' | ||
uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
environment-file: conda/conda-lock.yml | ||
environment-name: xarray-tutorial | ||
cache-environment: true | ||
|
||
- name: Build JupyterBook | ||
# NOTE: login shell activates conda environment | ||
shell: bash -l {0} | ||
if: github.event.action != 'closed' | ||
run: | | ||
jupyter-book build ./ --warningiserror --keep-going | ||
- name: Dump Build Logs | ||
if: always() | ||
if: github.event.action != 'closed' | ||
run: | | ||
if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi | ||
- name: Install Surge.sh | ||
uses: actions/setup-node@v4 | ||
|
||
- run: npm install -g surge | ||
|
||
- run: surge ./_build/html {{env.PREVIEW_URL}} --token $SURGE_TOKEN | ||
env: | ||
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} | ||
|
||
- name: Add URL to Summary | ||
run: | | ||
echo "#### :rocket: Preview deployed at {{env.PREVIEW_URL}}" >> $GITHUB_STEP_SUMMARY | ||
- name: Upload artifact | ||
if: github.event.action != 'closed' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: html | ||
path: book/_build/html |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Pull Request Preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Pull Request Build"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.workflow_run.id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# NOTE: match job name in pull_request.yaml | ||
preview: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | ||
|
||
steps: | ||
# Ensure folder exists for PR 'closed' case | ||
- run: mkdir html | ||
|
||
# Download built HTML from PR Build workflow | ||
- uses: actions/download-artifact@v4 | ||
continue-on-error: true | ||
with: | ||
github-token: ${{ github.token }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
|
||
- name: Manage Surge.sh Deployment | ||
id: preview_step | ||
uses: afc163/surge-preview@v1 | ||
with: | ||
surge_token: ${{ secrets.SURGE_TOKEN }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
build: echo 'Uploading html/ folder contents to Surge.sh...' | ||
dist: html # NOTE: match upload_artifact name in pull_request.yaml | ||
failOnError: true | ||
teardown: true |