ci code coverage report #20
Workflow file for this run
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: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
unit_tests: | |
name: "Unit tests" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ^1.22 | |
- name: Test | |
run: go test -v -cover -coverprofile=coverage.txt -covermode=count -mod=readonly ./... | |
- name: Archive code coverage results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage | |
path: coverage.txt | |
code_coverage: | |
name: "Code coverage report" | |
runs-on: ubuntu-latest | |
needs: unit_tests | |
env: | |
GH_REPO: ${{ github.repository }} | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ^1.22 | |
- name: Install go-coverage-report | |
run: | | |
go install github.com/fgrosse/go-coverage-report@v0.1.0 | |
which go-coverage-report | |
- name: Determine changed files | |
id: changed-files | |
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 # v42.1.0 | |
with: | |
write_output_files: true | |
json: true | |
files: | | |
**.go | |
files_ignore: | | |
**_test.go | |
vendor/** | |
- name: Download code coverage results | |
uses: actions/download-artifact@v4 | |
with: | |
name: code-coverage | |
- name: Rename code coverage results file | |
run: | | |
mv coverage.txt new-coverage.txt | |
- name: Download code coverage results from target branch # TODO: download from latest successful run on the target branch instead of main branch | |
run: | | |
gh run download --name=code-coverage | |
mv coverage.txt old-coverage.txt | |
- name: Compare code coverage results | |
run: | | |
go-coverage-report \ | |
-prefix=github.com/fgrosse/prioqueue \ | |
old-coverage.txt \ | |
new-coverage.txt \ | |
.github/outputs/all_changed_files.json \ | |
> coverage-comment.md | |
- name: Comment on pull request | |
run: gh pr comment ${{ github.event.number }} --body-file=coverage-comment.md |