From a5975adf4186a796fd5e91f97789e1947a528468 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:07:54 +0100 Subject: [PATCH 1/2] test: use testResultsProcessor to check if all tests are skipped Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/test.yml | 20 ++++++++++++++++++++ __tests__/testResultsProcessor.ts | 30 ++++++++++++++++++++++++++++++ jest.config.itg.ts | 1 + jest.config.ts | 1 + 4 files changed, 52 insertions(+) create mode 100644 __tests__/testResultsProcessor.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f01fe11..4ac52e7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,9 +30,19 @@ jobs: targets: test-coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Check coverage + run: | + if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then + echo "RUN_CODECOV=true" >> $GITHUB_ENV + else + echo "RUN_CODECOV=false" >> $GITHUB_ENV + fi + shell: bash - name: Upload coverage uses: codecov/codecov-action@v3 + if: env.RUN_CODECOV == 'true' with: file: ./coverage/clover.xml flags: unit @@ -100,9 +110,19 @@ jobs: yarn test:itg-coverage --runTestsByPath __tests__/${{ matrix.test }} --coverageDirectory=./coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Check coverage + run: | + if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then + echo "RUN_CODECOV=true" >> $GITHUB_ENV + else + echo "RUN_CODECOV=false" >> $GITHUB_ENV + fi + shell: bash - name: Upload coverage uses: codecov/codecov-action@v3 + if: env.RUN_CODECOV == 'true' with: file: ./coverage/clover.xml flags: itg diff --git a/__tests__/testResultsProcessor.ts b/__tests__/testResultsProcessor.ts new file mode 100644 index 0000000..ac53feb --- /dev/null +++ b/__tests__/testResultsProcessor.ts @@ -0,0 +1,30 @@ +/** + * Copyright 2024 actions-toolkit authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const fs = require('fs'); + +module.exports = results => { + const allSkipped = results.testResults.every(result => { + return result.skipped; + }); + if (allSkipped) { + console.log('All tests were skipped!'); + // create an empty file to signal that all tests were skipped for CI + fs.closeSync(fs.openSync('./coverage/allSkipped.txt', 'w')); + } + return results; +}; diff --git a/jest.config.itg.ts b/jest.config.itg.ts index b09d6e7..ac668c0 100644 --- a/jest.config.itg.ts +++ b/jest.config.itg.ts @@ -27,5 +27,6 @@ module.exports = { moduleNameMapper: { '^csv-parse/sync': '/node_modules/csv-parse/dist/cjs/sync.cjs' }, + testResultsProcessor: './__tests__/testResultsProcessor.ts', verbose: false }; diff --git a/jest.config.ts b/jest.config.ts index 4e28d8a..0f63e27 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -43,5 +43,6 @@ module.exports = { }, collectCoverageFrom: ['src/**/{!(index.ts),}.ts'], coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'], + testResultsProcessor: './__tests__/testResultsProcessor.ts', verbose: true }; From 666b19e915caac59afdb48524d1d7d2b2ec7972a Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:09:00 +0100 Subject: [PATCH 2/2] bump codecov/codecov-action to 4 Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ac52e7..7236167 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,7 @@ jobs: shell: bash - name: Upload coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 if: env.RUN_CODECOV == 'true' with: file: ./coverage/clover.xml @@ -121,7 +121,7 @@ jobs: shell: bash - name: Upload coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 if: env.RUN_CODECOV == 'true' with: file: ./coverage/clover.xml