A @tangro action to run jest with coverage. The command which is run is configurable and defaults to coverage:collect
.
Either use a specific version of this action, or latest
which should always point to the latest version of tangro/actions-coverage
. The latest published version of this action is v1.1.17
.
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/[email protected]
with:
node-version: 16.x
- name: Run npm install
run: npm install
- name: Collect Coverage
uses: tangro/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
Attention Do not forget to pass the
GITHUB_TOKEN
and theGITHUB_CONTEXT
Steps the example job will perform:
- Check out the latest code
- Use node
- Run npm install
- (this action) Collect the coverage using jest
The action will call npm run ${command}
. The command
can be specified by passing an input variable command
to the Action. It defaults to coverage:collect
. The command
should run jest --coverage --coverageReporters=\"json\" --coverageReporters=\"json-summary\" --coverageReporters=\"lcov\" --coverageReporters=\"text\"
.
The action will set a status to the commit to pending
under the context Tangro CI/coverage
. When it finishes successfully it will change the status to success
and the coverage percentages will be displayed in the description. If it fails the action will set the status to failed
.
It is also possible that the action posts a comment with the result to the commit. You have to set post-comment
to true
.
steps:
- name: Collect Coverage
uses: tangro/[email protected]
with:
command: 'coverage'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
steps:
- name: Collect Coverage
uses: tangro/[email protected]
with:
post-comment: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
There is also an option to adapt the minimum coverage percentage limits that need to be achieved for the build to complete successfully (Defaults to 100
). You can configure an overall minimum by setting the action argument coverage
and/or setting specific minimums for the different coverage metrics: coverage-lines
, coverage-statements
, coverage-functions
or coverage-branches
.
steps:
- name: Collect Coverage
uses: tangro/[email protected]
with:
coverage: 94
coverage-lines: 96
coverage-branches: 92
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
You can also publish the results to a static file server. The action will write the results into i18next/index.html
.
You can publish the results with our custom deploy actions
coverage:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout latest code
uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/[email protected]
with:
node-version: 16.x
- name: Authenticate with GitHub package registry
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.ACCESS_TOKEN }}" >> ~/.npmrc
- name: Run npm install
run: npm install
- name: Collect Coverage
uses: tangro/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Zip coverage results
run: |
cd coverage
cd lcov-report
zip --quiet --recurse-paths ../../coverage.zip *
- name: Deploy coverage
uses: tangro/[email protected]
with:
context: auto
zip-file: coverage.zip
deploy-url: ${{secrets.DEPLOY_URL}}
project: coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_CONTEXT: ${{ toJson(github) }}
DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
Attention Do not forget to use the correct
DEPLOY_URL
and provide all the tokens the actions need.
Follow the guide of the tangro-actions-template
-
npm run update-readme
- Run this script to update the README with the latest versions.You do not have to run this script, since it is run automatically by the release action
-
npm run update-dependencies
- Run this script to update all the dependencies