Render and deploy Book #147
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: main | |
pull_request: | |
branches: main | |
# to be able to trigger a manual build | |
workflow_dispatch: | |
schedule: | |
# run every day at 11 PM | |
- cron: '0 23 * * 3' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
name: Render and deploy Book | |
env: | |
isExtPR: ${{ github.event.pull_request.head.repo.fork == true }} | |
RUST_BACKTRACE: 1 | |
jobs: | |
build-deploy: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
CMDSTAN_VERSION: "2.35.0" | |
PANDOC_VERSION: "3.1.13" | |
QUARTO_VERSION: "1.4.555" | |
R_VERSION: "4.4.0" | |
LANG: "en_US.UTF-8" | |
TZ: "Asia/Shanghai" | |
RETICULATE_PYTHON_ENV: /opt/.virtualenvs/r-tensorflow | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Quarto | |
uses: quarto-dev/quarto-actions/setup@v2 | |
with: | |
version: ${{ env.QUARTO_VERSION }} | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
use-public-rspm: true | |
r-version: ${{ env.R_VERSION }} | |
extra-repositories: 'https://stan-dev.r-universe.dev https://inla.r-inla-download.org/R/stable' | |
- uses: r-lib/actions/setup-r-dependencies@v2 | |
- name: Install Pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
with: | |
pandoc-version: ${{ env.PANDOC_VERSION }} | |
- name: Install TinyTeX | |
uses: r-lib/actions/setup-tinytex@v2 | |
env: | |
# install full prebuilt version | |
TINYTEX_INSTALLER: TinyTeX | |
- name: Setup Python | |
run: | | |
pip3 install virtualenv | |
mkdir -p /opt/.virtualenvs/r-tensorflow | |
virtualenv -p /usr/bin/python3 $RETICULATE_PYTHON_ENV | |
source $RETICULATE_PYTHON_ENV/bin/activate | |
pip3 install -r requirements.txt | |
python -m spacy download en_core_web_sm | |
python -m spacy download zh_core_web_sm | |
deactivate | |
- name: Setup CmdStan | |
run: | | |
curl -fLo cmdstan-${CMDSTAN_VERSION}.tar.gz https://github.com/stan-dev/cmdstan/releases/download/v${CMDSTAN_VERSION}/cmdstan-${CMDSTAN_VERSION}.tar.gz | |
mkdir -p /opt/cmdstan/ | |
tar -xzf cmdstan-${CMDSTAN_VERSION}.tar.gz -C /opt/cmdstan/ | |
make build -C /opt/cmdstan/cmdstan-${CMDSTAN_VERSION} | |
rm cmdstan-${CMDSTAN_VERSION}.tar.gz | |
- name: Install Fonts From System | |
run: | | |
sudo apt-get install -y ghostscript graphviz optipng | |
sudo apt-get install -y fonts-noto-core fonts-noto-cjk | |
fc-list | grep 'noto' | sort | |
fc-list | sort | |
- name: Install LaTeX packages | |
run: | | |
if(!require('tinytex')) install.packages('tinytex') | |
tinytex::tlmgr_install(readLines("texlive.txt")) | |
tinytex::tl_pkgs() | |
tikzDevice::tikzTest("m", engine = "xetex") | |
tikzDevice::tikzTest("$\\sin(x^2/2 - y^2/4 + 3) \\cos(2 x + 1 - \\exp(y))$") | |
shell: Rscript {0} | |
- name: Reinstall R packages from source | |
run: | | |
install.packages(c("Matrix", "MatrixModels", "rjags", "lme4", "TMB", "glmmTMB"), repos = "https://cran.r-project.org/", type = "source") | |
shell: Rscript {0} | |
- name: Setup magick | |
run: | | |
sudo sed -i_bak \ | |
's/name="disk" value="1GiB"/name="disk" value="8GiB"/' \ | |
/etc/ImageMagick-6/policy.xml | |
- name: Render Book | |
run: | | |
source $RETICULATE_PYTHON_ENV/bin/activate | |
quarto check | |
quarto render --to html | |
shell: bash | |
env: | |
RETICULATE_PYTHON_ENV: /opt/.virtualenvs/r-tensorflow | |
RETICULATE_PYTHON: /opt/.virtualenvs/r-tensorflow/bin/python | |
CMDSTAN: /opt/cmdstan/cmdstan-${{ env.CMDSTAN_VERSION }} | |
- name: Deploy book to bookdown.org | |
env: | |
CONNECT_API_KEY: ${{ secrets.RSC_BOOKDOWN_TOKEN }} | |
CONTENT_ID: ${{ secrets.RSC_BOOKDOWN_APP_ID }} | |
run: | | |
Rscript '_deploy.R' | |
- name: Deploy book to Netlify | |
id: netlify-deploy | |
uses: nwtgck/[email protected] | |
with: | |
publish-dir: './_book' | |
production-branch: main | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
deploy-message: | |
'Deploy from GHA: ${{ github.event.pull_request.title || github.event.head_commit.message }} (${{ github.sha }})' | |
enable-pull-request-comment: true | |
enable-commit-comment: true | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
timeout-minutes: 1 |