Skip to content

Commit a7203a0

Browse files
committed
Merge branch 'main' into add_test_args
2 parents 2beaa83 + 1e5d0e1 commit a7203a0

File tree

11 files changed

+96
-54
lines changed

11 files changed

+96
-54
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ 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+
if: github.event_name == 'pull_request'
41+
needs:
42+
- test
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Check out code
46+
uses: actions/checkout@v5
47+
- name: Post coverage report
48+
uses: fgrosse/go-coverage-report@v1.2.0
49+
with:
50+
coverage-artifact-name: code-coverage
51+
coverage-file-name: cover.out
52+
permissions:
53+
actions: read
54+
contents: read
55+
pull-requests: write
3856
test:
3957
name: Test
4058
needs:
@@ -50,10 +68,8 @@ jobs:
5068
go-version: 1.24.6
5169
- name: Run tests and generate coverage report
5270
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
71+
- name: Archive code coverage results
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: code-coverage
75+
path: build/cover.out

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ run-shellcheck: FORCE install-shellcheck
108108

109109
build/cover.out: FORCE | build
110110
@printf "\e[1;36m>> Running tests\e[0m\n"
111-
@env $(GO_TESTENV) go test -shuffle=on -p 1 -coverprofile=$@ $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=go-makefile-maker -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTFLAGS) $(GO_TESTPKGS)
111+
@env $(GO_TESTENV) go test -shuffle=on -p 1 -coverprofile=build/coverprofile.out $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=go-makefile-maker -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTFLAGS) $(GO_TESTPKGS)
112+
@awk < build/coverprofile.out '$$1 != "mode:" { is_filename[$$1] = true; counts1[$$1]+=$$2; counts2[$$1]+=$$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | $(SED) '1s/^/mode: count\n/' > $@
112113

113114
build/cover.html: build/cover.out
114115
@printf "\e[1;36m>> go tool cover > build/cover.html\e[0m\n"

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

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.24
44

55
require (
66
github.com/majewsky/gg v1.3.0
7-
github.com/sapcc/go-api-declarations v1.17.3
8-
github.com/sapcc/go-bits v0.0.0-20250820121943-822ee6190027
7+
github.com/sapcc/go-api-declarations v1.17.4
8+
github.com/sapcc/go-bits v0.0.0-20250828142518-d29beaf1bcca
99
github.com/spf13/pflag v1.0.7
1010
golang.org/x/mod v0.27.0
1111
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
22
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
33
github.com/majewsky/gg v1.3.0 h1:1bBuQ+S1u9wuD8YT2OMdngEUctwv+xx5D6bZTd1lAto=
44
github.com/majewsky/gg v1.3.0/go.mod h1:KC7qUlln1VBY90OE0jXMNjXW2b9B4jJ1heYQ08OzeAg=
5-
github.com/sapcc/go-api-declarations v1.17.3 h1:ILRfsFD9ChSeekyzlDInLMqjC830gBcyK6ULlFdP45I=
6-
github.com/sapcc/go-api-declarations v1.17.3/go.mod h1:MWmLjmvjftgyAugNUfIhsDsHIzXH1pn32cWLZpiluKg=
7-
github.com/sapcc/go-bits v0.0.0-20250820121943-822ee6190027 h1:LC0YA3Kcmso6/POJIQ+W5RUVMwWt7PU5tbSnJhglU7Q=
8-
github.com/sapcc/go-bits v0.0.0-20250820121943-822ee6190027/go.mod h1:pMKo3e45ENJVwoTNqz/RWaRg0t++ySpjqWgygBjDFuM=
5+
github.com/sapcc/go-api-declarations v1.17.4 h1:F4smuE9x1NJ/7NAdytJ1wekeXT3QeRaYu3L/HyWKqqo=
6+
github.com/sapcc/go-api-declarations v1.17.4/go.mod h1:MWmLjmvjftgyAugNUfIhsDsHIzXH1pn32cWLZpiluKg=
7+
github.com/sapcc/go-bits v0.0.0-20250828142518-d29beaf1bcca h1:yqW5yQgIs+g9Cd2iq8l8L5L8Yq0+o1JvmOFDhJm36Hk=
8+
github.com/sapcc/go-bits v0.0.0-20250828142518-d29beaf1bcca/go.mod h1:455iF3CJNh/ZvXuUQPEuG/ZTHlTobVGQtlUEiDGKcbk=
99
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
1010
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
1111
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=

internal/core/constants.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ var DefaultGitHubEnterpriseRunsOn = map[string]string{
1616
}
1717
var SugarRunsOn = []string{"self-hosted"}
1818

19+
// GetUploadArtifactAction works around GitHub not supporting their own stuff
20+
// https://github.com/actions/upload-artifact/issues/537
21+
func GetUploadArtifactAction(isSelfHostedRunner bool) string {
22+
if isSelfHostedRunner {
23+
return "actions/upload-artifact@v2"
24+
} else {
25+
return "actions/upload-artifact@v4"
26+
}
27+
}
28+
1929
const (
2030
CheckoutAction = "actions/checkout@v5"
2131
SetupGoAction = "actions/setup-go@v5"
@@ -30,9 +40,10 @@ const (
3040
CodeqlAnalyzeAction = "github/codeql-action/analyze@v3"
3141
CodeqlAutobuildAction = "github/codeql-action/autobuild@v3"
3242

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"
43+
DownloadSyftAction = "anchore/sbom-action/download-syft@v0.20"
44+
GoCoverageReportAction = "fgrosse/go-coverage-report@v1.2.0"
45+
GolangciLintAction = "golangci/golangci-lint-action@v8"
46+
GoreleaserAction = "goreleaser/goreleaser-action@v6"
47+
MisspellAction = "reviewdog/action-misspell@v1"
48+
ReuseAction = "fsfe/reuse-action@v5"
3849
)

internal/ghworkflow/workflow.go

Lines changed: 9 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

@@ -97,6 +98,9 @@ type job struct {
9798
// The name of the job displayed on GitHub.
9899
Name string `yaml:"name,omitempty"`
99100

101+
// You can use the if conditional to prevent a step from running unless a condition is met.
102+
If string `yaml:"if,omitempty"`
103+
100104
// List of <job_id> that must complete successfully before this job will run.
101105
Needs []string `yaml:"needs,omitempty"`
102106

@@ -119,6 +123,11 @@ type job struct {
119123

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

124133
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,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,37 @@ 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.GetUploadArtifactAction(ghwCfg.IsSelfHostedRunner),
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.If = "github.event_name == 'pull_request'"
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
}

internal/makefile/makefile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ endif
378378
},
379379
}
380380

381-
testRunner := "go test -shuffle=on -p 1 -coverprofile=$@"
381+
// NOTE: Ginkgo will always write the coverage profile as "coverprofile.out", so we will choose the same path for non-Ginkgo tests, too.
382+
// The actual final path is build/cover.out, which will be filled by a post-processing step below.
383+
testRunner := "go test -shuffle=on -p 1 -coverprofile=build/coverprofile.out"
382384
if sr.UseGinkgo {
383385
testRunner = "go run github.com/onsi/ginkgo/v2/ginkgo run --randomize-all -output-dir=build"
384386
}
@@ -390,9 +392,8 @@ endif
390392
} else {
391393
testRule.recipe = append(testRule.recipe, `@env $(GO_TESTENV) `+goTest)
392394
}
393-
if sr.UseGinkgo {
394-
testRule.recipe = append(testRule.recipe, `@mv build/coverprofile.out build/cover.out`)
395-
}
395+
// workaround for <https://github.com/fgrosse/go-coverage-report/issues/61>: merge block coverage manually
396+
testRule.recipe = append(testRule.recipe, `@awk < build/coverprofile.out '$$1 != "mode:" { is_filename[$$1] = true; counts1[$$1]+=$$2; counts2[$$1]+=$$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | $(SED) '1s/^/mode: count\n/' > $@`)
396397

397398
test.addRule(testRule)
398399

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)