mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-03-11 17:49:25 -05:00
124 lines
3.8 KiB
YAML
124 lines
3.8 KiB
YAML
name: '📦 Kits · 👁️ Preview (Dev)'
|
|
|
|
# Builds and deploys Hardware Kits site (with PDF) to dev preview
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [dev]
|
|
paths:
|
|
- 'kits/**'
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
concurrency:
|
|
group: kits-dev-deploy
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# 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: [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: kits
|
|
run: |
|
|
quarto render
|
|
touch _build/.nojekyll
|
|
|
|
- name: 📥 Download PDF Artifact
|
|
uses: actions/download-artifact@v7
|
|
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 kits/_build/assets/downloads
|
|
|
|
if [ -f ./pdf-artifacts/Hardware-Kits.pdf ]; then
|
|
cp ./pdf-artifacts/Hardware-Kits.pdf kits/_build/assets/downloads/
|
|
echo "✅ Injected Hardware-Kits.pdf"
|
|
else
|
|
echo "⚠️ PDF not found"
|
|
fi
|
|
|
|
echo ""
|
|
echo "📦 Downloads folder contents:"
|
|
ls -la kits/_build/assets/downloads/ || echo "No downloads folder"
|
|
|
|
- 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 book/tools/scripts/publish/modify_dev_announcement.py \
|
|
kits/_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 }}/kits/_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"
|
|
git push origin main
|
|
|
|
echo "✅ Kits deployed to: https://harvard-edge.github.io/${{ vars.DEV_REPO }}/${{ vars.DEV_KITS_PATH }}/"
|