@@ -17,7 +17,10 @@ const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 1
17
17
const DEFAULT_CONCURRENCY = 2
18
18
const RESULTS_EXT = `.results.json`
19
19
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
+ }
21
24
22
25
const testFilters = {
23
26
unit : 'unit/' ,
@@ -36,6 +39,20 @@ const cleanUpAndExit = async (code) => {
36
39
process . exit ( code )
37
40
}
38
41
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
+
39
56
async function main ( ) {
40
57
let numRetries = DEFAULT_NUM_RETRIES
41
58
let concurrencyIdx = process . argv . indexOf ( '-c' )
@@ -46,7 +63,6 @@ async function main() {
46
63
const hideOutput = ! process . argv . includes ( '--debug' )
47
64
const outputTimings = process . argv . includes ( '--timings' )
48
65
const writeTimings = process . argv . includes ( '--write-timings' )
49
- const isAzure = process . argv . includes ( '--azure' )
50
66
const groupIdx = process . argv . indexOf ( '-g' )
51
67
const groupArg = groupIdx !== - 1 && process . argv [ groupIdx + 1 ]
52
68
@@ -110,14 +126,7 @@ async function main() {
110
126
} catch ( _ ) { }
111
127
112
128
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 ( )
121
130
console . log ( 'Fetched previous timings data successfully' )
122
131
123
132
if ( writeTimings ) {
@@ -377,16 +386,32 @@ async function main() {
377
386
// junitData += `</testsuites>`
378
387
// console.log('output timing data to junit.xml')
379
388
380
- if ( prevTimings ) {
389
+ if ( prevTimings && process . env . TEST_TIMINGS_TOKEN ) {
381
390
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
+
382
403
const timingsRes = await fetch ( TIMINGS_API , {
383
- method : 'POST ' ,
404
+ method : 'PATCH ' ,
384
405
headers : {
385
- 'content-type' : 'application/json' ,
406
+ ...TIMINGS_API_HEADERS ,
407
+ Authorization : `Bearer ${ process . env . TEST_TIMINGS_TOKEN } ` ,
386
408
} ,
387
409
body : JSON . stringify ( {
388
- timings : curTimings ,
389
- which : isAzure ? 'azure' : 'actions' ,
410
+ files : {
411
+ 'test-timings.json' : {
412
+ content : JSON . stringify ( newTimings ) ,
413
+ } ,
414
+ } ,
390
415
} ) ,
391
416
} )
392
417
0 commit comments