Skip to content

Commit 59b09dc

Browse files
Replace coveralls with github action
1 parent 1bb13d3 commit 59b09dc

File tree

6 files changed

+69
-43
lines changed

6 files changed

+69
-43
lines changed

.github/workflows/ci.yaml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ jobs:
3535
go-version: 1.24.6
3636
- name: Build all binaries
3737
run: make build-all
38+
code_coverage:
39+
name: Code coverage report
40+
needs:
41+
- test
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Check out code
45+
uses: actions/checkout@v5
46+
- name: Post coverage report
47+
uses: fgrosse/go-coverage-report@v1.2.0
48+
with:
49+
coverage-artifact-name: code-coverage
50+
coverage-file-name: cover.out
51+
permissions:
52+
actions: read
53+
contents: read
54+
pull-requests: write
3855
test:
3956
name: Test
4057
needs:
@@ -50,10 +67,8 @@ jobs:
5067
go-version: 1.24.6
5168
- name: Run tests and generate coverage report
5269
run: make build/cover.out
53-
- name: Upload coverage report to Coveralls
54-
env:
55-
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
GIT_BRANCH: ${{ github.head_ref }}
57-
run: |
58-
go install github.com/mattn/goveralls@latest
59-
goveralls -service=github -coverprofile=build/cover.out
70+
- name: Archive code coverage results
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: code-coverage
74+
path: build/cover.out

Makefile.maker.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ golangciLint:
1818
githubWorkflow:
1919
ci:
2020
enabled: true
21-
coveralls: true
2221
global:
2322
defaultBranch: main # only defined here so that the "Run go-makefile-maker" Action knows it
2423

internal/core/constants.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ var DefaultGitHubEnterpriseRunsOn = map[string]string{
1717
var SugarRunsOn = []string{"self-hosted"}
1818

1919
const (
20-
CheckoutAction = "actions/checkout@v5"
21-
SetupGoAction = "actions/setup-go@v5"
20+
CheckoutAction = "actions/checkout@v5"
21+
SetupGoAction = "actions/setup-go@v5"
22+
UploadArtifactAction = "actions/upload-artifact@v4"
2223

2324
DockerLoginAction = "docker/login-action@v3"
2425
DockerMetadataAction = "docker/metadata-action@v5"
@@ -30,9 +31,10 @@ const (
3031
CodeqlAnalyzeAction = "github/codeql-action/analyze@v3"
3132
CodeqlAutobuildAction = "github/codeql-action/autobuild@v3"
3233

33-
DownloadSyftAction = "anchore/sbom-action/download-syft@v0.20.5"
34-
GolangciLintAction = "golangci/golangci-lint-action@v8"
35-
GoreleaserAction = "goreleaser/goreleaser-action@v6"
36-
MisspellAction = "reviewdog/action-misspell@v1"
37-
ReuseAction = "fsfe/reuse-action@v5"
34+
DownloadSyftAction = "anchore/sbom-action/download-syft@v0.20"
35+
GoCoverageReportAction = "fgrosse/go-coverage-report@v1.2.0"
36+
GolangciLintAction = "golangci/golangci-lint-action@v8"
37+
GoreleaserAction = "goreleaser/goreleaser-action@v6"
38+
MisspellAction = "reviewdog/action-misspell@v1"
39+
ReuseAction = "fsfe/reuse-action@v5"
3840
)

internal/ghworkflow/workflow.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type permissions struct {
5959
Checks githubTokenScope `yaml:"checks,omitempty"`
6060
Contents githubTokenScope `yaml:"contents,omitempty"`
6161
Packages githubTokenScope `yaml:"packages,omitempty"`
62+
PullRequests githubTokenScope `yaml:"pull-requests,omitempty"`
6263
SecurityEvents githubTokenScope `yaml:"security-events,omitempty"`
6364
}
6465

@@ -119,6 +120,11 @@ type job struct {
119120

120121
// A map of <service_id> to their configuration(s).
121122
Services map[string]jobService `yaml:"services,omitempty"`
123+
124+
// Permissions modify the default permissions granted to the GITHUB_TOKEN. If you
125+
// specify the access for any of the scopes, all of those that are not specified are
126+
// set to 'none'.
127+
Permissions permissions `yaml:"permissions,omitempty"`
122128
}
123129

124130
type JobStrategy struct {

internal/ghworkflow/workflow_ci.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func ciWorkflow(cfg core.Configuration, sr golang.ScanResult) {
1919

2020
w := newWorkflow("CI", ghwCfg.Global.DefaultBranch, ignorePaths)
2121
w.On.WorkflowDispatch.manualTrigger = true
22+
w.On.Push.Branches = []string{ghwCfg.Global.DefaultBranch}
2223

2324
if w.deleteIf(ghwCfg.CI.Enabled) {
2425
return
@@ -52,36 +53,36 @@ func ciWorkflow(cfg core.Configuration, sr golang.ScanResult) {
5253
Run: makeMultilineYAMLString(testCmd),
5354
})
5455

55-
if ghwCfg.CI.Coveralls && !ghwCfg.IsSelfHostedRunner {
56-
multipleOS := len(ghwCfg.CI.RunsOn) > 1
57-
env := map[string]string{
58-
"GIT_BRANCH": "${{ github.head_ref }}",
59-
"COVERALLS_TOKEN": "${{ secrets.GITHUB_TOKEN }}",
60-
}
61-
installGoveralls := "go install github.com/mattn/goveralls@latest"
62-
cmd := "goveralls -service=github -coverprofile=build/cover.out"
63-
if multipleOS {
64-
cmd += ` -parallel -flagname="Unit-${{ matrix.os }}"`
65-
}
66-
testJob.addStep(jobStep{
67-
Name: "Upload coverage report to Coveralls",
68-
Run: makeMultilineYAMLString([]string{installGoveralls, cmd}),
69-
Env: env,
70-
})
56+
// see https://github.com/fgrosse/go-coverage-report#usage
57+
coverageArtifactName := "code-coverage"
58+
testJob.addStep(jobStep{
59+
Name: "Archive code coverage results",
60+
Uses: core.UploadArtifactAction,
61+
With: map[string]any{
62+
"name": coverageArtifactName,
63+
"path": "build/cover.out",
64+
},
65+
})
7166

72-
if multipleOS {
73-
// 04. Tell Coveralls to merge coverage results.
74-
finishJob := baseJobWithGo("Finish", cfg)
75-
finishJob.Needs = []string{"test"} // this is the <job_id> for the test job
76-
finishJob.addStep(jobStep{
77-
Name: "Coveralls post build webhook",
78-
Run: makeMultilineYAMLString([]string{installGoveralls, "goveralls -parallel-finish"}),
79-
Env: env,
80-
})
81-
w.Jobs["finish"] = finishJob
82-
}
83-
}
8467
w.Jobs["test"] = testJob
8568

69+
// see https://github.com/fgrosse/go-coverage-report#usage
70+
codeCov := baseJob("Code coverage report", cfg.GitHubWorkflow)
71+
codeCov.Needs = []string{"test"}
72+
codeCov.Permissions = permissions{
73+
Contents: "read",
74+
Actions: "read",
75+
PullRequests: "write",
76+
}
77+
codeCov.addStep(jobStep{
78+
Name: "Post coverage report",
79+
Uses: core.GoCoverageReportAction,
80+
With: map[string]any{
81+
"coverage-artifact-name": coverageArtifactName,
82+
"coverage-file-name": "cover.out",
83+
},
84+
})
85+
w.Jobs["code_coverage"] = codeCov
86+
8687
writeWorkflowToFile(w)
8788
}

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func main() {
112112
// Render GitHub workflows
113113
if cfg.GitHubWorkflow != nil {
114114
logg.Debug("rendering GitHub Actions workflows")
115+
if cfg.GitHubWorkflow.CI.Coveralls {
116+
logg.Fatal("Coveralls support has been removed, please remove it from your Makefile.maker.yaml")
117+
}
115118
ghworkflow.Render(cfg, sr)
116119
}
117120

0 commit comments

Comments
 (0)