Install vendored MkDocs plugins without committing build outputs #737
Workflow file for this run
This file contains hidden or 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
name: Docs CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
concurrency: | |
group: docs-ci-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
jobs: | |
build: | |
name: Build documentation | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
cache-dependency-path: requirements.txt | |
- name: Install dependencies | |
run: pip install -r requirements.txt | |
- name: Build MkDocs site | |
run: mkdocs build --strict | |
- name: Configure GitHub Pages | |
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' | |
uses: actions/configure-pages@v5 | |
- name: Upload MkDocs artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: mkdocs-site | |
path: site | |
- name: Upload GitHub Pages artifact | |
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: site | |
deploy-preview: | |
name: Deploy preview to GitHub Pages | |
needs: build | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages-preview | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy preview | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
with: | |
preview: true | |
deploy-production: | |
name: Deploy to production server | |
needs: build | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install SSH key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.DEPLOY_KEY }} | |
known_hosts: ${{ secrets.KNOWN_HOSTS }} | |
- name: Remote deploy via SSH | |
run: | | |
echo "π Deploying to remote server..." | |
ssh [email protected] "export GITHUB_SHA=$GITHUB_SHA; bash -s" <<'EOF' | |
set -eo pipefail | |
echo "π Changing to project directory..." | |
cd /var/www/ergodocs || { echo "β Failed to cd to project dir"; exit 1; } | |
echo "π Resetting repository to expected commit..." | |
git fetch origin main || { echo "β Git fetch failed"; exit 1; } | |
git reset --hard "${GITHUB_SHA}" || { echo "β Git reset failed"; exit 1; } | |
git clean -fd | |
if ! dpkg -s python3-venv >/dev/null 2>&1; then | |
echo "π§° Installing python3-venv..." | |
apt-get update -y && apt-get install -y python3-venv | |
fi | |
echo "π Setting up virtual environment..." | |
if [ ! -d .venv ]; then | |
python3 -m venv .venv | |
fi | |
source .venv/bin/activate | |
echo "π¦ Installing dependencies..." | |
pip install --upgrade pip | |
pip install -r requirements.txt || { echo "β Pip install failed"; exit 1; } | |
echo "π§Ή Cleaning old MkDocs site..." | |
rm -rf site || echo "β οΈ Failed to remove site dir" | |
echo "π Building MkDocs site..." | |
mkdocs build --strict || { echo "β MkDocs build failed"; exit 1; } | |
echo "πͺͺ Writing deploy metadata..." | |
echo "${GITHUB_SHA}" > site/deploy-sha.txt | |
date -u +"%Y-%m-%dT%H:%M:%SZ" > site/deploy-timestamp.txt | |
EOF | |
- name: Verify remote site files | |
run: | | |
echo "π Checking recently updated files..." | |
ssh [email protected] 'find /var/www/ergodocs/site -type f -printf "π %TY-%Tm-%Td %TH:%TM:%TS %p\n" | sort -r | head -n 10' | |
- name: Check web server served files | |
run: | | |
echo "π Verifying web server output..." | |
DEPLOYED_SHA=$(curl -fsS https://docs.ergoplatform.com/deploy-sha.txt || true) | |
if [ -z "$DEPLOYED_SHA" ]; then | |
echo "β Unable to read deployed SHA from web server" | |
exit 1 | |
fi | |
echo "π Remote site reports commit: $DEPLOYED_SHA" | |
if [ "$DEPLOYED_SHA" != "$GITHUB_SHA" ]; then | |
echo "β Remote site commit does not match expected $GITHUB_SHA" | |
exit 1 | |
fi | |
echo "β Remote site matches expected commit" |