Skip to content

Setup PR Preview workflow #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 14, 2023
60 changes: 60 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: PR Preview

on: [pull_request]

permissions:
pull-requests: write # allow surge-preview to create/update PR comments

jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup JupyterBook Cache
uses: actions/cache@v3
with:
path: _build
# NOTE: change key to "jupyterbook-DATE" to force rebuilding cache
key: jupyterbook-20230613

- name: Install Conda environment with Micromamba
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}
run: |
jupyter-book build ./ --warningiserror --keep-going

- name: Dump Build Logs
if: always()
run: |
if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi

- name: Publish to Surge
id: preview_step
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: _build/html
build: |
npm install surge

- name: Format preview url
id: format_url
run: |
echo "url_text=:rocket: Preview deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_OUTPUT

- name: Get the preview_url
run: echo "${{ steps.format_url.outputs.url_text }}"

- name: Generate summary
run: |
echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY