Merge pull request #132 from brian-rose/dependabot/github_actions/daw… #95
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
name: deploy-book | |
# Only run this when the main branch changes | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-and-deploy-book: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
if: github.repository == 'brian-rose/ClimateLaboratoryBook' | |
steps: | |
- name: Cancel previous runs | |
uses: styfle/cancel-workflow-action@0.12.1 | |
with: | |
access_token: ${{ github.token }} | |
- uses: actions/checkout@v4 | |
# Find the PR associated with this push, if there is one. | |
- uses: jwalton/gh-find-current-pr@v1 | |
id: findPr | |
with: | |
# Can be "open", "closed", or "all". Defaults to "open". | |
state: all | |
# This will echo "Your PR is 7", or be skipped if there is no current PR. | |
- run: echo "Your PR is ${PR}" | |
if: success() && steps.findPr.outputs.number | |
env: | |
PR: ${{ steps.findPr.outputs.pr }} | |
- name: Setup Mambaforge | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
miniforge-variant: Mambaforge | |
miniforge-version: latest | |
activate-environment: book-render | |
use-mamba: true | |
- name: Set cache date | |
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV | |
- uses: actions/cache@v4 | |
with: | |
path: /usr/share/miniconda3/envs/book-render | |
key: linux-64-conda-${{ hashFiles('render-environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} | |
id: cache | |
- name: Update environment | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: mamba env update -n book-render -f render-environment.yml | |
# Build the book | |
- name: Build the book | |
run: | | |
jupyter-book build . | |
- name: Delete preview files | |
if: ${{ steps.findPr.outputs.pr }} != '' | |
run: rm -rf _preview/${{ steps.findPr.outputs.pr }} | |
# Push the book's HTML to github-pages | |
- name: Deploy to GitHub pages | |
if: github.ref == 'refs/heads/main' | |
uses: peaceiris/actions-gh-pages@v3.9.3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./_build/html | |
enable_jekyll: false | |
keep_files: true # This should preserve existing previews from other PRs |