update actions #109
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
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
name: booklet | |
jobs: | |
bookdown: | |
name: build-bookdown | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install system dependencies | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt update | |
sudo apt install -y curl libcurl4-doc libcurl4-openssl-dev \ | |
libharfbuzz-dev libfribidi-dev libmagick++-dev libpoppler-cpp-dev \ | |
texlive-extra-utils ghostscript | |
- name: Install pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
- name: Install tinyTeX | |
uses: r-lib/actions/setup-tinytex@v2 | |
- name: Install R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: 'release' | |
- name: Install R dependencies via renv | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Cache bookdown results | |
uses: actions/cache@v4 | |
with: | |
path: _bookdown_files | |
key: bookdown-2-${{ hashFiles('**/*Rmd') }} | |
restore-keys: bookdown-2- | |
- name: Render book HTML | |
run: | | |
Rscript -e 'bookdown::clean_book(TRUE)' | |
Rscript -e 'bookdown::render_book("index.Rmd", quiet = TRUE)' | |
- name: Render book PDF | |
run: | | |
Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::pdf_book")' | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: _handbook | |
path: _handbook/ | |
# Need to first create an empty gh-pages branch | |
# see https://pkgdown.r-lib.org/reference/deploy_site_github.html | |
# and also add secrets for a GH_PAT and EMAIL to the repository | |
# gh-action from https://github.com/Cecilapp/GitHub-Pages-deploy | |
checkout-and-deploy: | |
runs-on: ubuntu-latest | |
needs: bookdown | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
# Artifact name | |
name: _handbook # optional | |
# Destination path | |
path: _handbook # optional | |
- name: Abbreviate Git SHA | |
run: echo "GITHUB_SHA_SHORT=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV | |
- name: Deploy to GitHub Pages | |
uses: Cecilapp/GitHub-Pages-deploy@v3 | |
if: github.event_name != 'pull_request' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
email: ${{ secrets.EMAIL }} # must be a GitHub-verified email | |
build_dir: _handbook/ # "_site/" by default | |
commit_message: Update book via ${{ env.GITHUB_SHA_SHORT }} |