-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathcreate-vinext-app-cloudflare-deploy.yml
More file actions
141 lines (123 loc) · 5.5 KB
/
Copy pathcreate-vinext-app-cloudflare-deploy.yml
File metadata and controls
141 lines (123 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: create-vinext-app Cloudflare Deploy
on:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: cva-cloudflare-deploy-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
# This workflow deploys a fixed Cloudflare Worker using repository secrets.
# Forks still receive pushes to their own main branch, but they do not have
# the canonical repo's Cloudflare credentials.
if: github.repository_owner == 'cloudflare'
name: Deploy and smoke test
runs-on: ubuntu-latest
env:
CVA_CLOUDFLARE_WORKER: create-vinext-app-cloudflare
CVA_CLOUDFLARE_EXPECTED_TEXT: vinext + Cloudflare Workers
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./.github/actions/setup
- name: Build packages
run: vp run build
- name: Pack vinext packages for local install
working-directory: packages/vinext
run: |
vp pm pack --pack-destination "${{ runner.temp }}"
cd ../types
vp pm pack --pack-destination "${{ runner.temp }}"
cd ../workers-response-store
vp pm pack --pack-destination "${{ runner.temp }}"
cd ../cloudflare
vp pm pack --pack-destination "${{ runner.temp }}"
cd ../create-vinext-app
vp pm pack --pack-destination "${{ runner.temp }}"
- name: Scaffold a fresh create-vinext-app project
working-directory: ${{ runner.temp }}
run: >-
npx --yes
--package "${{ runner.temp }}"/create-vinext-app-*.tgz
create-vinext-app "${{ runner.temp }}/cva-cloudflare"
--yes
--skip-install
--disable-git
--platform=cloudflare
--cdn-cache=response-store
--image-optimization=cloudflare-images
- name: Pin pnpm in scaffolded project to vinext's version
working-directory: ${{ runner.temp }}/cva-cloudflare
run: |
PKG_MGR=$(cd "${{ github.workspace }}" && node -p "require('./package.json').packageManager")
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
pkg.packageManager = '$PKG_MGR';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Allow required native dependency builds
working-directory: ${{ runner.temp }}/cva-cloudflare
run: |
node -e '
const fs = require("fs");
const f = "pnpm-workspace.yaml";
let y = fs.existsSync(f) ? fs.readFileSync(f, "utf8") : "";
y = y.replace(/allowBuilds:[\s\S]*?(?=\n\S|\n*$)/, "");
y = y.trimEnd() + "\n\nallowBuilds:\n esbuild: true\n sharp: true\n unrs-resolver: true\n workerd: true\n";
fs.writeFileSync(f, y);
'
- name: Install local vinext packages
working-directory: ${{ runner.temp }}/cva-cloudflare
run: |
node "$GITHUB_WORKSPACE/scripts/configure-local-vinext-types.mjs" "${{ runner.temp }}"
vp add "${{ runner.temp }}"/vinext-[0-9]*.tgz "${{ runner.temp }}"/cloudflare-workers-response-store-*.tgz "${{ runner.temp }}"/vinext-cloudflare-*.tgz
- name: Configure generated Cloudflare deployment
working-directory: ${{ runner.temp }}/cva-cloudflare
run: |
node -e '
const fs = require("node:fs");
const configPath = "wrangler.jsonc";
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
config.name = process.env.CVA_CLOUDFLARE_WORKER;
config.preview_urls = true;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
'
- name: Build generated Cloudflare project
working-directory: ${{ runner.temp }}/cva-cloudflare
run: vp exec vinext build
- name: Verify generated Cloudflare build output
working-directory: ${{ runner.temp }}/cva-cloudflare
run: |
test -f dist/server/wrangler.json
test -f wrangler.response-store.jsonc
- name: Deploy generated Workers Response Store
working-directory: ${{ runner.temp }}/cva-cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: node "$GITHUB_WORKSPACE/.github/scripts/wrangler-deploy.mjs" --config wrangler.response-store.jsonc
- name: Deploy generated Cloudflare project
working-directory: ${{ runner.temp }}/cva-cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: vp exec vinext-cloudflare deploy --skip-build
- name: Smoke test generated Cloudflare deployment
run: |
URL="https://${CVA_CLOUDFLARE_WORKER}.vinext.workers.dev/"
BODY_FILE="$(mktemp)"
trap 'rm -f "$BODY_FILE"' EXIT
for attempt in $(seq 1 45); do
STATUS=$(curl -sS -o "$BODY_FILE" -w "%{http_code}" -L --max-time 10 "$URL" || echo "000")
echo "HTTP status from ${URL}: ${STATUS} (attempt ${attempt})"
if [ "$STATUS" = "200" ] && grep -qiF "$CVA_CLOUDFLARE_EXPECTED_TEXT" "$BODY_FILE"; then
exit 0
fi
sleep 2
done
echo "Generated Cloudflare deployment did not return expected content"
exit 1