From 0b9e1d46fbaaa1f9c513540b109dc8b64a0905ea Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Tue, 1 Dec 2026 12:14:56 +0900 Subject: [PATCH 1/3] build: enable version URLs on the website worker The preview workflow publishes per-branch aliases, which Cloudflare only serves while version URLs are enabled. workers_dev stays off, so the production route is unchanged. Co-Authored-By: Claude --- wrangler.jsonc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wrangler.jsonc b/wrangler.jsonc index 0f57c13..82226d4 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -10,5 +10,7 @@ // pulsate-dev/infra manages, so cutover and rollback need no DNS change. "routes": [{ "pattern": "pulsate.dev/*", "zone_name": "pulsate.dev" }], "workers_dev": false, - "preview_urls": false, + // Version URLs stay on so preview.yaml can publish per-branch aliases; the + // production route is unaffected by them. + "preview_urls": true, } From e2e019c79692dfb5fb324086008a82efd8fb1e76 Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Tue, 1 Dec 2026 12:14:56 +0900 Subject: [PATCH 2/3] feat(ci): add per-branch preview build for pull requests Pull requests had no way to be checked on Cloudflare before merging. Upload each PR as a Worker version with a branch-derived alias and keep a single comment on the PR pointing at its URL. Co-Authored-By: Claude --- .github/workflows/preview.yaml | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/preview.yaml diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml new file mode 100644 index 0000000..0d1d744 --- /dev/null +++ b/.github/workflows/preview.yaml @@ -0,0 +1,88 @@ +name: Preview + +on: + pull_request: + branches: + - main + types: [opened, synchronize, reopened] + +permissions: + contents: read + pull-requests: write + +concurrency: + group: preview-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + preview: + # Fork PRs get no secrets, so a preview upload cannot work for them. + if: github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6 + + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build + run: pnpm run build + + # Aliases allow only [a-z0-9-], must start with a letter, and + # "-website" must fit in a 63-character DNS label. + - name: Compute alias + id: alias + env: + BRANCH: ${{ github.head_ref }} + run: | + alias=$(printf '%s' "$BRANCH" | tr 'A-Z' 'a-z' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//') + case "$alias" in + [a-z]*) ;; + *) alias="b-$alias" ;; + esac + alias=$(printf '%s' "${alias:0:54}" | sed -E 's/-+$//') + echo "alias=$alias" >> "$GITHUB_OUTPUT" + + # Why npx instead of cloudflare/wrangler-action: see deploy.yaml. + - name: Upload version + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/wrangler-output.ndjson + ALIAS: ${{ steps.alias.outputs.alias }} + run: npx --yes wrangler@4.158.0 versions upload --preview-alias "$ALIAS" + + - name: Read preview URL + id: url + env: + OUTPUT: ${{ runner.temp }}/wrangler-output.ndjson + run: | + url=$(jq -r 'select(.type == "version-upload") | .preview_alias_url // empty' "$OUTPUT" | tail -n 1) + if [ -z "$url" ]; then + echo "::error::No preview alias URL in wrangler output" + cat "$OUTPUT" + exit 1 + fi + echo "url=$url" >> "$GITHUB_OUTPUT" + + - name: Comment on PR + env: + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} + URL: ${{ steps.url.outputs.url }} + SHA: ${{ github.event.pull_request.head.sha }} + run: | + marker='' + body=$(printf '%s\n**Preview build is ready**\n\n- URL: %s\n- Commit: %s' "$marker" "$URL" "$SHA") + id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \ + --jq "[.[] | select(.body | startswith(\"$marker\"))][0].id // empty") + if [ -n "$id" ]; then + gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$id" -f body="$body" + else + gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$body" + fi From 888f5338f5c117df745344eb10e644913fe4165f Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Tue, 1 Dec 2026 13:06:15 +0900 Subject: [PATCH 3/3] ci: explain how to fix a missing preview URL The upload succeeds but yields no alias URL when Preview URLs are off on the Worker or the account has no workers.dev subdomain, and the bare error gave no hint about either cause. Co-Authored-By: Claude --- .github/workflows/preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 0d1d744..e3a5f78 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -64,7 +64,7 @@ jobs: run: | url=$(jq -r 'select(.type == "version-upload") | .preview_alias_url // empty' "$OUTPUT" | tail -n 1) if [ -z "$url" ]; then - echo "::error::No preview alias URL in wrangler output" + echo "::error::No preview alias URL in wrangler output. Check that Preview URLs are enabled on the website Worker and the account has a workers.dev subdomain." cat "$OUTPUT" exit 1 fi