-
Notifications
You must be signed in to change notification settings - Fork 897
190 lines (163 loc) · 6.69 KB
/
Copy pathvercel-deploy-e2e.yml
File metadata and controls
190 lines (163 loc) · 6.69 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Vercel Deploy E2E
on:
workflow_dispatch:
schedule:
- cron: '15 6 * * *'
jobs:
deployed-api-chat:
name: Deployed /api/chat E2E
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- name: Check required secrets
id: secrets_check
shell: bash
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
set -euo pipefail
if [[ -z "${VERCEL_TOKEN:-}" || -z "${OPENAI_API_KEY:-}" ]]; then
echo "missing=true" >> "$GITHUB_OUTPUT"
echo "Required secrets (VERCEL_TOKEN, OPENAI_API_KEY) are missing; skipping deploy E2E."
else
echo "missing=false" >> "$GITHUB_OUTPUT"
fi
- name: Deploy temporary app and test /api/chat
if: steps.secrets_check.outputs.missing == 'false'
shell: bash
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }}
VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
NEXT_TELEMETRY_DISABLED: '1'
run: |
set -euo pipefail
WORKDIR="$(mktemp -d)"
cd "$WORKDIR"
mkdir -p app/api/chat
cat > package.json <<'JSON'
{
"name": "cascadeflow-vercel-e2e",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"build": "next build"
},
"dependencies": {
"@cascadeflow/core": "latest",
"@cascadeflow/vercel-ai": "latest",
"@ai-sdk/react": "^3.0.0",
"ai": "^6.0.0",
"next": "^16.1.6",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"typescript": "^5.9.3",
"@types/react": "^19.2.4",
"@types/node": "^22.13.10"
}
}
JSON
cat > tsconfig.json <<'JSON'
{
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{ "name": "next" }]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
JSON
cat > next-env.d.ts <<'TS'
/// <reference types="next" />
/// <reference types="next/image-types/global" />
TS
cat > app/page.tsx <<'TSX'
export default function Page() {
return <main>cascadeflow vercel e2e</main>;
}
TSX
cat > app/api/chat/route.ts <<'TS'
import { CascadeAgent } from '@cascadeflow/core';
import { createChatHandler } from '@cascadeflow/vercel-ai';
export const runtime = 'edge';
const agent = new CascadeAgent({
models: [
{ name: 'gpt-4o-mini', provider: 'openai', cost: 0.00015, apiKey: process.env.OPENAI_API_KEY },
{ name: 'gpt-4o', provider: 'openai', cost: 0.00625, apiKey: process.env.OPENAI_API_KEY }
]
});
const handler = createChatHandler(agent, { protocol: 'data' });
export async function POST(req: Request) {
return handler(req);
}
TS
PROJECT_NAME="cf-vercel-e2e-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
TEAM_QS=""
if [[ -n "${VERCEL_TEAM_ID:-}" ]]; then
TEAM_QS="?teamId=${VERCEL_TEAM_ID}"
fi
CREATE_RESP=$(curl -sS -X POST "https://api.vercel.com/v10/projects${TEAM_QS}" \
-H "Authorization: Bearer ${VERCEL_TOKEN}" \
-H "Content-Type: application/json" \
--data "{\"name\":\"${PROJECT_NAME}\",\"framework\":\"nextjs\"}")
PROJECT_ID=$(node -e "const r=JSON.parse(process.argv[1]); if(!r.id){console.error(JSON.stringify(r)); process.exit(1)}; process.stdout.write(r.id);" "$CREATE_RESP")
cleanup() {
curl -sS -X DELETE "https://api.vercel.com/v9/projects/${PROJECT_ID}${TEAM_QS}" \
-H "Authorization: Bearer ${VERCEL_TOKEN}" >/dev/null || true
}
trap cleanup EXIT
# Disable deployment protection on the sandbox project so direct /api/chat checks work.
curl -sS -X PATCH "https://api.vercel.com/v10/projects/${PROJECT_ID}${TEAM_QS}" \
-H "Authorization: Bearer ${VERCEL_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"ssoProtection":null}' >/dev/null
ENV_PAYLOAD=$(node -e "const key=process.argv[1]; console.log(JSON.stringify([{type:'encrypted',key:'OPENAI_API_KEY',value:key,target:['preview','production']}]));" "$OPENAI_API_KEY")
curl -sS -X POST "https://api.vercel.com/v10/projects/${PROJECT_ID}/env${TEAM_QS}" \
-H "Authorization: Bearer ${VERCEL_TOKEN}" \
-H "Content-Type: application/json" \
--data "$ENV_PAYLOAD" >/dev/null
pnpm install --silent
SCOPE_ARGS=()
if [[ -n "${VERCEL_SCOPE:-}" ]]; then
SCOPE_ARGS=(--scope "${VERCEL_SCOPE}")
fi
pnpm dlx vercel@latest link --yes --project "${PROJECT_NAME}" --token "${VERCEL_TOKEN}" "${SCOPE_ARGS[@]}" >/dev/null
DEPLOY_URL=$(pnpm dlx vercel@latest deploy --yes --token "${VERCEL_TOKEN}" "${SCOPE_ARGS[@]}" | tail -n 1 | tr -d '\r')
if [[ "$DEPLOY_URL" != http* ]]; then
DEPLOY_URL="https://${DEPLOY_URL}"
fi
RESP=$(curl -sS -X POST "${DEPLOY_URL}/api/chat" \
-H "content-type: application/json" \
--data '{"messages":[{"role":"user","content":"Reply with exactly: cascadeflow-ok"}]}')
TEXT=$(printf '%s' "$RESP" | awk -F'"' '/^0:/{printf "%s", $2}')
if [[ "$TEXT" != *"cascadeflow-ok"* ]]; then
echo "Unexpected response payload:"
echo "$RESP"
exit 1
fi
echo "Deployment URL: ${DEPLOY_URL}"
echo "Verified /api/chat streamed text: ${TEXT}"