Skip to content

Commit 81ef602

Browse files
authored
fix(ci): deploy scaffolded Cloudflare Build Output (#3527)
* fix(ci): deploy scaffolded Cloudflare Build Output * fix(ci): support auto-provisioned KV scaffold bindings
1 parent 97638af commit 81ef602

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎.github/workflows/create-next-app-cloudflare-deploy.yml‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
working-directory: ${{ runner.temp }}/cna-cloudflare
8181
run: >-
8282
vp exec vinext init --skip-check --platform=cloudflare
83+
--cdn-cache=data-cache
8384
--data-cache=kv
8485
--image-optimization=cloudflare-images
8586
@@ -88,16 +89,18 @@ jobs:
8889
run: |
8990
node -e '
9091
const fs = require("node:fs");
91-
const configPath = "wrangler.jsonc";
92-
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
93-
config.name = process.env.CNA_CLOUDFLARE_WORKER;
94-
config.preview_urls = true;
95-
for (const namespace of config.kv_namespaces ?? []) {
96-
if (namespace.binding === "VINEXT_KV_CACHE") {
97-
namespace.id = process.env.CNA_CLOUDFLARE_KV_NAMESPACE_ID;
98-
}
99-
}
100-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
92+
const configPath = "cloudflare.config.ts";
93+
const config = fs.readFileSync(configPath, "utf8")
94+
.replace(
95+
"name: \"cna-cloudflare\",",
96+
"name: " + JSON.stringify(process.env.CNA_CLOUDFLARE_WORKER) + ",\n previewUrls: true,",
97+
)
98+
// Reuse the CI namespace even when init emits bindings.kv().
99+
.replace(
100+
/VINEXT_KV_CACHE: bindings\.kv\([^)]*\)/,
101+
"VINEXT_KV_CACHE: bindings.kv({ id: " + JSON.stringify(process.env.CNA_CLOUDFLARE_KV_NAMESPACE_ID) + " })",
102+
);
103+
fs.writeFileSync(configPath, config);
101104
'
102105
103106
- name: Build generated Cloudflare project
@@ -106,7 +109,11 @@ jobs:
106109

107110
- name: Verify generated Cloudflare build output
108111
working-directory: ${{ runner.temp }}/cna-cloudflare
109-
run: test -f dist/server/wrangler.json
112+
run: |
113+
test -f cloudflare.config.ts
114+
test -f .cloudflare/output/v0/config.json
115+
test -f .cloudflare/output/v0/workers/default/worker.config.json
116+
test ! -f wrangler.jsonc
110117
111118
- name: Deploy generated Cloudflare project
112119
working-directory: ${{ runner.temp }}/cna-cloudflare

‎.github/workflows/create-vinext-app-cloudflare-deploy.yml‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ jobs:
9191
run: |
9292
node -e '
9393
const fs = require("node:fs");
94-
const configPath = "wrangler.jsonc";
95-
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
96-
config.name = process.env.CVA_CLOUDFLARE_WORKER;
97-
config.preview_urls = true;
98-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
94+
const configPath = "cloudflare.config.ts";
95+
const config = fs.readFileSync(configPath, "utf8").replace(
96+
"name: \"cva-cloudflare\",",
97+
"name: " + JSON.stringify(process.env.CVA_CLOUDFLARE_WORKER) + ",\n previewUrls: true,",
98+
);
99+
fs.writeFileSync(configPath, config);
99100
'
100101
101102
- name: Build generated Cloudflare project
@@ -105,15 +106,19 @@ jobs:
105106
- name: Verify generated Cloudflare build output
106107
working-directory: ${{ runner.temp }}/cva-cloudflare
107108
run: |
108-
test -f dist/server/wrangler.json
109-
test -f wrangler.response-store.jsonc
109+
test -f cloudflare.config.ts
110+
test -f .cloudflare/output/v0/config.json
111+
test -f .cloudflare/output/v0/workers/default/worker.config.json
112+
test -f .cloudflare/output/v0/workers/cva-cloudflare-response-store/worker.config.json
113+
test ! -f wrangler.jsonc
114+
test ! -f wrangler.response-store.jsonc
110115
111116
- name: Deploy generated Workers Response Store
112117
working-directory: ${{ runner.temp }}/cva-cloudflare
113118
env:
114119
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
115120
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
116-
run: node "$GITHUB_WORKSPACE/.github/scripts/wrangler-deploy.mjs" --config wrangler.response-store.jsonc
121+
run: vp run deploy:response-store
117122

118123
- name: Deploy generated Cloudflare project
119124
working-directory: ${{ runner.temp }}/cva-cloudflare

0 commit comments

Comments
 (0)