Skip to content

Deploy to GitHub Pages #92

Deploy to GitHub Pages

Deploy to GitHub Pages #92

name: Deploy to GitHub Pages
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "src/**"
- "static/img/**"
- "docusaurus.config.ts"
- "sidebars.ts"
- "package.json"
workflow_run:
workflows: [Sync Notion Docs]
types: [completed]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
build:
name: Build
# Run on push/workflow_dispatch; if workflow_run, require success
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code (main branch)
uses: actions/checkout@v5
with:
ref: main
- name: Checkout content files from content branch
run: |
set -e # Exit on error
echo "📥 Fetching content from content branch..."
git fetch origin content
echo "📂 Checking out content files..."
git checkout origin/content -- docs/ i18n/ static/images/
# Validate content exists
echo "🔍 Validating content..."
# Count markdown files across all languages
# Guard against missing directories to avoid find failures
# Support both .md and .mdx files (Docusaurus accepts both)
if [ -d docs ]; then
DOCS_COUNT=$(find docs \( -name "*.md" -o -name "*.mdx" \) -type f 2>/dev/null | wc -l)
else
DOCS_COUNT=0
fi
if [ -d i18n ]; then
I18N_COUNT=$(find i18n \( -name "*.md" -o -name "*.mdx" \) -type f 2>/dev/null | wc -l)
else
I18N_COUNT=0
fi
TOTAL_CONTENT=$((DOCS_COUNT + I18N_COUNT))
if [ "$TOTAL_CONTENT" -eq 0 ]; then
echo "❌ Error: No documentation content found"
echo " Expected: At least one .md or .mdx file in docs/ or i18n/ directories"
echo " Found: 0 files"
echo "Cannot proceed with build - documentation content is required"
exit 1
fi
# Warn if default locale (English) has no content
if [ "$DOCS_COUNT" -eq 0 ]; then
echo "⚠️ WARNING: No English content in docs/ directory"
echo " Docusaurus build may fail if default locale has no content"
fi
if [ ! -d "static/images" ] || [ -z "$(ls -A static/images 2>/dev/null)" ]; then
echo "⚠️ Warning: static/images/ directory is empty or missing"
echo "Build will proceed but images may be unavailable"
fi
echo "✅ Content validation successful"
echo "📊 Content statistics:"
echo " - English docs: $DOCS_COUNT"
echo " - Localized docs: $I18N_COUNT"
echo " - Total docs: $TOTAL_CONTENT"
find static/images -type f 2>/dev/null | wc -l | xargs echo " - Images:"
- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
- name: Install dependencies
run: bun i
- name: Build website
env:
BASE_URL: /comapeo-docs/
DEFAULT_DOCS_PAGE: ${{ secrets.DEFAULT_DOCS_PAGE }}
run: bun run build
- name: Upload artifact
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
path: build
deploy:
name: Deploy
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
update-notion-status:
name: Update Notion Status → Draft published
needs: deploy
if: ${{ needs.deploy.result == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: main
- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
- name: Install dependencies
run: bun i
- name: Update Notion Status → Draft published
run: bun run notionStatus:draft
env:
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
DATA_SOURCE_ID: ${{ secrets.DATA_SOURCE_ID }}
DATABASE_ID: ${{ secrets.DATABASE_ID }}
notify-slack:
name: Notify Slack
runs-on: ubuntu-latest
needs:
- build
- deploy
- update-notion-status
if: ${{ always() }}
steps:
- name: Notify Slack
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*GitHub Pages pipeline*: build=${{ needs.build.result }}, deploy=${{ needs.deploy.result }}, notion=${{ needs['update-notion-status'].result }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "*GitHub Pages pipeline*: build=${{ needs.build.result }}, deploy=${{ needs.deploy.result }}, notion=${{ needs['update-notion-status'].result }}"
- type: "section"
text:
type: "mrkdwn"
text: "Triggered by: <https://github.com/${{ github.triggering_actor }}|${{ github.triggering_actor }}>\nRun: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>"
- type: "section"
text:
type: "mrkdwn"
text: "Site URL: https://digidem.github.io/comapeo-docs/ (GitHub Pages)"