Files
cs249r_book/.github/workflows/quarto-build-lite.yml
Vijay Janapa Reddi ced7d3a8e9 Replaces deploy action with shell script
Substitutes the deploy action with a shell script,
leveraging git commands directly for enhanced control
and customization during deployment. This change aims
to provide a more flexible and reliable deployment process.
2025-04-20 20:47:00 -04:00

235 lines
7.6 KiB
YAML

name: '📚 Quarto Build HTML'
on:
workflow_call:
inputs:
environment:
required: true
type: string
description: 'Build environment (development/production)'
os:
required: true
type: string
description: 'Operating system to run on (ubuntu-latest)'
quarto-version:
required: false
type: string
default: '1.6.42'
description: 'Version of Quarto to use'
r-version:
required: false
type: string
default: '4.3.2'
description: 'Version of R to use'
target:
required: true
type: string
description: 'Target branch (dev/main) - determines build behavior'
secrets:
SSH_DEPLOY_KEY:
required: true
permissions:
contents: write
pages: write
jobs:
build:
runs-on: ${{ inputs.os }}
container:
image: rocker/verse:latest
environment:
name: ${{ inputs.environment }}
steps:
- name: 🔍 Validate inputs
shell: bash
run: |
if [[ "${{ inputs.target }}" != "dev" && "${{ inputs.target }}" != "main" ]]; then
echo "❌ Target must be either 'dev' or 'main'"
exit 1
fi
echo "✅ Input validation passed"
- name: 📥 Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.target }}
fetch-depth: 0
# Cache apt packages
- name: 💾 Cache apt packages
uses: actions/cache@v3
id: apt-cache
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/workflow.yml') }}
restore-keys: |
${{ runner.os }}-apt-
# Install LaTeX packages with cache awareness
- name: 📦 Install LaTeX dependencies
shell: bash
run: |
apt-get update
# Use -d to download only without installing
apt-get -y --no-install-recommends -d install \
texlive-latex-base \
texlive-latex-extra \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-xetex \
texlive-luatex \
texlive-pictures \
lmodern
# Now install from cache
apt-get -y --no-install-recommends install \
texlive-latex-base \
texlive-latex-extra \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-xetex \
texlive-luatex \
texlive-pictures \
lmodern
echo "✅ LaTeX packages installed"
# Cache Quarto installation
- name: 💾 Cache Quarto
uses: actions/cache@v3
id: quarto-cache
with:
path: /opt/quarto/${{ inputs.quarto-version }}
key: ${{ runner.os }}-quarto-${{ inputs.quarto-version }}
# Install Quarto using the action with cache awareness
- name: 📦 Setup Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
version: ${{ inputs.quarto-version }}
# # Cache Inkscape and dependencies installation
# - name: 💾 Cache Inkscape installation
# if: runner.os == 'Linux'
# id: inkscape-cache
# uses: actions/cache@v3
# with:
# path: /usr/bin/inkscape
# key: ${{ runner.os }}-inkscape-${{ hashFiles('/etc/apt/sources.list.d/inkscape*.list') }}
# restore-keys: |
# ${{ runner.os }}-inkscape-
# Install Inkscape on Linux with cache awareness
- name: 📦 Install Inkscape (Linux)
if: runner.os == 'Linux' && steps.inkscape-cache.outputs.cache-hit != 'true'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:inkscape.dev/stable -y
sudo apt-get update
sudo apt-get install -y inkscape
- name: ✅ Verify Inkscape Installation (Linux)
if: runner.os == 'Linux'
shell: bash
run: inkscape --version
# Cache R packages
- name: 💾 Cache R packages
uses: actions/cache@v3
with:
path: /usr/local/lib/R/site-library
key: ${{ runner.os }}-r-${{ inputs.r-version }}-${{ hashFiles('**/install_packages.R', '**/*.Rmd', '**/*.qmd') }}
restore-keys: |
${{ runner.os }}-r-${{ inputs.r-version }}-
# Install any additional R packages needed
- name: 📦 Install additional R packages
shell: Rscript {0}
run: |
# First check which packages are already installed
installed_pkgs <- installed.packages()[, "Package"]
if (file.exists("install_packages.R")) {
source("install_packages.R")
} else {
# Install minimal set of packages needed if not already installed
pkgs <- c("knitr", "rmarkdown", "downlit")
missing_pkgs <- pkgs[!pkgs %in% installed_pkgs]
if (length(missing_pkgs) > 0) {
install.packages(missing_pkgs)
} else {
cat("All required packages already installed.\n")
}
}
# Print installed packages for debugging
cat("Installed packages:\n")
print(sort(installed.packages()[, "Package"]))
# Cache compilation artifacts
- name: 💾 Cache compilation artifacts
uses: actions/cache@v3
with:
path: |
**/_cache
**/.quarto
**/.jupyter_cache
**/_freeze
key: quarto-compilation-${{ hashFiles('**/*.qmd', '**/*.ipynb', '**/*.md', '**/*.Rmd', '**/*.R') }}
restore-keys: |
quarto-compilation-
# Render using Quarto action
- name: 🔨 Render Quarto to HTML
uses: quarto-dev/quarto-actions/render@v2
with:
to: html
- name: 📤 Upload artifact
uses: actions/upload-artifact@v4
with:
name: html-output
path: _book
- name: 🚀 Stage to Dev Site
if: inputs.target == 'dev'
run: |
git config --global user.email "khoshnevis.naeem@gmail.com"
git config --global user.name "github-actions"
git clone git@github.com:harvard-edge/cs249r_book_dev.git target-repo
cd target-repo
git checkout main
git pull origin main
rm -rf docs
cp -r ../_book docs
git add docs
git commit -m "📚 Push dev branch HTML build (Docker version)"
git push origin main
env:
GIT_SSH_COMMAND: 'ssh -i ${{ secrets.SSH_DEPLOY_KEY }} -o StrictHostKeyChecking=no'
- name: 📋 Build Summary
shell: bash
run: |
cat << EOF >> $GITHUB_STEP_SUMMARY
## 📊 HTML-only Quarto Build Summary (Docker)
🎯 Target: ${{ inputs.target }}
💻 OS: ${{ inputs.os }}
🔧 Environment: ${{ inputs.environment }}
📚 Quarto Version: ${{ inputs.quarto-version }}
🔬 R Version: ${{ inputs.r-version }}
🐳 Docker Image: rocker/verse:${{ inputs.r-version }}
⏰ Completed at: $(date "+%Y-%m-%d %H:%M:%S")
### 💾 Cache Status
- APT Cache: ${{ steps.apt-cache.outputs.cache-hit == 'true' && '✅ Hit' || '❌ Miss' }}
- Quarto Cache: ${{ steps.quarto-cache.outputs.cache-hit == 'true' && '✅ Hit' || '❌ Miss' }}
- Inkscape Cache: ${{ steps.inkscape-cache.outputs.cache-hit == 'true' && '✅ Hit' || '❌ Miss' }}
EOF