Skip to content

Commit a4dee7b

Browse files
authored
Update test timings endpoint (vercel#29443)
* Update test timings endpoint * bump
1 parent 0df6836 commit a4dee7b

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

.github/workflows/build_test_deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ jobs:
214214
env:
215215
NEXT_TELEMETRY_DISABLED: 1
216216
NEXT_TEST_JOB: 1
217+
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
217218
strategy:
218219
fail-fast: false
219220
matrix:

run-tests.js

+40-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 1
1717
const DEFAULT_CONCURRENCY = 2
1818
const RESULTS_EXT = `.results.json`
1919
const isTestJob = !!process.env.NEXT_TEST_JOB
20-
const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
20+
const TIMINGS_API = `https://api.github.com/gists/4500dd89ae2f5d70d9aaceb191f528d1`
21+
const TIMINGS_API_HEADERS = {
22+
Accept: 'application/vnd.github.v3+json',
23+
}
2124

2225
const testFilters = {
2326
unit: 'unit/',
@@ -36,6 +39,20 @@ const cleanUpAndExit = async (code) => {
3639
process.exit(code)
3740
}
3841

42+
async function getTestTimings() {
43+
const timingsRes = await fetch(TIMINGS_API, {
44+
headers: {
45+
...TIMINGS_API_HEADERS,
46+
},
47+
})
48+
49+
if (!timingsRes.ok) {
50+
throw new Error(`request status: ${timingsRes.status}`)
51+
}
52+
const timingsData = await timingsRes.json()
53+
return JSON.parse(timingsData.files['test-timings.json'].content)
54+
}
55+
3956
async function main() {
4057
let numRetries = DEFAULT_NUM_RETRIES
4158
let concurrencyIdx = process.argv.indexOf('-c')
@@ -46,7 +63,6 @@ async function main() {
4663
const hideOutput = !process.argv.includes('--debug')
4764
const outputTimings = process.argv.includes('--timings')
4865
const writeTimings = process.argv.includes('--write-timings')
49-
const isAzure = process.argv.includes('--azure')
5066
const groupIdx = process.argv.indexOf('-g')
5167
const groupArg = groupIdx !== -1 && process.argv[groupIdx + 1]
5268

@@ -110,14 +126,7 @@ async function main() {
110126
} catch (_) {}
111127

112128
if (!prevTimings) {
113-
const timingsRes = await fetch(
114-
`${TIMINGS_API}?which=${isAzure ? 'azure' : 'actions'}`
115-
)
116-
117-
if (!timingsRes.ok) {
118-
throw new Error(`request status: ${timingsRes.status}`)
119-
}
120-
prevTimings = await timingsRes.json()
129+
prevTimings = await getTestTimings()
121130
console.log('Fetched previous timings data successfully')
122131

123132
if (writeTimings) {
@@ -377,16 +386,32 @@ async function main() {
377386
// junitData += `</testsuites>`
378387
// console.log('output timing data to junit.xml')
379388

380-
if (prevTimings) {
389+
if (prevTimings && process.env.TEST_TIMINGS_TOKEN) {
381390
try {
391+
const newTimings = {
392+
...(await getTestTimings()),
393+
...curTimings,
394+
}
395+
396+
for (const test of Object.keys(newTimings)) {
397+
if (!(await fs.pathExists(path.join(__dirname, test)))) {
398+
console.log('removing stale timing', test)
399+
delete newTimings[test]
400+
}
401+
}
402+
382403
const timingsRes = await fetch(TIMINGS_API, {
383-
method: 'POST',
404+
method: 'PATCH',
384405
headers: {
385-
'content-type': 'application/json',
406+
...TIMINGS_API_HEADERS,
407+
Authorization: `Bearer ${process.env.TEST_TIMINGS_TOKEN}`,
386408
},
387409
body: JSON.stringify({
388-
timings: curTimings,
389-
which: isAzure ? 'azure' : 'actions',
410+
files: {
411+
'test-timings.json': {
412+
content: JSON.stringify(newTimings),
413+
},
414+
},
390415
}),
391416
})
392417

0 commit comments

Comments
 (0)