Skip to content

Commit bed81e7

Browse files
committed
ci: add cf-typegen step and automatic PR preview comment with Cloudflare preview URL
1 parent ae87e5c commit bed81e7

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ jobs:
3030
# Generates apps/sanity/extract.json and the site's types.gen.ts, both of
3131
# which are derived artifacts and therefore gitignored. Runs before
3232
# typecheck because the site imports the generated types.
33-
- name: Typegen
33+
- name: Typegen (Sanity)
3434
run: pnpm typegen
3535
env:
3636
SANITY_STUDIO_PROJECT_ID: hfh83o0w
3737
SANITY_STUDIO_DATASET: production
3838

39+
- name: Typegen (Cloudflare)
40+
run: pnpm --filter @codingcatdev/site cf-typegen
41+
3942
- name: Lint (site)
4043
run: pnpm --filter @codingcatdev/site lint
4144

@@ -54,6 +57,9 @@ jobs:
5457
SANITY_STUDIO_PROJECT_ID: hfh83o0w
5558
SANITY_STUDIO_DATASET: production
5659

60+
- name: Run E2E Tests
61+
run: pnpm --filter @codingcatdev/site test:e2e
62+
5763
# extract.json is committed and is the single source of truth for typegen.
5864
# The Typegen step above regenerates it; if that changed the file, the
5965
# commit is stale. This is what stopped three divergent copies before.
@@ -91,6 +97,9 @@ jobs:
9197
SANITY_STUDIO_PROJECT_ID: hfh83o0w
9298
SANITY_STUDIO_DATASET: dev
9399

100+
- name: Generate Cloudflare Types
101+
run: pnpm --filter @codingcatdev/site cf-typegen
102+
94103
- name: Build site (preview)
95104
run: pnpm --filter @codingcatdev/site build
96105

@@ -99,7 +108,32 @@ jobs:
99108
run: |
100109
OUTPUT=$(pnpm --filter @codingcatdev/site exec wrangler versions upload --tag "pr-${{ github.event.pull_request.number }}" --message "PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}")
101110
echo "$OUTPUT"
111+
112+
PREVIEW_URL=$(echo "$OUTPUT" | grep -i "Version Preview URL:" | awk '{print $NF}' | head -n 1)
113+
VERSION_ID=$(echo "$OUTPUT" | grep -i "Worker Version ID:" | awk '{print $NF}' | head -n 1)
114+
115+
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
116+
echo "version_id=$VERSION_ID" >> $GITHUB_OUTPUT
117+
118+
echo "### ⚡ Cloudflare Worker Preview Ready" >> $GITHUB_STEP_SUMMARY
119+
echo "" >> $GITHUB_STEP_SUMMARY
120+
echo "- **Preview URL**: [${PREVIEW_URL}](${PREVIEW_URL})" >> $GITHUB_STEP_SUMMARY
121+
echo "- **Version ID**: \`${VERSION_ID}\`" >> $GITHUB_STEP_SUMMARY
122+
echo "- **Target Worker**: \`codingcatdev-dev\`" >> $GITHUB_STEP_SUMMARY
123+
124+
if [ -n "$PREVIEW_URL" ]; then
125+
gh pr comment ${{ github.event.pull_request.number }} --body "### ⚡ Cloudflare Worker Preview Ready!
126+
127+
| Environment | URL |
128+
|---|---|
129+
| **PR Preview** | [${PREVIEW_URL}](${PREVIEW_URL}) |
130+
| **Dev Custom Domain** | [https://dev.codingcat.dev](https://dev.codingcat.dev) |
131+
132+
- **Worker Version ID**: \`${VERSION_ID}\`
133+
- **Protection**: Restricted to \`@codingcat.dev\` accounts via Cloudflare Zero Trust Access"
134+
fi
102135
env:
103136
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
104137
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID || 'c46bd0f3b9ed47b8692cca098030edbf' }}
138+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105139

‎.github/workflows/deploy-workers.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
SANITY_STUDIO_PROJECT_ID: hfh83o0w
3737
SANITY_STUDIO_DATASET: dev
3838

39+
- name: Generate Cloudflare Types
40+
run: pnpm --filter @codingcatdev/site cf-typegen
41+
3942
- name: Build site (dev)
4043
run: pnpm --filter @codingcatdev/site build
4144

@@ -67,6 +70,9 @@ jobs:
6770
SANITY_STUDIO_PROJECT_ID: hfh83o0w
6871
SANITY_STUDIO_DATASET: production
6972

73+
- name: Generate Cloudflare Types
74+
run: pnpm --filter @codingcatdev/site cf-typegen
75+
7076
- name: Build site (production)
7177
run: pnpm --filter @codingcatdev/site build:production
7278

0 commit comments

Comments
 (0)