mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-08-03 12:14:39 -05:00
Rolls the same gating pattern from staffml out to kits, slides, instructors, site, and mlsysim, all of which had the same race — preview-dev and validate-dev triggered independently on push to dev with no `needs:` between them, so a deploy could ship even when validate failed on the same SHA. (labs and tinytorch already gate via `workflow_run` and were left alone.) For each pair: validate-dev gains a workflow_call trigger and rekeys concurrency to `head_ref || run_id`. preview-dev adds a `validate` job that calls validate-dev via `uses:` and the existing build-and-deploy job grows a `needs: [validate, ...]`. Build doesn't start until validate finishes, so wall-clock per push regresses by roughly the validate duration; can be upgraded to the staffml-style parallel-build split per component if that becomes painful.
170 lines
5.7 KiB
YAML
170 lines
5.7 KiB
YAML
name: '📦 Kits · 👁️ Preview (Dev)'
|
|
|
|
# =============================================================================
|
|
# Hardware Kits — Dev Preview Deploy
|
|
# =============================================================================
|
|
#
|
|
# Builds the Hardware Kits Quarto site with PDF and deploys to the dev
|
|
# preview site via SSH.
|
|
#
|
|
# Flow:
|
|
# 1. BUILD_PDF — Compile Hardware Kits PDF (reusable workflow)
|
|
# 2. BUILD_SITE — Quarto render + inject PDF into site
|
|
# 3. DEPLOY — Push to dev preview repo via SSH
|
|
#
|
|
# Triggers:
|
|
# - push: dev branch, kits/** paths
|
|
# - workflow_dispatch: manual
|
|
#
|
|
# Deploys to: harvard-edge.github.io/{DEV_REPO}/{DEV_KITS_PATH}/
|
|
# Secrets: SSH_DEPLOY_KEY
|
|
# Vars: KITS_ROOT, BOOK_TOOLS, DEV_REPO, DEV_REPO_URL, DEV_KITS_PATH
|
|
#
|
|
# Related:
|
|
# - kits-validate-dev.yml — Content & build validation
|
|
# - kits-publish-live.yml — Production deploy to mlsysbook.ai/kits/
|
|
# - kits-build-pdfs.yml — Reusable PDF build
|
|
#
|
|
# =============================================================================
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [dev]
|
|
paths:
|
|
- 'kits/**'
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
concurrency:
|
|
group: kits-dev-deploy
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# Run the full validate-dev workflow inline. Deploy depends on it so
|
|
# Preview can never deploy on a SHA where validate failed (the bug
|
|
# this gating closes is the screenshot pattern of "Preview ✅ but
|
|
# Validate ❌ on the same SHA"). Validate runs in parallel with
|
|
# build-pdf, so wall-clock impact is small.
|
|
validate:
|
|
name: '✅ Validate (Dev)'
|
|
uses: ./.github/workflows/kits-validate-dev.yml
|
|
|
|
# Build PDF first
|
|
build-pdf:
|
|
name: '📚 Build PDF'
|
|
uses: ./.github/workflows/kits-build-pdfs.yml
|
|
with:
|
|
ref: ${{ github.ref }}
|
|
|
|
build-and-deploy:
|
|
name: '📦 Build & Deploy Kits (Dev)'
|
|
runs-on: ubuntu-latest
|
|
needs: [validate, build-pdf]
|
|
|
|
steps:
|
|
- name: 📥 Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 🔧 Setup Quarto
|
|
uses: quarto-dev/quarto-actions/setup@v2
|
|
|
|
- name: 🔨 Build Kits Site
|
|
working-directory: ${{ vars.KITS_ROOT }}
|
|
run: |
|
|
quarto render
|
|
touch _build/.nojekyll
|
|
|
|
- name: 📥 Download PDF Artifact
|
|
uses: actions/download-artifact@v8
|
|
continue-on-error: true
|
|
with:
|
|
name: Kits-PDF
|
|
path: ./pdf-artifacts/
|
|
|
|
- name: 📁 Inject PDF into site
|
|
run: |
|
|
echo "📁 Injecting PDF into built site..."
|
|
mkdir -p ${{ vars.KITS_ROOT }}/_build/assets/downloads
|
|
|
|
if [ -f ./pdf-artifacts/Hardware-Kits.pdf ]; then
|
|
cp ./pdf-artifacts/Hardware-Kits.pdf ${{ vars.KITS_ROOT }}/_build/assets/downloads/
|
|
echo "✅ Injected Hardware-Kits.pdf"
|
|
else
|
|
echo "⚠️ PDF not found"
|
|
fi
|
|
|
|
echo ""
|
|
echo "📦 Downloads folder contents:"
|
|
ls -la ${{ vars.KITS_ROOT }}/_build/assets/downloads/ || echo "No downloads folder"
|
|
|
|
- name: 🔗 Rewrite URLs for dev site
|
|
run: bash .github/scripts/rewrite-dev-urls.sh kits ${{ vars.KITS_ROOT }}/_build
|
|
|
|
- name: 🔧 Modify announcement for dev preview
|
|
run: |
|
|
echo "🔧 Modifying announcement banner for development preview..."
|
|
COMMIT_SHORT="${{ github.sha }}"
|
|
COMMIT_SHORT="${COMMIT_SHORT:0:8}"
|
|
|
|
python3 ${{ vars.BOOK_TOOLS }}/scripts/publish/modify_dev_announcement.py \
|
|
${{ vars.KITS_ROOT }}/_build \
|
|
--verbose \
|
|
--commit-hash "${{ github.sha }}" \
|
|
--commit-short "$COMMIT_SHORT"
|
|
|
|
- name: 🚀 Deploy to Dev Site via SSH
|
|
env:
|
|
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
|
run: |
|
|
echo "🔐 Starting ssh-agent..."
|
|
eval "$(ssh-agent -s)"
|
|
echo "$SSH_DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
|
|
|
# Add github.com to known hosts
|
|
mkdir -p ~/.ssh
|
|
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
|
|
|
echo "🔧 Configuring git..."
|
|
git config --global user.email "actions@github.com"
|
|
git config --global user.name "GitHub Actions"
|
|
|
|
echo "🔄 Cloning dev preview repository (${{ vars.DEV_REPO }})..."
|
|
git clone --depth=1 ${{ vars.DEV_REPO_URL }} target-repo
|
|
|
|
cd target-repo
|
|
|
|
echo "🧹 Cleaning ${{ vars.DEV_KITS_PATH }} directory..."
|
|
rm -rf ${{ vars.DEV_KITS_PATH }}
|
|
mkdir -p ${{ vars.DEV_KITS_PATH }}
|
|
|
|
echo "🚚 Copying Kits site content..."
|
|
cp -r "${{ github.workspace }}/${{ vars.KITS_ROOT }}/_build/." ${{ vars.DEV_KITS_PATH }}/
|
|
|
|
echo "🔍 Validating deployment content..."
|
|
if [ ! -f "${{ vars.DEV_KITS_PATH }}/index.html" ]; then
|
|
echo "❌ CRITICAL: ${{ vars.DEV_KITS_PATH }}/index.html is missing. Aborting deployment."
|
|
exit 1
|
|
fi
|
|
|
|
echo "📦 Contents of ${{ vars.DEV_KITS_PATH }}/:"
|
|
ls -la ${{ vars.DEV_KITS_PATH }}/ | head -10
|
|
|
|
echo "📦 Committing and pushing changes..."
|
|
git add .
|
|
git commit -m "📦 Deploy Kits dev to /${{ vars.DEV_KITS_PATH }}/ from ${{ github.sha }}" --allow-empty || echo "🟡 Nothing to commit"
|
|
|
|
# Retry push with rebase to handle concurrent deploys
|
|
for i in 1 2 3; do
|
|
if git push origin main 2>/dev/null; then
|
|
echo "✅ Push succeeded on attempt $i"
|
|
break
|
|
fi
|
|
echo "⚠️ Push failed (attempt $i/3), pulling with rebase..."
|
|
git pull --rebase origin main || true
|
|
done
|
|
|
|
echo "✅ Kits deployed to: https://harvard-edge.github.io/${{ vars.DEV_REPO }}/${{ vars.DEV_KITS_PATH }}/"
|