Skip to content

Build and Deploy jac-lang.org Documentation #121

Build and Deploy jac-lang.org Documentation

Build and Deploy jac-lang.org Documentation #121

Workflow file for this run

name: Build and Deploy jac-lang.org Documentation
on:
release:
types: [published]
workflow_dispatch:
push:
branches:
- main
paths:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
schedule:
# Rebuild documentation daily at 2 AM UTC
- cron: '0 2 * * *'
permissions:
id-token: write
contents: read
env:
ECR_REGISTRY: 776241927220.dkr.ecr.us-east-2.amazonaws.com
ECR_REPOSITORY: jac-lang-website
jobs:
deploy-jac-lang-website:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: docs
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0 # Full git history for changelog generation
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install documentation dependencies
run: |
python -m pip install --upgrade pip
pip install -e ../jac
pip install -e .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4.2.0
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::776241927220:role/GitHubActionsSharedECRRole
role-session-name: GitHubActions-JacLang-Docs
audience: sts.amazonaws.com
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Get tag name
id: tag
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="manual-$(date +%Y%m%d-%H%M%S)"
elif [[ "${{ github.event_name }}" == "release" ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
if [[ $TAG_NAME =~ ^jac-lang-docs-(.+)$ ]]; then
TAG="${BASH_REMATCH[1]}"
elif [[ $TAG_NAME =~ ^jaclang-(.+)$ ]]; then
TAG="${BASH_REMATCH[1]}"
elif [[ $TAG_NAME =~ ^v(.+)$ ]]; then
TAG="$TAG_NAME"
else
TAG="$TAG_NAME"
fi
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
TAG="nightly-$(date +'%Y%m%d')"
else
COMMIT_COUNT=$(git rev-list --count HEAD)
SHORT_SHA=$(git rev-parse --short=8 HEAD)
TAG="v1.${COMMIT_COUNT}.${SHORT_SHA}"
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Prepare documentation for serving
working-directory: .
run: |
echo "Build Information:" > docs/build-info.txt
echo "Version: ${{ steps.tag.outputs.tag }}" >> docs/build-info.txt
echo "Built: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> docs/build-info.txt
echo "Commit: ${{ github.sha }}" >> docs/build-info.txt
echo "Branch: ${{ github.ref_name }}" >> docs/build-info.txt
echo "Trigger: ${{ github.event_name }}" >> docs/build-info.txt
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build Docker image
working-directory: .
run: |
cat > Dockerfile << 'EOF'
FROM python:3.12-slim
RUN apt-get update && apt-get install -y \
curl \
git \
graphviz \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY .git/ ./.git/
COPY docs/ ./docs/
COPY jac/ ./jac/
COPY jac-client/ ./jac-client/
COPY scripts/ ./scripts/
COPY CONTRIBUTING.md ./CONTRIBUTING.md
COPY .pre-commit-config.yaml ./.pre-commit-config.yaml
RUN pip install -e ./jac
RUN pip install -e ./docs
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8000/health || exit 1
CMD ["python", "docs/scripts/mkdocs_serve.py"]
EOF
docker buildx build --load \
--cache-to type=gha,mode=max \
--cache-from type=gha \
-t docs-smoke-test .
- name: Smoke test container
run: |
docker run -d --name docs-test -p 8000:8000 docs-smoke-test
echo "Waiting for container to start..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8000/health > /dev/null 2>&1; then
echo "Health check passed after ${i}0 seconds"
docker rm -f docs-test
exit 0
fi
echo "Attempt $i/30 - waiting 10s..."
sleep 10
done
echo "Container failed to become healthy"
docker logs docs-test
docker rm -f docs-test
exit 1
- name: Push Docker image to ECR
working-directory: .
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
-t $ECR_REGISTRY/$ECR_REPOSITORY:${{ steps.tag.outputs.tag }} \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
--push \
.
summary:
needs: [deploy-jac-lang-website]
runs-on: ubuntu-latest
if: always()
steps:
- name: Build and Push Summary
run: |
echo "## jac-lang.org Documentation Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Documentation Website" >> $GITHUB_STEP_SUMMARY
echo "- **Image Tag**: ${{ needs.deploy-jac-lang-website.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **ECR Repository**: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ${{ needs.deploy-jac-lang-website.result }}" >> $GITHUB_STEP_SUMMARY
echo "- **Production URLs**:" >> $GITHUB_STEP_SUMMARY
echo " - https://jac-lang.org" >> $GITHUB_STEP_SUMMARY
echo " - https://www.jac-lang.org" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Note**: Deployment will be handled automatically by Flux in jaseci-cluster." >> $GITHUB_STEP_SUMMARY