Files
warmbly/.github/workflows/marketing-pages.yml
T

121 lines
5.0 KiB
YAML

name: Deploy marketing Pages
on:
pull_request:
paths:
- '.github/workflows/marketing-pages.yml'
- '.github/scripts/pages-*'
workflow_dispatch:
inputs:
expected_sha:
description: Reviewed main commit to deploy (full SHA)
required: true
type: string
permissions:
contents: read
concurrency:
group: ${{ github.event_name == 'workflow_dispatch' && 'release' || format('marketing-pages-check-{0}', github.ref) }}
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
- run: node --test .github/scripts/pages-*.test.mjs
deploy:
needs: check
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && vars.CLOUDFLARE_PAGES_DEPLOY_ENABLED == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
environment: site-production
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
PAGES_APP: site
WRANGLER_SEND_METRICS: "false"
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Require the reviewed main commit
env:
EXPECTED_SHA: ${{ inputs.expected_sha }}
run: test "$EXPECTED_SHA" = "$GITHUB_SHA"
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
- name: Select only the configured marketing project
env:
CLOUDFLARE_PAGES_PROJECTS: ${{ vars.CLOUDFLARE_PAGES_PROJECTS }}
run: |
node --input-type=module <<'JS'
import { appendFileSync } from 'node:fs';
import { deploymentMatrix } from './.github/scripts/pages-projects.mjs';
const sites = deploymentMatrix(process.env.CLOUDFLARE_PAGES_PROJECTS).include.filter(target => target.app === 'site');
if (sites.length !== 1) throw new Error('Configure exactly one marketing Pages project');
appendFileSync(process.env.GITHUB_ENV, `CLOUDFLARE_PAGES_PROJECT_NAME=${sites[0].project}\n`);
JS
- name: Load existing marketing production configuration
id: config
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
for name in CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID CLOUDFLARE_PAGES_PROJECT_NAME; do
test -n "${!name}"
done
curl --fail --silent --show-error \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PAGES_PROJECT_NAME" \
| node .github/scripts/pages-production-config.mjs
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
with:
version: "11.9.0"
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
cache: pnpm
cache-dependency-path: site/pnpm-lock.yaml
- name: Install marketing dependencies
working-directory: site
run: pnpm install --frozen-lockfile
- name: Check marketing behavior and CSP
working-directory: site
run: pnpm test
- name: Build marketing with production configuration
working-directory: site
run: pnpm build
- name: Deploy an isolated preview
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
PREVIEW_BRANCH: marketing-check-${{ github.run_id }}-${{ github.run_attempt }}
PRODUCTION_BRANCH: ${{ steps.config.outputs.production_branch }}
WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/marketing-preview-${{ github.run_id }}-${{ github.run_attempt }}.ndjson
run: |
test "$PREVIEW_BRANCH" != "$PRODUCTION_BRANCH"
test ! -e "$WRANGLER_OUTPUT_FILE_PATH"
pnpm dlx wrangler@4.45.0 pages deploy site/dist \
--project-name "$CLOUDFLARE_PAGES_PROJECT_NAME" \
--branch "$PREVIEW_BRANCH" --commit-hash "$GITHUB_SHA"
- name: Verify preview responses before production
env:
WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/marketing-preview-${{ github.run_id }}-${{ github.run_attempt }}.ndjson
run: node .github/scripts/pages-marketing-preview.mjs
- name: Publish the verified marketing artifact
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
PRODUCTION_BRANCH: ${{ steps.config.outputs.production_branch }}
run: |
pnpm dlx wrangler@4.45.0 pages deploy site/dist \
--project-name "$CLOUDFLARE_PAGES_PROJECT_NAME" \
--branch "$PRODUCTION_BRANCH" --commit-hash "$GITHUB_SHA" \
--commit-message "Marketing $GITHUB_SHA"