mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-03 05:19:45 -06:00
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
This commit is contained in:
@@ -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)
|
||||
})
|
||||
Reference in New Issue
Block a user