Skip to content

perf: add Cache-Control headers to S3 sync for edge caching #14

perf: add Cache-Control headers to S3 sync for edge caching

perf: add Cache-Control headers to S3 sync for edge caching #14

Workflow file for this run

name: Deploy Product Docs
on:
push:
branches: [astro]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# Fetch the chat-widget from the landing-page repo (pre-built dist is committed)
- name: Fetch @futureagi/chat-widget
run: |
git clone --depth 1 \
https://x-access-token:${{ secrets.GH_PAT }}@github.com/future-agi/landing-page.git .landing-tmp
cp -r .landing-tmp/docs-agent/packages/chat-widget ./chat-widget
rm -rf .landing-tmp
# Replace workspace:* with local file reference so npm can install it
- name: Patch chat-widget dependency
run: |
sed -i 's|"@futureagi/chat-widget": "workspace:\*"|"@futureagi/chat-widget": "file:./chat-widget"|' package.json
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json', 'package.json') }}
restore-keys: ${{ runner.os }}-npm-
- name: Install dependencies
run: npm install
- name: Create .env.production for build
run: |
printf '%s\n' \
"PUBLIC_DOCS_AGENT_URL=${{ secrets.PUBLIC_DOCS_AGENT_URL }}" \
"PUBLIC_TURNSTILE_SITE_KEY=${{ secrets.PUBLIC_TURNSTILE_SITE_KEY }}" \
> .env.production
- name: Build product docs
run: npx astro build && npx pagefind --site dist
env:
NODE_OPTIONS: --max-old-space-size=4096
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Sync dist/ to S3 with cache headers
run: |
# Hashed assets (_astro/) — immutable, cache for 1 year
aws s3 sync dist/_astro/ s3://${{ secrets.DOCS_S3_BUCKET }}/_astro/ \
--cache-control "public, max-age=31536000, immutable" --delete
# Everything else (HTML, pagefind, images) — short cache, revalidate
aws s3 sync dist/ s3://${{ secrets.DOCS_S3_BUCKET }}/ \
--cache-control "public, max-age=300, s-maxage=86400, stale-while-revalidate=3600" \
--exclude "_astro/*" --delete
- name: Invalidate CloudFront cache
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ secrets.DOCS_CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/*"