|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import path from 'path'; |
| 10 | + |
| 11 | +import { getMetadata, setMetadata } from 'buildkite-agent-node'; |
| 12 | + |
| 13 | +import { updateCheckStatus } from './../../utils/github'; |
| 14 | +import { exec, downloadArtifacts, startGroup, yarnInstall, getNumber, decompress, compress, bkEnv } from '../../utils'; |
| 15 | +import { ENV_URL } from '../../utils/constants'; |
| 16 | + |
| 17 | +const jobIndex = getNumber(process.env.BUILDKITE_PARALLEL_JOB); |
| 18 | +const shardIndex = jobIndex ? jobIndex + 1 : 1; |
| 19 | +const jobTotal = getNumber(process.env.BUILDKITE_PARALLEL_JOB_COUNT); |
| 20 | + |
| 21 | +const pwFlags = ['--project=Chrome', '--config=playwright.a11y.config.ts']; |
| 22 | + |
| 23 | +if (jobIndex !== null && jobTotal !== null) { |
| 24 | + pwFlags.push(`--shard=${shardIndex}/${jobTotal}`); |
| 25 | +} |
| 26 | + |
| 27 | +void (async () => { |
| 28 | + await yarnInstall('e2e'); |
| 29 | + |
| 30 | + const key = `${bkEnv.checkId}--activeJobs`; |
| 31 | + const value = shardIndex === jobTotal ? jobTotal - 1 : Number(await getMetadata(key)); |
| 32 | + // TODO improve this status logic, not easy to communicate state of parallel steps |
| 33 | + const activeJobs = Math.min((Number.isNaN(value) ? 0 : value) + 1, jobTotal ?? 1); |
| 34 | + await setMetadata(key, String(activeJobs)); |
| 35 | + |
| 36 | + await updateCheckStatus( |
| 37 | + { |
| 38 | + status: 'in_progress', |
| 39 | + }, |
| 40 | + 'playwright_a11y', |
| 41 | + `${activeJobs} of ${jobTotal ?? 1} a11y jobs started`, |
| 42 | + ); |
| 43 | + |
| 44 | + const src = '.buildkite/artifacts/e2e_server.gz'; |
| 45 | + await downloadArtifacts(src, 'build_e2e'); |
| 46 | + await decompress({ |
| 47 | + src, |
| 48 | + dest: 'e2e/server', |
| 49 | + }); |
| 50 | + |
| 51 | + startGroup('Check Architecture'); |
| 52 | + await exec('arch'); |
| 53 | + |
| 54 | + startGroup('Running e2e a11y playwright job'); |
| 55 | + const reportDir = `reports/a11y_report_${shardIndex}`; |
| 56 | + async function postCommandTasks() { |
| 57 | + await compress({ |
| 58 | + src: path.join('e2e', reportDir), |
| 59 | + dest: `.buildkite/artifacts/a11y_reports/report_${shardIndex}.gz`, |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + const command = `yarn playwright test ${pwFlags.join(' ')}`; |
| 64 | + |
| 65 | + try { |
| 66 | + await exec(command, { |
| 67 | + cwd: 'e2e', |
| 68 | + env: { |
| 69 | + [ENV_URL]: 'http://127.0.0.1:9002', |
| 70 | + PLAYWRIGHT_HTML_REPORT: reportDir, |
| 71 | + PLAYWRIGHT_JSON_OUTPUT_NAME: `reports/a11y-json/report_${shardIndex}.json`, |
| 72 | + }, |
| 73 | + }); |
| 74 | + await postCommandTasks(); |
| 75 | + } catch (error) { |
| 76 | + await postCommandTasks(); |
| 77 | + throw error; |
| 78 | + } |
| 79 | +})(); |
0 commit comments