Test skip-comment feature of go-coverage-report action #59
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: | |
types: [opened, reopened, synchronize] | |
push: | |
branches: | |
- 'main' | |
jobs: | |
unit_tests: | |
name: "Unit tests" | |
runs-on: ubuntu-latest | |
outputs: | |
html-coverage-url: ${{ steps.upload-html.outputs.artifact-url }} | |
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 -cover -coverprofile=coverage.txt -mod=readonly ./... | |
- name: Archive code coverage results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage | |
path: coverage.txt | |
- name: Convert the plaintext coverage report to HTML | |
run: go tool cover -html coverage.txt -o coverage.html | |
- name: Upload html coverage report | |
id: upload-html | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-html | |
path: coverage.html | |
code_coverage: | |
name: "Code coverage report" | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
needs: unit_tests | |
permissions: | |
contents: read # to download code coverage results from unit_tests job | |
pull-requests: write # write permission needed to comment on PR | |
steps: | |
- id: report-step | |
uses: fgrosse/go-coverage-report@671cf6b6dc4d7a6d8196f9259ce5d674b38782bb | |
with: | |
skip-comment: true | |
- name: Leave a comment with a link | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const report = `${{ steps.report-step.outputs.coverage_report }}`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `[Coverage Report](${{ needs.unit_tests.outputs.html-coverage-url }})\n${report}` | |
}) |