ci: optimize e2e and refactor workflow (#3530)

* ci: split e2e

* chore: 3 parts

* chore: use matrix

* chore: use playwright container, bump playwright

* chore: remove playwright container

* ci: move all packages into matrix

* ci: reusable action to restore build cache

* chore: revert custom action

* chore: cleanup logs
This commit is contained in:
Elliot DeNolf
2023-10-09 23:43:34 -04:00
committed by GitHub
parent 8bfae6b932
commit 890af8be05
5 changed files with 76 additions and 180 deletions

View File

@@ -1,4 +1,5 @@
import glob from 'glob'
import minimist from 'minimist'
import path from 'path'
import shelljs from 'shelljs'
import slash from 'slash'
@@ -8,14 +9,39 @@ shelljs.env.DISABLE_LOGGING = 'true'
const playwrightBin = path.resolve(__dirname, '../node_modules/.bin/playwright')
const testRunCodes: { code: number; suiteName: string }[] = []
const args = process.argv.slice(2)
const { _: args, bail, part } = minimist(process.argv.slice(2))
const suiteName = args[0]
// Run all
if (!suiteName || args[0].startsWith('-')) {
const bail = args.includes('--bail')
const files = glob.sync(`${path.resolve(__dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`)
console.log(`\n\nExecuting all ${files.length} E2E tests...`)
if (!suiteName) {
let files = glob.sync(`${path.resolve(__dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`)
const totalFiles = files.length
if (part) {
if (!part.includes('/')) {
throw new Error('part must be in the format of "1/2"')
}
const [partToRun, totalParts] = part.split('/').map((n) => parseInt(n))
if (partToRun > totalParts) {
throw new Error('part cannot be greater than totalParts')
}
const partSize = Math.ceil(files.length / totalParts)
const start = (partToRun - 1) * partSize
const end = start + partSize
files = files.slice(start, end)
}
if (files.length !== totalFiles) {
console.log(`\n\nExecuting part ${part}: ${files.length} of ${totalFiles} E2E tests...\n\n`)
} else {
console.log(`\n\nExecuting all ${files.length} E2E tests...\n\n`)
}
console.log(`${files.join('\n')}\n`)
files.forEach((file) => {
clearWebpackCache()
executePlaywright(file, bail)