deploy.ymlYAML, shown as text and never run
# Build and check every pull request. Deploy to Cloudflare Workers on push to main.
# Replace <SITE_DIR> with the site folder. For a site at the repo root use "."
# and delete both "paths:" filters.
name: Site
on:
pull_request:
paths: ["<SITE_DIR>/**", ".github/workflows/site.yml"]
push:
branches: [main]
paths: ["<SITE_DIR>/**", ".github/workflows/site.yml"]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: site-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
WRANGLER_SEND_METRICS: "false"
# Optional: used by builds that need the public URL (canonical, Open Graph).
SITE_URL: ${{ vars.SITE_URL }}
defaults:
run:
working-directory: <SITE_DIR>
jobs:
build:
name: Build and check
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: <SITE_DIR>/.nvmrc
cache: npm
cache-dependency-path: <SITE_DIR>/package-lock.json
- run: npm ci
# Delete any step whose script the project does not have.
- name: Check
run: npm run check --if-present
- name: Test
run: npm test --if-present
- name: Build
run: npm run build
- name: Check the config and bundle without deploying
run: npx wrangler deploy --dry-run --outdir .wrangler/dry-run
deploy:
name: Deploy to Cloudflare
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: production
url: ${{ vars.SITE_URL }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
steps:
- name: Stop if the Cloudflare secrets are missing
working-directory: .
run: |
if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
echo "::error::Add CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as repository secrets."
exit 1
fi
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: <SITE_DIR>/.nvmrc
cache: npm
cache-dependency-path: <SITE_DIR>/package-lock.json
- run: npm ci
- name: Build
run: npm run build
- name: Deploy
run: npx wrangler deploy --message "Deploy ${GITHUB_SHA}"