|
| 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" |
0 commit comments