Update test timings endpoint (#29443)

* Update test timings endpoint

* bump
This commit is contained in:
JJ Kasper 2021-09-28 10:15:04 -05:00 committed by GitHub
parent 0df68366ca
commit a4dee7b254
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 15 deletions

View file

@ -214,6 +214,7 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
strategy:
fail-fast: false
matrix:

View file

@ -17,7 +17,10 @@ const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 1
const DEFAULT_CONCURRENCY = 2
const RESULTS_EXT = `.results.json`
const isTestJob = !!process.env.NEXT_TEST_JOB
const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
const TIMINGS_API = `https://api.github.com/gists/4500dd89ae2f5d70d9aaceb191f528d1`
const TIMINGS_API_HEADERS = {
Accept: 'application/vnd.github.v3+json',
}
const testFilters = {
unit: 'unit/',
@ -36,6 +39,20 @@ const cleanUpAndExit = async (code) => {
process.exit(code)
}
async function getTestTimings() {
const timingsRes = await fetch(TIMINGS_API, {
headers: {
...TIMINGS_API_HEADERS,
},
})
if (!timingsRes.ok) {
throw new Error(`request status: ${timingsRes.status}`)
}
const timingsData = await timingsRes.json()
return JSON.parse(timingsData.files['test-timings.json'].content)
}
async function main() {
let numRetries = DEFAULT_NUM_RETRIES
let concurrencyIdx = process.argv.indexOf('-c')
@ -46,7 +63,6 @@ async function main() {
const hideOutput = !process.argv.includes('--debug')
const outputTimings = process.argv.includes('--timings')
const writeTimings = process.argv.includes('--write-timings')
const isAzure = process.argv.includes('--azure')
const groupIdx = process.argv.indexOf('-g')
const groupArg = groupIdx !== -1 && process.argv[groupIdx + 1]
@ -110,14 +126,7 @@ async function main() {
} catch (_) {}
if (!prevTimings) {
const timingsRes = await fetch(
`${TIMINGS_API}?which=${isAzure ? 'azure' : 'actions'}`
)
if (!timingsRes.ok) {
throw new Error(`request status: ${timingsRes.status}`)
}
prevTimings = await timingsRes.json()
prevTimings = await getTestTimings()
console.log('Fetched previous timings data successfully')
if (writeTimings) {
@ -377,16 +386,32 @@ async function main() {
// junitData += `</testsuites>`
// console.log('output timing data to junit.xml')
if (prevTimings) {
if (prevTimings && process.env.TEST_TIMINGS_TOKEN) {
try {
const newTimings = {
...(await getTestTimings()),
...curTimings,
}
for (const test of Object.keys(newTimings)) {
if (!(await fs.pathExists(path.join(__dirname, test)))) {
console.log('removing stale timing', test)
delete newTimings[test]
}
}
const timingsRes = await fetch(TIMINGS_API, {
method: 'POST',
method: 'PATCH',
headers: {
'content-type': 'application/json',
...TIMINGS_API_HEADERS,
Authorization: `Bearer ${process.env.TEST_TIMINGS_TOKEN}`,
},
body: JSON.stringify({
timings: curTimings,
which: isAzure ? 'azure' : 'actions',
files: {
'test-timings.json': {
content: JSON.stringify(newTimings),
},
},
}),
})