Skip to content

Deploy: clean v2-publish so stale bookdown files stop serving #269

Deploy: clean v2-publish so stale bookdown files stop serving

Deploy: clean v2-publish so stale bookdown files stop serving #269

on:
push:
branches: [main, master, v2-quarto-html]
pull_request:
branches: [main, master, v2-quarto-html]
workflow_dispatch:
name: Quarto Publish
jobs:
build-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# renv is DISABLED in CI (temporary, during content review): when active,
# renv intercepts the GitHub-package installs and resolves their SHAs via
# api.github.com, which intermittently 4xx-fails (error 22) and breaks the
# build. With the autoloader off, R uses the default library; we install
# the lockfile's CRAN packages directly from P3M and the GitHub data
# packages via plain git clone. Re-enable + properly fix renv at the end.
RENV_CONFIG_AUTOLOADER_ENABLED: "FALSE"
RENV_CONFIG_SYNCHRONIZED_CHECK: "FALSE"
steps:
# Checkout repository
- uses: actions/checkout@v6
# Setup Quarto
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
# Setup R environment - pin to the version renv.lock was built against
# so RSPM serves precompiled binaries (avoids source compilation against
# mismatched R API headers).
- uses: r-lib/actions/setup-r@v2
with:
r-version: '4.5.2'
use-public-rspm: true
# Install system libraries for the V8 R package
- name: Install system libraries for V8
run: |
sudo apt-get update
# Try libv8-dev first; if not available on this Ubuntu image, fall back to libnode-dev
sudo apt-get install -y libv8-dev || sudo apt-get install -y libnode-dev
# ICU is a common runtime dependency for V8 on Ubuntu
sudo apt-get install -y libicu-dev
# renv DISABLED: install the lockfile's CRAN packages (everything that is
# NOT a GitHub source — including moderndive, which the lockfile pins from
# CRAN) directly from P3M binaries into the default library. No renv,
# no api.github.com.
- name: Install CRAN packages from renv.lock
run: |
R -q -e '
if (!requireNamespace("jsonlite", quietly = TRUE)) install.packages("jsonlite")
lock <- jsonlite::fromJSON("renv.lock", simplifyVector = FALSE)$Packages
keep <- Filter(function(p) !identical(p$Source, "GitHub") && !identical(p$RemoteType, "github"), lock)
need <- setdiff(names(keep), rownames(installed.packages()))
need <- setdiff(need, "moderndive") # dev moderndive comes from GitHub main below
message("Installing ", length(need), " CRAN packages from the lockfile")
if (length(need)) install.packages(need)
'
# The 4 GitHub-only data packages via plain git clone. remotes::install_git
# does NOT call api.github.com (only renv's interception did, and renv is
# off here), so this just clones + installs.
- name: Install GitHub-only exercise packages
run: |
R -q -e 'if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes")'
ok=0
for attempt in 1 2 3 4 5; do
R -q -e 'for (repo in c("moderndive/olympicAthletes",
"moderndive/exoplanetdata",
"moderndive/volcanoes",
"moderndive/moderndive")) remotes::install_git(
paste0("https://github.com/", repo, ".git"), upgrade = "never", quiet = FALSE)' && { ok=1; break; }
echo "::warning::GitHub install attempt $attempt failed; retrying in $((attempt*10))s"; sleep $((attempt*10))
done
[ "$ok" = 1 ] || { echo "::error::GitHub package install failed after 5 attempts"; exit 1; }
# Cache Quarto's freeze directory so chapters don't re-execute on every push.
# Cache key now hashes ONLY the root-level book qmds + index.qmd (what
# the main book actually renders) — not instructor-solutions/ or other
# nested qmds, whose changes don't affect the main book's freeze.
- name: Cache Quarto freeze
uses: actions/cache@v5
with:
path: .quarto/_freeze
key: quarto-freeze-${{ hashFiles('*.qmd', 'index.qmd', 'scripts/exercise_helpers.R', 'scripts/image_functions.R', 'exercises/*.yml') }}
restore-keys: quarto-freeze-
# Render Quarto book
- name: Render Quarto Book
run: quarto render
# Save R package state
- name: Save R Package State
run: |
R -e 'saveRDS(installed.packages(), file = "installed_packages.rds")'
# Deploy HTML to GitHub Pages if on main or master branch
- name: Deploy to GitHub pages from main/master 🚀
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
uses: JamesIves/github-pages-deploy-action@v4.8.0
with:
branch: gh-pages
folder: docs
clean: false
# Deploy to v2-publish if on v2-quarto-html branch.
# NOTE: deliberately not deploying to gh-pages/v2 — that subfolder
# is the live moderndive.com/v2 page and stays on the bookdown build
# served from the v2 branch.
# clean: true so each deploy wipes files no longer produced by the
# render — otherwise orphans linger forever (e.g. the old bookdown
# build's non-prefixed chapter files like getting-started.html, which
# kept serving stale content alongside the Quarto 01-getting-started.html).
# previous_versions/ is preserved: the preface links to it but Quarto
# does not re-emit it into docs/, so it must be excluded from cleaning.
- name: Deploy to v2-publish branch 🚀
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/v2-quarto-html'
uses: JamesIves/github-pages-deploy-action@v4.8.0
with:
branch: v2-publish
folder: docs
clean: true
clean-exclude: |
previous_versions