Skip to content

Commit 9155de4

Browse files
hugo-ccabralclaude
andcommitted
ci(fast-deploy): GitHub Action to sync .deco/blocks to KV on content commits
Content-only commits are excluded from Cloudflare Workers Builds, so they never redeploy. This workflow (push to main, paths: .deco/blocks/**) writes the snapshot to KV via deco-sync-blocks-to-kv and purges affected pages. Adds a sync:kv package script for local/CI reuse. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e9f1588 commit 9155de4

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Fast deploy — sync content to KV
2+
3+
# Content-only commits (.deco/blocks/**) are EXCLUDED from Cloudflare Workers
4+
# Builds via the worker's "Build watch paths", so they never redeploy the worker.
5+
# This workflow is the ONE place that pushes those content changes into
6+
# Cloudflare KV (the worker reads KV-first) and purges the edge cache for the
7+
# affected pages. Code deploys stay on Cloudflare Builds — the two never overlap.
8+
#
9+
# Required GitHub secrets:
10+
# CF_ACCOUNT_ID Cloudflare account id
11+
# CF_KV_NAMESPACE_ID the site's DECO_KV namespace id
12+
# CF_API_TOKEN token with "Workers KV Storage: Edit"
13+
# PURGE_TOKEN must equal the worker's PURGE_TOKEN env var
14+
# Required GitHub variable (Settings → Secrets and variables → Variables):
15+
# SITE_ORIGIN the live origin, e.g. https://www.example.com
16+
17+
on:
18+
push:
19+
branches: [main]
20+
paths:
21+
- ".deco/blocks/**"
22+
23+
concurrency:
24+
group: sync-content-to-kv
25+
cancel-in-progress: false # never interrupt an in-flight KV write
26+
27+
jobs:
28+
sync:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0 # need history to diff against the previous commit
34+
35+
- uses: oven-sh/setup-bun@v2
36+
37+
- run: bun install --frozen-lockfile
38+
39+
- name: Sync .deco/blocks → Cloudflare KV (+ purge changed pages)
40+
env:
41+
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
42+
CF_KV_NAMESPACE_ID: ${{ secrets.CF_KV_NAMESPACE_ID }}
43+
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
44+
PURGE_TOKEN: ${{ secrets.PURGE_TOKEN }}
45+
SITE_ORIGIN: ${{ vars.SITE_ORIGIN }}
46+
BEFORE_SHA: ${{ github.event.before }}
47+
run: |
48+
# A brand-new branch or a force-push reports an all-zero parent SHA —
49+
# there's nothing to diff against, so sync the whole snapshot instead.
50+
if [ -z "$BEFORE_SHA" ] || [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
51+
RANGE_ARGS="--all"
52+
else
53+
RANGE_ARGS="--since $BEFORE_SHA"
54+
fi
55+
bun node_modules/@decocms/start/scripts/sync-blocks-to-kv.ts \
56+
--write $RANGE_ARGS \
57+
--purge-url "$SITE_ORIGIN" \
58+
--purge-token "$PURGE_TOKEN"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build": "npm run generate:blocks && npm run generate:sections && npm run generate:loaders && npm run generate:schema && tsr generate && vite build",
1616
"preview": "vite preview",
1717
"deploy": "npm run build && wrangler deploy",
18+
"sync:kv": "bun node_modules/@decocms/start/scripts/sync-blocks-to-kv.ts",
1819
"types": "wrangler types",
1920
"typecheck": "tsc --noEmit",
2021
"format": "prettier --write \"src/**/*.{ts,tsx}\"",

0 commit comments

Comments
 (0)