|
8 | 8 | - main |
9 | 9 | - v2* |
10 | 10 | pull_request: |
| 11 | + types: [opened, reopened, synchronize] |
11 | 12 | permissions: |
12 | 13 | contents: read |
| 14 | + # Needed to leave comments |
| 15 | + pull-requests: write |
13 | 16 | jobs: |
14 | 17 | build: |
15 | 18 | runs-on: ubuntu-latest |
|
18 | 21 | - uses: actions/setup-go@v5 |
19 | 22 | with: |
20 | 23 | go-version: 1.21.8 |
21 | | - - run: go test ./... |
| 24 | + - run: go test ./... -coverprofile=./cover.out -coverpkg=./... |
| 25 | + # upload the plaintext coverage report |
| 26 | + - name: Upload txt coverage report |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: code-coverage |
| 30 | + path: ./cover.out |
| 31 | + # convert the plaintext coverage report to html |
| 32 | + - run: go tool cover -html cover.out -o cover.html |
| 33 | + # upload the html coverage report |
| 34 | + - name: Upload html coverage report |
| 35 | + uses: actions/upload-artifact@v4 |
| 36 | + with: |
| 37 | + name: code-coverage-html |
| 38 | + path: ./cover.html |
| 39 | + id: html-upload-step |
| 40 | + outputs: |
| 41 | + artifact-url: ${{ steps.html-upload-step.outputs.artifact-url }} |
| 42 | + |
| 43 | + coverage: |
| 44 | + name: "Analyze coverage report" |
| 45 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'rocket-pool/smartnode' |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: build # only run if the previous job finished successfully |
| 48 | + steps: |
| 49 | + - name: Leave a comment with a link |
| 50 | + uses: actions/github-script@v6 |
| 51 | + with: |
| 52 | + script: | |
| 53 | + github.rest.issues.createComment({ |
| 54 | + issue_number: context.issue.number, |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + body: '[Coverage Report](${{ needs.build.outputs.artifact-url }})' |
| 58 | + }) |
| 59 | + - uses: fgrosse/go-coverage-report@ff33f0f3f96d20ecb97198100852d2af288094ff |
| 60 | + with: |
| 61 | + coverage-artifact-name: "code-coverage" |
| 62 | + coverage-file-name: "cover.out" |
0 commit comments