Skip to content

Commit

Permalink
Add coverage reports to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jshufro committed Jul 12, 2024
1 parent edcbd62 commit e75bd5c
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ on:
- main
- v2*
pull_request:
types: [opened, reopened, synchronize]
permissions:
contents: read
# Needed to leave comments
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -18,4 +21,42 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.21.8
- run: go test ./...
- run: go test ./... -coverprofile=./cover.out -coverpkg=./...
# upload the plaintext coverage report
- name: Upload txt coverage report
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: ./cover.out
# convert the plaintext coverage report to html
- run: go tool cover -html cover.out -o cover.html
# upload the html coverage report
- name: Upload html coverage report
uses: actions/upload-artifact@v4
with:
name: code-coverage-html
path: ./cover.html
id: html-upload-step
outputs:
artifact-url: ${{ steps.html-upload-step.outputs.artifact-url }}

coverage:
name: "Analyze coverage report"
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'rocket-pool/smartnode'
runs-on: ubuntu-latest
needs: build # only run if the previous job finished successfully
steps:
- name: Leave a comment with a link
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '[Coverage Report](${{ needs.build.outputs.artifact-url }})'
})
- uses: fgrosse/go-coverage-report@ff33f0f3f96d20ecb97198100852d2af288094ff
with:
coverage-artifact-name: "code-coverage"
coverage-file-name: "cover.out"

0 comments on commit e75bd5c

Please sign in to comment.