From bdef79428396c1509379e8a06914d51638c8b81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 27 Jul 2022 09:52:30 +0200 Subject: [PATCH] fix(ci): make CTS only run generated tests (#871) --- .github/actions/restore-artifacts/action.yml | 6 ------ .github/workflows/check.yml | 4 ++-- scripts/ci/githubActions/createMatrix.ts | 22 ++++++++++++++------ scripts/ci/githubActions/types.ts | 4 ++++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/actions/restore-artifacts/action.yml b/.github/actions/restore-artifacts/action.yml index 387652361d..8a2df87a0f 100644 --- a/.github/actions/restore-artifacts/action.yml +++ b/.github/actions/restore-artifacts/action.yml @@ -71,8 +71,6 @@ runs: shell: bash run: | rm -rf clients/algoliasearch-client-javascript - rm -rf tests/output/javascript/src/client || true - rm -rf tests/output/javascript/src/methods || true unzip -q -o clients-javascript.zip && rm clients-javascript.zip # PHP @@ -87,8 +85,6 @@ runs: shell: bash run: | rm -rf clients/algoliasearch-client-php - rm -rf tests/output/php/src/client || true - rm -rf tests/output/php/src/methods || true unzip -q -o clients-php.zip && rm clients-php.zip # Java @@ -103,6 +99,4 @@ runs: shell: bash run: | rm -rf clients/algoliasearch-client-java-2 - rm -rf tests/output/java/src/test/java/com/algolia/client || true - rm -rf tests/output/java/src/test/java/com/algolia/methods || true unzip -q -o clients-java.zip && rm clients-java.zip diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 08289ad69c..edd365a7e0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -246,7 +246,7 @@ jobs: if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }} run: cd ${{ matrix.client.path }} && yarn workspace algoliasearch test - - name: Remove CTS output before generate + - name: Remove previous CTS output run: rm -rf ${{ matrix.client.testsToDelete }} || true - name: Generate CTS @@ -278,7 +278,7 @@ jobs: run: yarn cli cts run ${{ matrix.client.language }} - name: Zip artifact before storing - run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsRootFolder }} -x "**/node_modules**" "**/.yarn/cache/**" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" + run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} -x "**/node_modules**" "**/.yarn/cache/**" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" - name: Store ${{ matrix.client.language }} clients uses: actions/upload-artifact@v3 diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index 682b129044..4c52698ff4 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -86,19 +86,28 @@ async function getClientMatrix(baseBranch: string): Promise { const testsOutputBase = `${testsRootFolder}/${getTestOutputFolder( language )}`; - const testsToDelete = matrix[language].toRun + // We delete all tests because the CTS runs everything present in the folder + // but we then re-generate the ones that needs to run + const testsToDelete = `${testsOutputBase}/client ${testsOutputBase}/methods/requests`; + + // We only store tests of clients that ran during this job, the rest stay as is + let testsToStore = matrix[language].toRun .map((client) => { const clientName = createClientName(client, language); const extension = getTestExtension(language); - // REMOVE THIS IN NEXT PR !! - const oldPath = - language === 'php' ? createClientName(client, language) : client; - const tmpPath = `${testsOutputBase}/client/${oldPath}${extension} ${testsOutputBase}/methods/requests/${oldPath}${extension}`; - return `${testsOutputBase}/client/${clientName}${extension} ${testsOutputBase}/methods/requests/${clientName}${extension} ${tmpPath}`; + return `${testsOutputBase}/client/${clientName}${extension} ${testsOutputBase}/methods/requests/${clientName}${extension}`; }) .join(' '); + switch (language) { + case 'java': + testsToStore = `${testsToStore} ${testsRootFolder}/build.gradle`; + break; + default: + break; + } + clientMatrix.client.push({ language, path: matrix[language].path, @@ -111,6 +120,7 @@ async function getClientMatrix(baseBranch: string): Promise { ]), testsRootFolder, testsToDelete, + testsToStore, }); console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`); } diff --git a/scripts/ci/githubActions/types.ts b/scripts/ci/githubActions/types.ts index 0e7779b7e7..7fe6a8403f 100644 --- a/scripts/ci/githubActions/types.ts +++ b/scripts/ci/githubActions/types.ts @@ -37,6 +37,10 @@ export type ClientMatrix = BaseMatrix & { * The test output path to delete before running the CTS generation. */ testsToDelete: string; + /** + * The test output path to store in the artifact. + */ + testsToStore: string; }; export type SpecMatrix = Pick & {