From 42a0a67c77f6b439a0806b43c9452b28ce9926ad Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Tue, 10 Nov 2020 12:46:59 -0500 Subject: [PATCH] build: fail tests when the conditional CI script errors (#9141) * fail tests if ci script fails * exit with nonzero exit code on uncaught exeptions * move check halt out of yarn so it doesn't check node version * rename check halt to check conditional ci --- circle.yml | 75 +++++++++---------- package.json | 1 - ...{check-halt.js => check-conditional-ci.js} | 23 +++--- 3 files changed, 47 insertions(+), 52 deletions(-) rename scripts/{check-halt.js => check-conditional-ci.js} (85%) diff --git a/circle.yml b/circle.yml index 3c88b6b25f..c0b0aa96c9 100644 --- a/circle.yml +++ b/circle.yml @@ -120,7 +120,7 @@ commands: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: environment: CYPRESS_KONFIG_ENV: production @@ -162,7 +162,7 @@ commands: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: | cmd=$([[ <> == 'true' ]] && echo 'yarn percy exec --') || true @@ -186,7 +186,7 @@ commands: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn workspace @packages/server test ./test/e2e/$(( $CIRCLE_NODE_INDEX ))_*spec* --browser <> - verify-mocha-results @@ -237,6 +237,7 @@ commands: steps: - attach_workspace: at: ~/ + - check-conditional-ci - run: name: "Cloning test project: <>" command: | @@ -284,7 +285,6 @@ commands: steps: - attach_workspace: at: ~/ - - check-halt # make sure the binary and NPM package files are present - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -385,12 +385,12 @@ commands: name: "Waiting on Circle CI jobs: <>" command: node ./scripts/wait-on-circle-jobs.js --job-names="<>" - check-halt: + check-conditional-ci: description: Halt CI if the package that this job corresponds to is unchanged steps: - run: name: Check if job should run - command: yarn check-halt || circleci-agent step halt + command: node scripts/check-conditional-ci.js jobs: ## code checkout and yarn installs @@ -536,7 +536,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: mkdir -p cli/visual-snapshots - run: command: node cli/bin/cypress info --dev | yarn --silent term-to-html | node scripts/sanitize --type cli-info > cli/visual-snapshots/cypress-info.html @@ -561,7 +561,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure mocha runs - run: yarn test-mocha # test binary build code @@ -607,7 +607,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - install-required-node - run: name: Mocha tests @@ -627,7 +627,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: yarn test-unit --scope @packages/server - verify-mocha-results: expectedResultCount: 1 @@ -641,7 +641,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: yarn test-integration --scope @packages/server - verify-mocha-results: expectedResultCount: 1 @@ -654,7 +654,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn workspace @packages/server test-performance - verify-mocha-results: @@ -735,7 +735,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn build-prod working_directory: packages/desktop-gui @@ -761,7 +761,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn build-prod working_directory: packages/desktop-gui @@ -796,7 +796,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: # builds JS and CSS, and we need the app CSS # to correctly apply component styles @@ -830,7 +830,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn build-for-tests working_directory: packages/reporter @@ -852,7 +852,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: yarn build-for-tests working_directory: packages/ui-components @@ -874,7 +874,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: command: node index.js working_directory: packages/launcher @@ -884,7 +884,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: name: Build command: yarn workspace @cypress/webpack-preprocessor build @@ -923,7 +923,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: name: Build command: yarn workspace @cypress/vue build @@ -937,7 +937,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: name: Build command: yarn workspace @cypress/react build @@ -966,7 +966,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - restore_cache: name: Restore Cache keys: @@ -990,7 +990,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: name: Run tests command: yarn workspace @cypress/eslint-plugin-dev test @@ -1037,7 +1037,7 @@ jobs: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: $(yarn bin)/print-arch - install-required-node - run: @@ -1070,7 +1070,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: ls -l - run: name: upload unique binary @@ -1088,7 +1088,6 @@ jobs: test-kitchensink: <<: *defaults steps: - - check-halt - clone-repo-and-checkout-release-branch: repo: cypress-example-kitchensink - install-required-node @@ -1115,7 +1114,6 @@ jobs: "test-kitchensink-against-staging": <<: *defaults steps: - - check-halt - clone-repo-and-checkout-release-branch: repo: cypress-example-kitchensink - run: @@ -1140,7 +1138,6 @@ jobs: "test-against-staging": <<: *defaults steps: - - check-halt - clone-repo-and-checkout-release-branch: repo: cypress-test-tiny - run: @@ -1157,7 +1154,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - install-required-node - run: name: Check next dev version @@ -1204,7 +1201,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: ls -l # NPM package file should have filename cypress-.tgz - run: @@ -1227,7 +1224,7 @@ jobs: # needs uploaded NPM and test binary - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: ls -la # make sure JSON files with uploaded urls are present - run: ls -la binary-url.json npm-package-url.json @@ -1265,7 +1262,7 @@ jobs: # needs uploaded NPM and test binary - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: ls -la - post-install-comment @@ -1274,7 +1271,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure we have cypress.zip received - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -1310,7 +1307,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure we have cypress.zip received - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -1352,7 +1349,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure we have cypress.zip received - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -1396,7 +1393,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure we have cypress.zip received - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -1440,7 +1437,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # make sure we have cypress.zip received - run: ls -l - run: ls -l cypress.zip cypress.tgz @@ -1473,7 +1470,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci - run: ls -l # make sure we have the binary and NPM package - run: ls -l cypress.zip cypress.tgz @@ -1609,7 +1606,7 @@ jobs: steps: - attach_workspace: at: ~/ - - check-halt + - check-conditional-ci # the user should be "node" - run: whoami - run: pwd diff --git a/package.json b/package.json index c5e84975d4..f1573892ee 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "build": "lerna run build --stream", "build-prod": "lerna run build-prod --stream", "bump": "node ./scripts/binary.js bump", - "check-halt": "node scripts/check-halt.js", "check-next-dev-version": "node scripts/check-next-dev-version.js", "check-node-version": "node scripts/check-node-version.js", "check-terminal": "node scripts/check-terminal.js", diff --git a/scripts/check-halt.js b/scripts/check-conditional-ci.js similarity index 85% rename from scripts/check-halt.js rename to scripts/check-conditional-ci.js index 6dbe0917c3..e60b67d31c 100644 --- a/scripts/check-halt.js +++ b/scripts/check-conditional-ci.js @@ -1,20 +1,17 @@ /* eslint-disable no-console */ +const { execSync } = require('child_process') const { getCurrentBranch, readPackageJson } = require('./utils') const { getChangedPackagesAndDependents, getLernaPackages } = require('./changed-packages') -const runTestsAndExit = () => { - process.exit(0) -} - -const skipTestsAndExit = () => { - process.exit(1) +const skipTests = () => { + execSync('circleci-agent step halt') } const main = async (ciJob) => { if (!ciJob) { console.log(`Could not get current CI job`) - return skipTestsAndExit() + process.exit(1) } const currentBranch = await getCurrentBranch() @@ -22,7 +19,7 @@ const main = async (ciJob) => { if (currentBranch === 'develop' || currentBranch === 'master') { console.log(`Currently on ${currentBranch} - all tests run`) - return runTestsAndExit() + return } const packages = await getLernaPackages() @@ -44,7 +41,7 @@ const main = async (ciJob) => { if (Object.keys(changed).includes(pack)) { console.log(`${pack} was directly changed, so tests run.`) - return runTestsAndExit() + return } const dependenciesChanged = [] @@ -58,12 +55,14 @@ const main = async (ciJob) => { if (dependenciesChanged.length) { console.log(`${pack} is listed as a dependant of ${dependenciesChanged.join(', ')}, so tests run.`) - return runTestsAndExit() + return } console.log(`${pack} is unchanged and not dependent on any changed packages, so tests do not run.`) - return skipTestsAndExit() + return skipTests() } -main(process.env.CIRCLE_JOB) +main(process.env.CIRCLE_JOB).catch(() => { + process.exit(1) +})