Skip to content

Commit f5b8e98

Browse files
authored
Merge pull request #287 from smlx/github-coverage
feat: switch from third-party coverage tool to GitHub API
2 parents a482170 + b840535 commit f5b8e98

3 files changed

Lines changed: 18 additions & 25 deletions

File tree

.github/dependency-review-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ allow-licenses:
2424
- 'LicenseRef-scancode-google-patent-license-golang'
2525

2626
allow-dependencies-licenses:
27-
# this action is GPL-3 but it is only used in CI
28-
# https://github.com/actions/dependency-review-action/issues/530#issuecomment-1638291806
29-
- pkg:githubactions/vladopajic/go-test-coverage@bcd064e5ceef1ccec5441519eb054263b6a44787
3027
# this package is MPL-2.0 and has a CNCF exception
3128
# https://github.com/cncf/foundation/blob/9b8c9173c2101c1b4aedad3caf2c0128715133f6/license-exceptions/cncf-exceptions-2022-04-12.json#L43C17-L43C47
3229
- pkg:golang/github.com/go-sql-driver/mysql

.github/workflows/coverage.yaml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ on:
33
push:
44
branches:
55
- main
6+
pull_request:
7+
branches:
8+
- main
69
permissions: {}
710
jobs:
811
coverage:
912
permissions:
10-
contents: write
13+
contents: read
14+
code-quality: write
15+
pull-requests: read # not sure if this is required
1116
runs-on: ubuntu-latest
1217
steps:
1318
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
@@ -17,11 +22,15 @@ jobs:
1722
- name: Calculate coverage
1823
run: |
1924
go test -count=1 -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./...
20-
- name: Generage coverage badge
21-
uses: vladopajic/go-test-coverage@a93b868a4cbcbf18dc3781650fad241f0020e609 # v2.18.8
25+
- name: Convert Go coverage profile to cobertuba format
26+
run: |
27+
go install github.com/boumenot/gocover-cobertura@v1.5.0
28+
gocover-cobertura < cover.out > cover.xml
29+
- name: Upload coverage to GitHub API
30+
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1.3.0
2231
with:
23-
profile: cover.out
24-
local-prefix: github.com/${{ github.repository }}
25-
git-token: ${{ secrets.GITHUB_TOKEN }}
26-
# orphan branch for storing badges
27-
git-branch: badges
32+
file: cover.xml
33+
language: Go
34+
label: code-coverage/go-test
35+
# feature only available for team and enterprise accounts
36+
fail-on-error: false

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Go Reference](https://pkg.go.dev/badge/github.com/smlx/go-cli-github.svg)](https://pkg.go.dev/github.com/smlx/go-cli-github)
44
[![Release](https://github.com/smlx/go-cli-github/actions/workflows/release.yaml/badge.svg)](https://github.com/smlx/go-cli-github/actions/workflows/release.yaml)
5-
[![coverage](https://raw.githubusercontent.com/smlx/go-cli-github/badges/.badges/main/coverage.svg)](https://github.com/smlx/go-cli-github/actions/workflows/coverage.yaml)
65
[![Go Report Card](https://goreportcard.com/badge/github.com/smlx/go-cli-github)](https://goreportcard.com/report/github.com/smlx/go-cli-github)
76
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/smlx/go-cli-github/badge)](https://securityscorecards.dev/viewer/?uri=github.com/smlx/go-cli-github)
87
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8168/badge)](https://www.bestpractices.dev/projects/8168)
@@ -23,7 +22,7 @@ It also automatically builds and tests your code using [GitHub Actions](https://
2322
* Test Pull Requests using `go test`.
2423
* Build container images from Pull Requests and push them to the GitHub container registry for manual testing and review.
2524
* Static code analysis using [CodeQL](https://codeql.github.com/) and [Go Report Card](https://goreportcard.com/).
26-
* Coverage analysis using the [go-test-coverage action](https://github.com/vladopajic/go-test-coverage).
25+
* Coverage analysis using the [GitHub coverage API](https://docs.github.com/en/code-security/how-tos/maintain-quality-code/set-up-code-coverage).
2726
* Security analysis using [OpenSSF](https://securityscorecards.dev).
2827
* Signed binary and container release artifacts using [artifact attestations](https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
2928
* SBOM generation for both release artifacts and container images, with image SBOMs pushed to the container registry.
@@ -54,18 +53,6 @@ Then push some code to main:
5453
git push -u origin main
5554
```
5655

57-
1. Create the `badges` branch for storing the README coverage badge.
58-
59-
```bash
60-
git checkout --orphan badges
61-
git rm -rf .
62-
rm -f .gitignore
63-
echo 'This branch exists only to store the coverage badge in the README on `main`.' > README.md
64-
git add README.md
65-
git commit -m 'chore: initialize the badges branch'
66-
git push origin badges
67-
```
68-
6956
Then customize the code for your repository:
7057

7158
1. Check out a new branch to set up the repo `git checkout -b setup main`

0 commit comments

Comments
 (0)