Deploy site to Cloudflare Pages workflow (jnMetaCode/superpowers-zh)
The Deploy site to Cloudflare Pages workflow from jnMetaCode/superpowers-zh, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Deploy site to Cloudflare Pages workflow from the jnMetaCode/superpowers-zh repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Deploy site to Cloudflare Pages
# 官网自动部署:site/ 或 skills/ 变更时重建并发布。
# 需在仓库 Settings → Secrets 配置 CLOUDFLARE_API_TOKEN 与 CLOUDFLARE_ACCOUNT_ID。
on:
push:
branches: [main]
paths:
- 'site/**'
- 'skills/**'
- '.github/workflows/deploy-site.yml'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
steps:
# Action 全部 SHA 固定(防供应链/标签劫持,因本 job 持有可写的 Cloudflare token)
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 20
- name: Build site
run: node site/build.mjs
# 首次部署前确保 Pages 项目存在(wrangler pages deploy 不会自动创建)。
# 幂等:项目已存在时创建命令报错,由 || 兜住继续。token 需 Pages:Edit 权限。
- name: Ensure Pages project exists
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
npx --yes wrangler@3 pages project create superpowers-zh-site \
--production-branch main \
|| echo "项目已存在或创建跳过,继续部署"
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy site/dist --project-name=superpowers-zh-site
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Deploy site to Cloudflare Pages # 官网自动部署:site/ 或 skills/ 变更时重建并发布。 # 需在仓库 Settings → Secrets 配置 CLOUDFLARE_API_TOKEN 与 CLOUDFLARE_ACCOUNT_ID。 on: push: branches: [main] paths: - 'site/**' - 'skills/**' - '.github/workflows/deploy-site.yml' workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: deploy: timeout-minutes: 30 runs-on: latchkey-small permissions: contents: read deployments: write steps: # Action 全部 SHA 固定(防供应链/标签劫持,因本 job 持有可写的 Cloudflare token) - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: cache: 'npm' node-version: 20 - name: Build site run: node site/build.mjs # 首次部署前确保 Pages 项目存在(wrangler pages deploy 不会自动创建)。 # 幂等:项目已存在时创建命令报错,由 || 兜住继续。token 需 Pages:Edit 权限。 - name: Ensure Pages project exists env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} run: | npx --yes wrangler@3 pages project create superpowers-zh-site \ --production-branch main \ || echo "项目已存在或创建跳过,继续部署" - name: Deploy to Cloudflare Pages uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy site/dist --project-name=superpowers-zh-site
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.