From 57ec9444b5dad6e6ec77db0e910b872462b49e2d Mon Sep 17 00:00:00 2001 From: Trevor Pierce <1Copenut@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:04:52 -0500 Subject: [PATCH] [INFRA] Parallelize the Buildkite `test` job on PR (#7197) --- .../pipelines/pipeline_pull_request_test.yml | 43 ++++++++++++-- .buildkite/scripts/pipeline_test.sh | 57 +++++++++++++++---- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/.buildkite/pipelines/pipeline_pull_request_test.yml b/.buildkite/pipelines/pipeline_pull_request_test.yml index af25c625a9f..a983a2f1b75 100644 --- a/.buildkite/pipelines/pipeline_pull_request_test.yml +++ b/.buildkite/pipelines/pipeline_pull_request_test.yml @@ -1,9 +1,44 @@ # 🏠/.buildkite/pipelines/pipeline_pull_request_test.yml steps: - - agents: + - command: .buildkite/scripts/pipeline_test.sh + label: ":typescript: Linting" + agents: provider: "gcp" - command: .buildkite/scripts/pipeline_test.sh - if: build.branch != "main" # We're skipping testing commits in main for now to maintain parity with previous Jenkins setup + env: + TEST_TYPE: 'lint' + if: build.branch != "main" # This job is triggered by the combined test and deploy docs for every PR + - command: .buildkite/scripts/pipeline_test.sh + label: ":jest: Unit tests" + agents: + provider: "gcp" + env: + TEST_TYPE: 'unit' + if: build.branch != "main" + - command: .buildkite/scripts/pipeline_test.sh + label: ":cypress: Cypress tests on React 16" + agents: + provider: "gcp" + env: + TEST_TYPE: 'cypress:16' + if: build.branch != "main" + artifact_paths: + - "cypress/react16/screenshots/**/*.png" + - command: .buildkite/scripts/pipeline_test.sh + label: ":cypress: Cypress tests on React 17" + agents: + provider: "gcp" + env: + TEST_TYPE: 'cypress:17' + if: build.branch != "main" + artifact_paths: + - "cypress/react17/screenshots/**/*.png" + - command: .buildkite/scripts/pipeline_test.sh + label: ":cypress: Cypress tests on React 18" + agents: + provider: "gcp" + env: + TEST_TYPE: 'cypress:18' + if: build.branch != "main" artifact_paths: - - "cypress/screenshots/**/*.png" + - "cypress/react18/screenshots/**/*.png" diff --git a/.buildkite/scripts/pipeline_test.sh b/.buildkite/scripts/pipeline_test.sh index 7fef13e2c04..f80576cbd43 100644 --- a/.buildkite/scripts/pipeline_test.sh +++ b/.buildkite/scripts/pipeline_test.sh @@ -2,15 +2,48 @@ set -euo pipefail -docker run \ - -i --rm \ - --env GIT_COMMITTER_NAME=test \ - --env GIT_COMMITTER_EMAIL=test \ - --env HOME=/tmp \ - --user="$(id -u):$(id -g)" \ - --volume="$(pwd):/app" \ - --workdir=/app \ - docker.elastic.co/eui/ci:5.3 \ - bash -c "/opt/yarn*/bin/yarn \ - && yarn cypress install \ - && NODE_OPTIONS=\"--max-old-space-size=2048\" npm run test-ci" +DOCKER_OPTIONS=( + -i --rm + --env GIT_COMMITTER_NAME=test + --env GIT_COMMITTER_EMAIL=test + --env HOME=/tmp + --user="$(id -u):$(id -g)" + --volume="$(pwd):/app" + --workdir=/app + docker.elastic.co/eui/ci:5.3 +) + +case $TEST_TYPE in + lint) + echo "[TASK]: Running linters" + DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && NODE_OPTIONS=\"--max-old-space-size=2048\" yarn lint") + ;; + + unit) + echo "[TASK]: Running unit tests" + DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && NODE_OPTIONS=\"--max-old-space-size=2048\" yarn test-unit") + ;; + + cypress:16) + echo "[TASK]: Running Cypress tests against React 16" + DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && NODE_OPTIONS=\"--max-old-space-size=2048\" yarn test-cypress --react-version 16") + ;; + + cypress:17) + echo "[TASK]: Running Cypress tests against React 17" + DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && NODE_OPTIONS=\"--max-old-space-size=2048\" yarn test-cypress --react-version 17") + ;; + + cypress:18) + echo "[TASK]: Running Cypress tests against React 18" + DOCKER_OPTIONS+=(bash -c "/opt/yarn*/bin/yarn && yarn cypress install && NODE_OPTIONS=\"--max-old-space-size=2048\" yarn test-cypress") + ;; + + *) + echo "[ERROR]: Unknown task" + echo "Exit code: 1" + exit 1 + ;; +esac + +docker run "${DOCKER_OPTIONS[@]}"