-
Notifications
You must be signed in to change notification settings - Fork 0
217 lines (203 loc) · 8.16 KB
/
e2e-api.yml
File metadata and controls
217 lines (203 loc) · 8.16 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# E2E API - Venom API tests on Vercel preview deploys
# Trigger: deployment_status (Vercel webhook)
# Parallel: runs alongside e2e-web on preview deploy
name: e2e-api
on:
deployment_status:
permissions:
contents: read
pull-requests: read
jobs:
api-tests:
if: >
github.event.deployment_status.state == 'success' &&
github.event.deployment_status.environment_url != '' &&
(startsWith(github.event.deployment_status.environment_url, 'https://') ||
startsWith(github.event.deployment_status.environment_url, 'http://')) &&
(github.event.deployment.environment == 'Preview' || github.event.deployment.environment == 'preview')
runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 20
steps:
- name: Check for doc-only changes
id: doc_check
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const sha =
context.payload.deployment?.sha ??
context.payload.deployment_status?.deployment?.sha;
if (!sha) {
core.warning("No deployment SHA found; running tests.");
core.setOutput("run_tests", "true");
return;
}
let prs = [];
try {
const response =
await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: sha,
});
prs = response.data ?? [];
} catch (error) {
core.warning(`Failed to resolve PR for ${sha}: ${error.message}`);
core.setOutput("run_tests", "true");
return;
}
if (!prs.length) {
core.notice(`No PR found for ${sha}; running tests.`);
core.setOutput("run_tests", "true");
return;
}
const pr = prs[0];
const prNumber = pr.number;
const isBumpPr =
pr.title?.startsWith("chore: bump version") ||
pr.head?.ref?.startsWith("chore/bump-version");
if (isBumpPr) {
core.notice("Bump PR detected; skipping E2E API tests.");
core.setOutput("run_tests", "false");
return;
}
const files = await github.paginate(
github.rest.pulls.listFiles,
{ owner, repo, pull_number: prNumber, per_page: 100 }
);
const docOnly = files.every(
(file) =>
file.filename === "README.md" ||
file.filename === "AGENTS.md" ||
file.filename.startsWith("docs/") ||
file.filename.startsWith(".codex/") ||
file.filename.startsWith("packages/opencode-excalidraw/") ||
file.filename.startsWith(".github/workflows/opencode-excalidraw-")
);
core.setOutput("run_tests", docOnly ? "false" : "true");
if (docOnly) {
core.notice("Docs-only change; skipping E2E API tests.");
}
- name: Checkout
if: steps.doc_check.outputs.run_tests == 'true'
uses: actions/checkout@v4
- name: Setup Bun
if: steps.doc_check.outputs.run_tests == 'true'
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.5"
- name: Install Dependencies
if: steps.doc_check.outputs.run_tests == 'true'
run: bun install --frozen-lockfile
- name: Install Playwright browsers
if: steps.doc_check.outputs.run_tests == 'true'
run: ./packages/backend/node_modules/.bin/playwright install --with-deps
- name: Install Venom
if: steps.doc_check.outputs.run_tests == 'true'
run: |
curl -L -o venom https://github.com/ovh/venom/releases/download/v1.3.0/venom.linux-amd64
chmod +x venom
sudo mv venom /usr/local/bin/
- name: Run API tests
if: steps.doc_check.outputs.run_tests == 'true'
env:
BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
SKETCHI_E2E_EMAIL: ${{ secrets.SKETCHI_E2E_EMAIL }}
SKETCHI_E2E_PASSWORD: ${{ secrets.SKETCHI_E2E_PASSWORD }}
VENOM_VAR_target_url: ${{ github.event.deployment_status.environment_url }}
VENOM_VAR_bypass_secret: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
run: |
if [ -z "$BYPASS_SECRET" ]; then
echo "Missing required secret: VERCEL_AUTOMATION_BYPASS_SECRET"
exit 1
fi
if [ -z "$SKETCHI_E2E_EMAIL" ]; then
echo "Missing required secret: SKETCHI_E2E_EMAIL"
exit 1
fi
if [ -z "$SKETCHI_E2E_PASSWORD" ]; then
echo "Missing required secret: SKETCHI_E2E_PASSWORD"
exit 1
fi
API_AUTH_TOKEN="$(
TARGET_URL="${{ github.event.deployment_status.environment_url }}" \
BYPASS_SECRET="$BYPASS_SECRET" \
SKETCHI_E2E_EMAIL="$SKETCHI_E2E_EMAIL" \
SKETCHI_E2E_PASSWORD="$SKETCHI_E2E_PASSWORD" \
bun packages/backend/scripts/mint-device-token.mjs
)"
if [ -z "$API_AUTH_TOKEN" ]; then
echo "Failed to mint auth token via device flow."
exit 1
fi
echo "::add-mask::$BYPASS_SECRET"
echo "::add-mask::$API_AUTH_TOKEN"
export VENOM_VAR_auth_token="$API_AUTH_TOKEN"
venom run tests/api/auth-device.yml tests/api/diagrams.yml \
--output-dir tests/api/results \
--format xml
- name: Collect Venom log
if: always() && steps.doc_check.outputs.run_tests == 'true'
run: |
mkdir -p tests/api/results
if [ -f venom.log ]; then
cp venom.log tests/api/results/venom.log
fi
- name: Summarize API tests
if: always() && steps.doc_check.outputs.run_tests == 'true'
run: |
node -e "
const fs = require('fs');
const path = require('path');
const resultsDir = path.join(process.cwd(), 'tests', 'api', 'results');
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
const lines = [];
lines.push('## API Test Results');
if (!fs.existsSync(resultsDir)) {
lines.push('No results directory found.');
fs.appendFileSync(summaryPath, lines.join('\\n') + '\\n');
process.exit(0);
}
const xmlFiles = fs.readdirSync(resultsDir).filter((f) => f.endsWith('.xml'));
if (xmlFiles.length === 0) {
lines.push('No XML results found.');
fs.appendFileSync(summaryPath, lines.join('\\n') + '\\n');
process.exit(0);
}
let totalTests = 0;
let totalFailures = 0;
const testcases = [];
for (const file of xmlFiles) {
const xml = fs.readFileSync(path.join(resultsDir, file), 'utf8');
const testsMatch = xml.match(/tests=\\\"(\\d+)\\\"/);
if (testsMatch) {
totalTests += Number(testsMatch[1] || 0);
}
const failureCount =
(xml.match(/<failure\\b/g) || []).length +
(xml.match(/<error\\b/g) || []).length;
totalFailures += failureCount;
const caseRegex = /<testcase[^>]*name=\\\"([^\\\"]+)\\\"/g;
let match;
while ((match = caseRegex.exec(xml)) !== null) {
testcases.push(match[1]);
}
}
lines.push('Total tests: ' + totalTests);
lines.push('Failures: ' + totalFailures);
if (testcases.length > 0) {
lines.push('Testcases:');
for (const name of testcases) {
lines.push('- ' + name);
}
}
fs.appendFileSync(summaryPath, lines.join('\\n') + '\\n');
"
- name: Upload API test artifacts
if: always() && steps.doc_check.outputs.run_tests == 'true'
uses: actions/upload-artifact@v4
with:
name: api-test-results-${{ github.run_id }}
path: tests/api/results
if-no-files-found: warn
retention-days: 7