Skip to content

The agent that turns websites into APIs!

ci: deploy website previews and production to Cloudflare Pages (#126)

kalil0321fbb142b0a528
diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml
new file mode 100644
index 0000000..efd3530
--- /dev/null
+++ b/.github/workflows/website.yml
@@ -0,0 +1,81 @@
+name: Deploy website
+
+on:
+ push:
+ branches:
+ - '**'
+ paths:
+ - 'website/**'
+ - '.github/workflows/website.yml'
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: website-${{ github.ref }}
+ # Finish production deployments; replace outdated previews on the same branch.
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
+
+jobs:
+ deploy:
+ name: Build and deploy
+ if: github.ref_type == 'branch'
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ permissions:
+ contents: read
+ deployments: write
+ defaults:
+ run:
+ working-directory: website
+ env:
+ NEXT_TELEMETRY_DISABLED: '1'
+ WRANGLER_SEND_METRICS: 'false'
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v6
+ with:
+ persist-credentials: false
+
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ version: 10.17.1
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v6
+ with:
+ node-version: '22'
+ cache: pnpm
+ cache-dependency-path: website/pnpm-lock.yaml
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Build static site
+ run: pnpm build
+
+ - name: Deploy to Cloudflare Pages
+ id: deploy
+ uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
+ with:
+ apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
+ gitHubToken: ${{ secrets.GITHUB_TOKEN }}
+ workingDirectory: website
+ # Wrangler reads the checked-out branch: main is production,
+ # every other branch gets a preview in the same Pages project.
+ command: pages deploy out --project-name=reverse-api-engineer
+
+ - name: Add deployment links to summary
+ env:
+ DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
+ BRANCH_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
+ run: |
+ printf '### Website deployment\n\n' >> "$GITHUB_STEP_SUMMARY"
+ printf '[Open deployment](%s)\n' "$DEPLOYMENT_URL" >> "$GITHUB_STEP_SUMMARY"
+ if [ -n "$BRANCH_URL" ]; then
+ printf '\n[Open branch preview](%s)\n' "$BRANCH_URL" >> "$GITHUB_STEP_SUMMARY"
+ fi
diff --git a/website/README.md b/website/README.md
index fc41306..f877f96 100644
--- a/website/README.md
+++ b/website/README.md
@@ -62,9 +62,52 @@ pnpm pages:deploy
First-time setup:
1. `pnpm wrangler login`
-2. Edit `name` in `wrangler.jsonc` if you want a different Pages project name.
+2. If the Pages project does not exist yet, create it with
+ `pnpm exec wrangler pages project create reverse-api-engineer --production-branch main`.
3. Optional: attach a custom domain via the Cloudflare dashboard.
+### Automatic deployments (GitHub Actions)
+
+The [`Deploy website` workflow](../.github/workflows/website.yml) builds with
+Node.js 22 and pnpm 10.17.1, installs the committed lockfile, and uploads `out/`
+to the existing `reverse-api-engineer` Pages project.
+
+- Pushes that change `website/**` or the workflow itself trigger a deployment.
+- Every branch other than `main` gets a preview. Its stable branch alias points
+ to the latest deployment; the production site stays unchanged.
+- Pushes to `main`, including merged pull requests, update production and its
+ custom domains when those paths changed.
+- Deployment and branch-preview links appear in the Actions run summary and
+ GitHub's deployment status. No pull request is required for a branch preview.
+- **Actions > Deploy website > Run workflow** can redeploy a selected branch
+ manually, even without a website change, once the workflow exists on `main`.
+
+One-time configuration:
+
+1. In the repository's **Settings > Secrets and variables > Actions**, add these
+ repository secrets:
+
+ | Secret | Value |
+ |--------|-------|
+ | `CLOUDFLARE_API_TOKEN` | API token with **Account > Cloudflare Pages > Edit**, scoped to the account that owns the project. |
+ | `CLOUDFLARE_ACCOUNT_ID` | That Cloudflare account's ID. |
+
+2. Confirm the Pages project's **production branch is `main`**. Cloudflare uses
+ this setting to distinguish production from preview deployments. For an
+ existing Direct Upload project, follow the
+ [production-branch configuration instructions](https://developers.cloudflare.com/pages/get-started/direct-upload/#production-branch-configuration).
+3. If the Pages project also uses Cloudflare's Git integration, disable its
+ automatic production and preview builds to avoid duplicate deployments;
+ this workflow handles both through Wrangler.
+
+The workflow runs on branch pushes in this repository. Fork pull requests do
+not receive deployment credentials or publish previews in this account.
+If you rename the Pages project, update both `wrangler.jsonc` and the workflow's
+`--project-name` argument.
+
+See Cloudflare's [CI deployment guide](https://developers.cloudflare.com/pages/how-to/use-direct-upload-with-continuous-integration/)
+and [preview deployment documentation](https://developers.cloudflare.com/pages/configuration/preview-deployments/).
+
## Why static export?
The site has no server-side runtime needs:
diff --git a/website/wrangler.jsonc b/website/wrangler.jsonc
index 15065e1..47a6ca9 100644
--- a/website/wrangler.jsonc
+++ b/website/wrangler.jsonc
@@ -10,7 +10,9 @@
*
* First-time setup:
* 1. pnpm wrangler login
- * 2. (Optional) rename `pages_build_output_dir` project via the dashboard
+ * 2. Create the project if needed:
+ * pnpm exec wrangler pages project create reverse-api-engineer --production-branch main
+ * 3. See README.md for the GitHub Actions secrets and production branch setup.
*/
{
"$schema": "node_modules/wrangler/config-schema.json",