mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-27 06:46:07 +08:00
Merge pull request #249 from crazy-max/test-check-coverage
test: use testResultsProcessor to check if all tests are skipped
This commit is contained in:
commit
2267dad53e
24
.github/workflows/test.yml
vendored
24
.github/workflows/test.yml
vendored
@ -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
|
||||
uses: codecov/codecov-action@v4
|
||||
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
|
||||
uses: codecov/codecov-action@v4
|
||||
if: env.RUN_CODECOV == 'true'
|
||||
with:
|
||||
file: ./coverage/clover.xml
|
||||
flags: itg
|
||||
|
30
__tests__/testResultsProcessor.ts
Normal file
30
__tests__/testResultsProcessor.ts
Normal file
@ -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;
|
||||
};
|
@ -27,5 +27,6 @@ module.exports = {
|
||||
moduleNameMapper: {
|
||||
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
||||
},
|
||||
testResultsProcessor: './__tests__/testResultsProcessor.ts',
|
||||
verbose: false
|
||||
};
|
||||
|
@ -43,5 +43,6 @@ module.exports = {
|
||||
},
|
||||
collectCoverageFrom: ['src/**/{!(index.ts),}.ts'],
|
||||
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
||||
testResultsProcessor: './__tests__/testResultsProcessor.ts',
|
||||
verbose: true
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user