Skip to content

Install vendored MkDocs plugins without committing build outputs #737

Install vendored MkDocs plugins without committing build outputs

Install vendored MkDocs plugins without committing build outputs #737

Workflow file for this run

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"