Skip to content

Commit

Permalink
ci(detect-jobs-to-run): fix stdin empty case
Browse files Browse the repository at this point in the history
follows 3fde8fb

[skip ci]
  • Loading branch information
Jolg42 committed Jan 31, 2023
1 parent 3fde8fb commit 3e695e7
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions .github/workflows/scripts/detect-jobs-to-run.js
Expand Up @@ -24,35 +24,37 @@ async function getStdin() {
async function main() {
const jobsToRun = []
const stdinData = await getStdin()
console.debug('stdin:', stdinData)
console.debug(`stdin: \`${stdinData}\``)
const stdinDataTrimmed = stdinData.trim()
console.debug(`stdin trimmed: \`${stdinDataTrimmed}\``)

// If the stdin is empty, we run all jobs
// It happens if the get-changed-files-action fails (e.g. if ran on a schedule)
if (!stdinData) {
if (!stdinDataTrimmed) {
console.log('Stdin is empty (expected some JSON as a string) - running all jobs as fallback.')
jobsToRun.push('-all-')
}

/**
* @type string[]
**/
const filesChanged = JSON.parse(stdinData)
console.debug('filesChanged:', filesChanged)

// If changes are located only in one of the paths below
if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/cli/'))) {
jobsToRun.push('-cli-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/client/'))) {
jobsToRun.push('-client-')
jobsToRun.push('-integration-tests-')
jobsToRun.push('-cli-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/integration-tests/'))) {
jobsToRun.push('-integration-tests-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/migrate/'))) {
jobsToRun.push('-migrate-')
jobsToRun.push('-cli-')
} else {
jobsToRun.push('-all-')
/**
* @type string[]
**/
const filesChanged = JSON.parse(stdinData)
console.debug('filesChanged:', filesChanged)

// If changes are located only in one of the paths below
if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/cli/'))) {
jobsToRun.push('-cli-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/client/'))) {
jobsToRun.push('-client-')
jobsToRun.push('-integration-tests-')
jobsToRun.push('-cli-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/integration-tests/'))) {
jobsToRun.push('-integration-tests-')
} else if (filesChanged.every((fileChanged) => fileChanged.startsWith('packages/migrate/'))) {
jobsToRun.push('-migrate-')
jobsToRun.push('-cli-')
} else {
jobsToRun.push('-all-')
}
}

console.log('jobsToRun:', jobsToRun)
Expand Down

0 comments on commit 3e695e7

Please sign in to comment.