Skip to content

Instantly share code, notes, and snippets.

@nilsreichardt
Created February 6, 2022 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsreichardt/1463bb948f8b1a26ab155032b3201b1c to your computer and use it in GitHub Desktop.
Save nilsreichardt/1463bb948f8b1a26ab155032b3201b1c to your computer and use it in GitHub Desktop.
A GitHub action to report code coverage
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/lcov-reporter-action@v0.3.1
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