Skip to content

Commit f04ce24

Browse files
Replace coveralls with github action
1 parent 1bb13d3 commit f04ce24

File tree

6 files changed

+75
-43
lines changed

6 files changed

+75
-43
lines changed

.github/workflows/ci.yaml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ name: CI
1818
- '*'
1919
paths-ignore:
2020
- '**.md'
21+
types:
22+
- opened
23+
- reopened
24+
- synchronize
2125
workflow_dispatch: {}
2226
permissions:
2327
contents: read
@@ -35,6 +39,23 @@ jobs:
3539
go-version: 1.24.6
3640
- name: Build all binaries
3741
run: make build-all
42+
code_coverage:
43+
name: Code coverage report
44+
needs:
45+
- test
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Check out code
49+
uses: actions/checkout@v5
50+
- name: Post coverage report
51+
uses: fgrosse/go-coverage-report@v1.2.0
52+
with:
53+
coverage-artifact-name: code-coverage
54+
coverage-file-name: cover.out
55+
permissions:
56+
actions: read
57+
contents: read
58+
pull-requests: write
3859
test:
3960
name: Test
4061
needs:
@@ -50,10 +71,8 @@ jobs:
5071
go-version: 1.24.6
5172
- name: Run tests and generate coverage report
5273
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
74+
- name: Archive code coverage results
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: code-coverage
78+
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: 7 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

@@ -83,6 +84,7 @@ type pushAndPRTriggerOpts struct {
8384
Paths []string `yaml:"paths,omitempty"`
8485
PathsIgnore []string `yaml:"paths-ignore,omitempty"`
8586
Tags []string `yaml:"tags,omitempty"`
87+
Types []string `yaml:"types,omitempty"`
8688
}
8789

8890
type workflowDispatch struct {
@@ -119,6 +121,11 @@ type job struct {
119121

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

124131
type JobStrategy struct {

internal/ghworkflow/workflow_ci.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ 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.PullRequest.Types = []string{"opened", "reopened", "synchronize"}
23+
w.On.Push.Branches = []string{ghwCfg.Global.DefaultBranch}
2224

2325
if w.deleteIf(ghwCfg.CI.Enabled) {
2426
return
@@ -52,36 +54,36 @@ func ciWorkflow(cfg core.Configuration, sr golang.ScanResult) {
5254
Run: makeMultilineYAMLString(testCmd),
5355
})
5456

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-
})
57+
// see https://github.com/fgrosse/go-coverage-report#usage
58+
coverageArtifactName := "code-coverage"
59+
testJob.addStep(jobStep{
60+
Name: "Archive code coverage results",
61+
Uses: core.UploadArtifactAction,
62+
With: map[string]any{
63+
"name": coverageArtifactName,
64+
"path": "build/cover.out",
65+
},
66+
})
7167

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-
}
8468
w.Jobs["test"] = testJob
8569

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

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)