Created
February 6, 2022 12:38
-
-
Save nilsreichardt/1463bb948f8b1a26ab155032b3201b1c to your computer and use it in GitHub Desktop.
A GitHub action to report code coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
env: | |
WORKING_DIRECTORY: backend/cloud_functions | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install dependencies | |
working-directory: ${{ env.WORKING_DIRECTORY }} | |
run: npm install | |
# Running tests for head branch and create a coverage report. | |
- name: Run tests | |
working-directory: ${{ env.WORKING_DIRECTORY }} | |
run: | | |
npm install -g nyc | |
npm run ci | |
# In order to show the coverage difference between head and base branch, | |
# we need to create a coverage report for the base branch as well. | |
- name: Create coverage report for base branch | |
run: | | |
mv $WORKING_DIRECTORY/coverage/lcov.info $WORKING_DIRECTORY/coverage/lcov_head.info | |
git fetch | |
git checkout origin/${{ github.event.pull_request.base.ref }} | |
cd $WORKING_DIRECTORY && npm run ci | |
- name: Post coverage report | |
uses: romeovs/[email protected] | |
with: | |
lcov-file: "${{ env.WORKING_DIRECTORY }}/coverage/lcov_head.info" | |
lcov-base: "${{ env.WORKING_DIRECTORY }}/coverage/lcov.info" | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
delete-old-comments: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment