Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Simplify detect_jobs_to_run output (and related if) #4307

Merged
merged 15 commits into from
Nov 28, 2023
253 changes: 0 additions & 253 deletions .github/workflows/detect-jobs-to-run.test.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/optional-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Install Dependencies
run: pnpm install
- id: detect
run: ./.github/workflows/detect-jobs-to-run.js <<<'${{ steps.files.outputs.all }}'
run: ./.github/workflows/scripts/detect-jobs-to-run.js <<<'${{ steps.files.outputs.all }}'

report-to-slack-success:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:

community-generators:
needs: [detect_jobs_to_run]
if: ${{ fromJson(needs.detect_jobs_to_run.outputs.jobs)['community-generators'] == true }}
if: contains(fromJSON(needs.detect_jobs_to_run.outputs.jobs), 'community-generators')

strategy:
fail-fast: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function getStdin() {
}

async function detectJobsTorun({ filesChanged, GITHUB_REF }) {
console.debug("filesChanged", filesChanged)
const testYamlString = fs.readFileSync(path.join(process.cwd(), '.github/workflows/test.yaml'), { encoding: 'utf8' })
const testYaml = yaml.parse(testYamlString)
const optionalTestYamlString = fs.readFileSync(path.join(process.cwd(), '.github/workflows/optional-test.yaml'), {
Expand All @@ -38,22 +39,22 @@ async function detectJobsTorun({ filesChanged, GITHUB_REF }) {
// ['process-managers', 'docker', 'core-features', ...]
const testDirectories = Object.keys(allJobs).filter((key) => {
const jobsToIgnore = [
'node16dot13',
'report-to-slack-success', // Not a test but a job that posts to slack
'report-to-slack-failure', // Not a test but a job that posts to slack
'detect_jobs_to_run', // Not a test but a job that decides which tests should run
'cleanup-runs', // Not a test but a job that cancels previous runs
'confirm_all_jobs_have_run', // Not a test but a job that confirms all tests have run (for Renovate)
'detect_jobs_to_run', // Not a test but a job that decides which tests should run
'report-to-slack-success', // Not a test but a job that posts to slack
'report-to-slack-failure', // Not a test but a job that posts to slack
'cleanup-runs', // Not a test but a job that cancels previous runs
'confirm_all_jobs_have_run', // Not a test but a job that confirms all tests have run (for Renovate)
'node16dot13', // TODO
]
return !jobsToIgnore.includes(key)
})
console.debug(testDirectories)
console.debug("testDirectories", testDirectories)

// Object used as output
const jobsToRun = {}
// Array used as output
const jobsToRun = []

// creates an object with all values set to true to be used a fallback to run all tests
const fallbackRunAllJobs = testDirectories.reduce((acc, curr) => ((acc[curr] = true), acc), {})
// fallback is to test all testDirectories
const fallbackRunAllJobs = testDirectories

// If we are in one of our special branches we always run all tests
if (['refs/heads/dev', 'refs/heads/patch-dev', 'refs/heads/latest', 'refs/heads/integration'].includes(GITHUB_REF)) {
Expand Down Expand Up @@ -88,10 +89,9 @@ async function detectJobsTorun({ filesChanged, GITHUB_REF }) {
totalNumberOfFilesChangedInsideDirectories += filesChangedInsideDirectory.length

// we need to run the test
jobsToRun[directoryName] = true
jobsToRun.push(directoryName)
} else {
// we don't need to run the test
jobsToRun[directoryName] = false
}
}

Expand Down Expand Up @@ -135,6 +135,8 @@ async function main() {
GITHUB_REF,
})

console.debug({ jobsToRun })

if (typeof process.env.GITHUB_OUTPUT == 'string' && process.env.GITHUB_OUTPUT.length > 0) {
fs.appendFileSync(process.env.GITHUB_OUTPUT, `jobs=${JSON.stringify(jobsToRun)}\n`)
console.debug('jobsToRun added to GITHUB_OUTPUT')
Expand Down
Loading
Loading