From 622421db937374a7fbb49be78ca585a10032df9e Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Thu, 7 Nov 2024 14:18:57 -0500 Subject: [PATCH 1/4] run all tests in merge queue https://coveord.atlassian.net/browse/KIT-3702 fix default value https://coveord.atlassian.net/browse/KIT-3702 test run all tests https://coveord.atlassian.net/browse/KIT-3702 invert logic for merge queue tests https://coveord.atlassian.net/browse/KIT-3702 test change detection https://coveord.atlassian.net/browse/KIT-3702 Revert "test change detection" This reverts commit ed84727eab28a0f267185cabe0038fe405588e70. revert change https://coveord.atlassian.net/browse/KIT-3702 Revert "revert change" This reverts commit 7313e3bd38c3c46444d4e8eb9b174c06dee0e1e4. fix script https://coveord.atlassian.net/browse/KIT-3702 print files for debugging https://coveord.atlassian.net/browse/KIT-3702 throw error fallback https://coveord.atlassian.net/browse/KIT-3702 try something differente https://coveord.atlassian.net/browse/KIT-3702 revert script changes https://coveord.atlassian.net/browse/KIT-3702 fix logic https://coveord.atlassian.net/browse/KIT-3702 --- .github/workflows/prbot.yml | 7 ++++++- scripts/ci/determine-tests.mjs | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/prbot.yml b/.github/workflows/prbot.yml index 49111d0d93..9336c5e94c 100644 --- a/.github/workflows/prbot.yml +++ b/.github/workflows/prbot.yml @@ -149,7 +149,12 @@ jobs: - run: npm run build - name: Identify E2E Test Files to run id: determine-tests - run: node ./scripts/ci/determine-tests.mjs testsToRun shardIndex shardTotal + run: | + echo "GitHub Event Name: ${{ github.event_name }}" + runAllTests=$([ "${{ github.event_name }}" == "merge_group" ] && echo true || echo false) + echo "Run All Tests: $runAllTests" + node ./scripts/ci/determine-tests.mjs testsToRun shardIndex shardTotal $runAllTests + env: projectRoot: ${{ github.workspace }} maximumShards: ${{ env.maximumShards }} diff --git a/scripts/ci/determine-tests.mjs b/scripts/ci/determine-tests.mjs index 74d7d9fd66..d615e6512f 100644 --- a/scripts/ci/determine-tests.mjs +++ b/scripts/ci/determine-tests.mjs @@ -135,6 +135,7 @@ function ensureIsNotCoveoPackage(file) { * @throws {PackageJsonChangeError} If the file is 'package.json' or 'package-lock.json'. */ function ensureIsNotPackageJsonOrPackageLockJson(file) { + console.log(file); if (file.includes('package.json') || file.includes('package-lock.json')) { throw new PackageJsonChangeError(file); } @@ -176,14 +177,17 @@ const changedFiles = getChangedFiles(base, head).split(EOL); const outputNameTestsToRun = process.argv[2]; const outputNameShardIndex = process.argv[3]; const outputNameShardTotal = process.argv[4]; +const runAllTests = process.argv[5] === 'true'; const projectRoot = process.env.projectRoot; const atomicSourceComponents = join('packages', 'atomic', 'src', 'components'); try { const testFiles = findAllTestFiles(atomicSourceComponents); const testDependencies = createTestFileMappings(testFiles, projectRoot); - const testsToRun = determineTestFilesToRun(changedFiles, testDependencies); - if (testsToRun === '') { + const testsToRun = runAllTests + ? testFiles.join(' ') + : determineTestFilesToRun(changedFiles, testDependencies); + if (testsToRun === '' && !runAllTests) { throw new NoRelevantChangesError(); } const maximumShards = parseInt(process.env.maximumShards, 10); From 2d8b5ebe25b14961b223e74e9561f4ec89aad022 Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Fri, 8 Nov 2024 16:25:02 -0500 Subject: [PATCH 2/4] remove logs https://coveord.atlassian.net/browse/KIT-3702 --- .github/workflows/prbot.yml | 2 -- scripts/ci/determine-tests.mjs | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/workflows/prbot.yml b/.github/workflows/prbot.yml index 9336c5e94c..d7b8f6ed1b 100644 --- a/.github/workflows/prbot.yml +++ b/.github/workflows/prbot.yml @@ -150,9 +150,7 @@ jobs: - name: Identify E2E Test Files to run id: determine-tests run: | - echo "GitHub Event Name: ${{ github.event_name }}" runAllTests=$([ "${{ github.event_name }}" == "merge_group" ] && echo true || echo false) - echo "Run All Tests: $runAllTests" node ./scripts/ci/determine-tests.mjs testsToRun shardIndex shardTotal $runAllTests env: diff --git a/scripts/ci/determine-tests.mjs b/scripts/ci/determine-tests.mjs index d615e6512f..6bef1751ad 100644 --- a/scripts/ci/determine-tests.mjs +++ b/scripts/ci/determine-tests.mjs @@ -135,7 +135,6 @@ function ensureIsNotCoveoPackage(file) { * @throws {PackageJsonChangeError} If the file is 'package.json' or 'package-lock.json'. */ function ensureIsNotPackageJsonOrPackageLockJson(file) { - console.log(file); if (file.includes('package.json') || file.includes('package-lock.json')) { throw new PackageJsonChangeError(file); } From 76fd46ae33d1e35d2246d7e444eba711bba91371 Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Tue, 12 Nov 2024 11:46:18 -0500 Subject: [PATCH 3/4] simplify logic https://coveord.atlassian.net/browse/KIT-3702 --- scripts/ci/determine-tests.mjs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/scripts/ci/determine-tests.mjs b/scripts/ci/determine-tests.mjs index 6bef1751ad..2cf7f02b43 100644 --- a/scripts/ci/determine-tests.mjs +++ b/scripts/ci/determine-tests.mjs @@ -33,6 +33,13 @@ class PackageJsonChangeError extends Error { } } +class RunAllTestsInMergeQueueError extends Error { + constructor() { + super(`In a merge queue. Running all tests.`); + this.name = 'RunAllTestsInMergeQueueError'; + } +} + /** * Recursively finds all end-to-end test files with the `.e2e.ts` extension in a given directory. * @@ -181,16 +188,19 @@ const projectRoot = process.env.projectRoot; const atomicSourceComponents = join('packages', 'atomic', 'src', 'components'); try { + if (runAllTests) { + throw new RunAllTestsInMergeQueue(); + } + const testFiles = findAllTestFiles(atomicSourceComponents); const testDependencies = createTestFileMappings(testFiles, projectRoot); - const testsToRun = runAllTests - ? testFiles.join(' ') - : determineTestFilesToRun(changedFiles, testDependencies); - if (testsToRun === '' && !runAllTests) { + const testsToRun = determineTestFilesToRun(changedFiles, testDependencies); + + if (testsToRun === '') { throw new NoRelevantChangesError(); } - const maximumShards = parseInt(process.env.maximumShards, 10); + const maximumShards = parseInt(process.env.maximumShards, 10); const [shardIndex, shardTotal] = allocateShards( testsToRun.split(' ').length, maximumShards @@ -205,11 +215,10 @@ try { setOutput(outputNameTestsToRun, ''); setOutput(outputNameShardIndex, [0]); setOutput(outputNameShardTotal, [0]); - } - - if ( + } else if ( error instanceof DependentPackageChangeError || - error instanceof PackageJsonChangeError + error instanceof PackageJsonChangeError || + error instanceof RunAllTestsInMergeQueueError ) { console.warn(error?.message || error); setOutput(outputNameTestsToRun, ''); @@ -220,5 +229,8 @@ try { setOutput(outputNameShardIndex, shardIndex); const shardTotal = [process.env.maximumShards]; setOutput(outputNameShardTotal, shardTotal); + } else { + console.error('Unexpected error:', error); + process.exit(1); } } From 74fc5491f3b5f732178861778e97ecd901520fa8 Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Thu, 14 Nov 2024 10:54:54 -0500 Subject: [PATCH 4/4] fix typo --- scripts/ci/determine-tests.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/determine-tests.mjs b/scripts/ci/determine-tests.mjs index 2cf7f02b43..319c128029 100644 --- a/scripts/ci/determine-tests.mjs +++ b/scripts/ci/determine-tests.mjs @@ -189,7 +189,7 @@ const atomicSourceComponents = join('packages', 'atomic', 'src', 'components'); try { if (runAllTests) { - throw new RunAllTestsInMergeQueue(); + throw new RunAllTestsInMergeQueueError(); } const testFiles = findAllTestFiles(atomicSourceComponents);