Skip to content

Commit 211175a

Browse files
authored
feat: add option to print detailed debugging output (#180)
1 parent 2030c01 commit 211175a

File tree

15 files changed

+381
-237
lines changed

15 files changed

+381
-237
lines changed

.github/.testcoverage-local.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ override:
1111
threshold: 66
1212
exclude:
1313
paths:
14-
- main\.go$
14+
- main\.go$
15+
- main_config\.go$

.github/.testcoverage.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ threshold:
66
total: 100
77
exclude:
88
paths:
9-
- main\.go$
9+
- main\.go$
10+
- main_config\.go$

.github/workflows/action-test.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,22 @@ jobs:
125125
config: ./.github/workflows/testdata/total100.yml
126126
threshold-file: 0
127127
threshold-package: 0
128-
threshold-total: 0
128+
threshold-total: 0
129+
130+
## Test 6
131+
132+
- name: "test: debug output"
133+
uses: ./
134+
id: test-6
135+
continue-on-error: true
136+
with:
137+
profile: unexistant-profile.out
138+
debug: true
139+
threshold-file: 0
140+
threshold-package: 0
141+
threshold-total: 100
142+
143+
- name: "check: test should have failed"
144+
if: steps.test-4.outcome != 'failure'
145+
shell: bash
146+
run: echo "Previous step should have failed" && exit 1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test:
2727
# Runs test coverage check
2828
.PHONY: check-coverage
2929
check-coverage: test
30-
go run ./main.go --config=./.github/.testcoverage-local.yml
30+
go run ./ --config=./.github/.testcoverage-local.yml
3131

3232
# View coverage profile
3333
.PHONY: view-coverage

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ inputs:
1313
required: false
1414
default: ""
1515
type: string
16+
debug:
17+
description: Prints additional debugging output when running action.
18+
required: false
19+
default: false
20+
type: boolean
1621

1722
# Individual properties
1823
profile:
@@ -138,6 +143,7 @@ runs:
138143
- --config=${{ inputs.config || '''''' }}
139144
- --profile=${{ inputs.profile || '''''' }}
140145
- --source-dir=${{ inputs.source-dir || '''''' }}
146+
- --debug=${{ inputs.debug }}
141147
- --github-action-output=true
142148
- --threshold-file=${{ inputs.threshold-file }}
143149
- --threshold-package=${{ inputs.threshold-package }}

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/google/go-github/v56 v56.0.0
1111
github.com/johannesboyne/gofakes3 v0.0.0-20230914150226-f005f5cc03aa
1212
github.com/narqo/go-badge v0.0.0-20230821190521-c9a75c019a59
13+
github.com/rs/zerolog v1.34.0
1314
github.com/stretchr/testify v1.10.0
1415
golang.org/x/tools v0.26.0
1516
gopkg.in/yaml.v3 v3.0.1
@@ -22,11 +23,14 @@ require (
2223
github.com/google/go-querystring v1.1.0 // indirect
2324
github.com/jmespath/go-jmespath v0.4.0 // indirect
2425
github.com/kr/pretty v0.3.1 // indirect
26+
github.com/mattn/go-colorable v0.1.13 // indirect
27+
github.com/mattn/go-isatty v0.0.19 // indirect
2528
github.com/pmezard/go-difflib v1.0.0 // indirect
2629
github.com/rogpeppe/go-internal v1.11.0 // indirect
2730
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
2831
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500 // indirect
2932
golang.org/x/image v0.18.0 // indirect
33+
golang.org/x/sys v0.26.0 // indirect
3034
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3135
gopkg.in/yaml.v2 v2.4.0 // indirect
3236
)

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oy
55
github.com/aws/aws-sdk-go v1.44.256/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
66
github.com/aws/aws-sdk-go v1.49.4 h1:qiXsqEeLLhdLgUIyfr5ot+N/dGPWALmtM1SetRmbUlY=
77
github.com/aws/aws-sdk-go v1.49.4/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
8+
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
89
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
910
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1011
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1112
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
1214
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
1315
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
1416
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -31,6 +33,11 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
3133
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
3234
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
3335
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
36+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
37+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
38+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
39+
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
40+
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
3441
github.com/narqo/go-badge v0.0.0-20230821190521-c9a75c019a59 h1:kbREB9muGo4sHLoZJD/E/IV8yK3Y15eEA9mYi/ztRsk=
3542
github.com/narqo/go-badge v0.0.0-20230821190521-c9a75c019a59/go.mod h1:m9BzkaxwU4IfPQi9ko23cmuFltayFe8iS0dlRlnEWiM=
3643
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -40,6 +47,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4047
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
4148
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
4249
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
50+
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
51+
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
52+
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
4353
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8=
4454
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
4555
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500 h1:WnNuhiq+FOY3jNj6JXFT+eLN3CQ/oPIsDPRanvwsmbI=
@@ -77,9 +87,14 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
7787
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7888
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7989
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
90+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8091
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8192
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
93+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8294
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
95+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
96+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
97+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
8398
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
8499
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
85100
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

main.go

Lines changed: 12 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,38 @@
11
package main
22

33
import (
4-
"errors"
54
"fmt"
65
"os"
7-
"strings"
8-
9-
"github.com/alexflint/go-arg"
106

117
"github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage"
8+
"github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/logger"
129
)
1310

1411
const (
1512
Version = "v2.13.2" // VERSION: when changing version update version in other places
1613
Name = "go-test-coverage"
1714
)
1815

19-
const (
20-
// default value of string variables passed by CI
21-
ciDefaultString = `''`
22-
// default value of int variables passed by CI
23-
ciDefaultInt = -1
24-
)
25-
26-
type args struct {
27-
ConfigPath string `arg:"-c,--config"`
28-
Profile string `arg:"-p,--profile" help:"path to coverage profile"`
29-
LocalPrefix string `arg:"-l,--local-prefix"` // deprecated
30-
SourceDir string `arg:"-s,--source-dir"`
31-
GithubActionOutput bool `arg:"-o,--github-action-output"`
32-
ThresholdFile int `arg:"-f,--threshold-file"`
33-
ThresholdPackage int `arg:"-k,--threshold-package"`
34-
ThresholdTotal int `arg:"-t,--threshold-total"`
35-
36-
BreakdownFileName string `arg:"--breakdown-file-name"`
37-
DiffBaseBreakdownFileName string `arg:"--diff-base-breakdown-file-name"`
38-
39-
BadgeFileName string `arg:"-b,--badge-file-name"`
40-
41-
CDNKey string `arg:"--cdn-key"`
42-
CDNSecret string `arg:"--cdn-secret"`
43-
CDNRegion string `arg:"--cdn-region"`
44-
CDNEndpoint string `arg:"--cdn-endpoint"`
45-
CDNFileName string `arg:"--cdn-file-name"`
46-
CDNBucketName string `arg:"--cdn-bucket-name"`
47-
CDNForcePathStyle bool `arg:"--cdn-force-path-style"`
48-
49-
GitToken string `arg:"--git-token"`
50-
GitRepository string `arg:"--git-repository"`
51-
GitBranch string `arg:"--git-branch"`
52-
GitFileName string `arg:"--git-file-name"`
53-
}
54-
55-
func newArgs() args {
56-
return args{
57-
ConfigPath: ciDefaultString,
58-
Profile: ciDefaultString,
59-
LocalPrefix: ciDefaultString,
60-
SourceDir: ciDefaultString,
61-
GithubActionOutput: false,
62-
ThresholdFile: ciDefaultInt,
63-
ThresholdPackage: ciDefaultInt,
64-
ThresholdTotal: ciDefaultInt,
65-
66-
BreakdownFileName: ciDefaultString,
67-
DiffBaseBreakdownFileName: ciDefaultString,
68-
69-
// Badge
70-
BadgeFileName: ciDefaultString,
71-
72-
// CDN
73-
CDNKey: ciDefaultString,
74-
CDNSecret: ciDefaultString,
75-
CDNRegion: ciDefaultString,
76-
CDNEndpoint: ciDefaultString,
77-
CDNFileName: ciDefaultString,
78-
CDNBucketName: ciDefaultString,
79-
CDNForcePathStyle: false,
80-
81-
// Git
82-
GitToken: ciDefaultString,
83-
GitRepository: ciDefaultString,
84-
GitBranch: ciDefaultString,
85-
GitFileName: ciDefaultString,
86-
}
87-
}
88-
89-
func (*args) Version() string {
90-
return Name + " " + Version
91-
}
92-
93-
//nolint:cyclop,maintidx,mnd,funlen // relax
94-
func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, error) {
95-
if !isCIDefaultString(a.Profile) {
96-
cfg.Profile = a.Profile
97-
}
98-
99-
if a.GithubActionOutput {
100-
cfg.GithubActionOutput = true
101-
}
102-
103-
if !isCIDefaultString(a.LocalPrefix) {
104-
cfg.LocalPrefixDeprecated = a.LocalPrefix
105-
}
106-
107-
if !isCIDefaultString(a.SourceDir) {
108-
cfg.SourceDir = a.SourceDir
109-
}
110-
111-
if !isCIDefaultInt(a.ThresholdFile) {
112-
cfg.Threshold.File = a.ThresholdFile
113-
}
114-
115-
if !isCIDefaultInt(a.ThresholdPackage) {
116-
cfg.Threshold.Package = a.ThresholdPackage
117-
}
118-
119-
if !isCIDefaultInt(a.ThresholdTotal) {
120-
cfg.Threshold.Total = a.ThresholdTotal
121-
}
122-
123-
if !isCIDefaultString(a.BreakdownFileName) {
124-
cfg.BreakdownFileName = a.BreakdownFileName
125-
}
126-
127-
if !isCIDefaultString(a.DiffBaseBreakdownFileName) {
128-
cfg.Diff.BaseBreakdownFileName = a.DiffBaseBreakdownFileName
129-
}
130-
131-
if !isCIDefaultString(a.BadgeFileName) {
132-
cfg.Badge.FileName = a.BadgeFileName
133-
}
134-
135-
if !isCIDefaultString(a.CDNSecret) {
136-
cfg.Badge.CDN.Secret = a.CDNSecret
137-
cfg.Badge.CDN.Key = escapeCiDefaultString(a.CDNKey)
138-
cfg.Badge.CDN.Region = escapeCiDefaultString(a.CDNRegion)
139-
cfg.Badge.CDN.FileName = escapeCiDefaultString(a.CDNFileName)
140-
cfg.Badge.CDN.BucketName = escapeCiDefaultString(a.CDNBucketName)
141-
cfg.Badge.CDN.ForcePathStyle = a.CDNForcePathStyle
142-
143-
if !isCIDefaultString(a.CDNEndpoint) {
144-
cfg.Badge.CDN.Endpoint = a.CDNEndpoint
145-
}
146-
}
147-
148-
if !isCIDefaultString(a.GitToken) {
149-
cfg.Badge.Git.Token = a.GitToken
150-
cfg.Badge.Git.Branch = escapeCiDefaultString(a.GitBranch)
151-
cfg.Badge.Git.FileName = escapeCiDefaultString(a.GitFileName)
152-
153-
parts := strings.Split(escapeCiDefaultString(a.GitRepository), "/")
154-
if len(parts) != 2 {
155-
return cfg, errors.New("--git-repository flag should have format {owner}/{repository}")
156-
}
157-
158-
cfg.Badge.Git.Owner = parts[0]
159-
cfg.Badge.Git.Repository = parts[1]
160-
}
161-
162-
return cfg, nil
163-
}
164-
165-
//nolint:forbidigo // relax
16+
//nolint:forbidigo,wsl // relax
16617
func main() {
16718
cfg, err := readConfig()
16819
if err != nil {
16920
fmt.Println(err.Error())
17021
os.Exit(1)
17122
}
17223

173-
pass := testcoverage.Check(os.Stdout, cfg)
174-
if !pass {
175-
os.Exit(1)
176-
}
177-
}
178-
179-
func readConfig() (testcoverage.Config, error) {
180-
cmdArgs := newArgs()
181-
arg.MustParse(&cmdArgs)
24+
logger.Init()
18225

183-
cfg := testcoverage.Config{}
184-
185-
// Load config from file
186-
if !isCIDefaultString(cmdArgs.ConfigPath) {
187-
err := testcoverage.ConfigFromFile(&cfg, cmdArgs.ConfigPath)
188-
if err != nil {
189-
return testcoverage.Config{}, fmt.Errorf("failed loading config from file: %w", err)
190-
}
191-
}
192-
193-
// Override config with values from args
194-
cfg, err := cmdArgs.overrideConfig(cfg)
26+
pass, err := testcoverage.Check(os.Stdout, cfg)
19527
if err != nil {
196-
return testcoverage.Config{}, fmt.Errorf("argument is not valid: %w", err)
197-
}
198-
199-
// Validate config
200-
if err := cfg.Validate(); err != nil {
201-
return testcoverage.Config{}, fmt.Errorf("config file is not valid: %w", err)
28+
fmt.Println("Running coverage check failed.")
29+
if cfg.GithubActionOutput {
30+
fmt.Printf("Please set `debug: true` input to see detailed output.")
31+
} else {
32+
fmt.Println("Please use `--debug=true` flag to see detailed output.")
33+
}
20234
}
203-
204-
return cfg, nil
205-
}
206-
207-
func isCIDefaultString(v string) bool { return v == ciDefaultString }
208-
209-
func isCIDefaultInt(v int) bool { return v == ciDefaultInt }
210-
211-
func escapeCiDefaultString(v string) string {
212-
if v == ciDefaultString {
213-
return ""
35+
if !pass || err != nil {
36+
os.Exit(1)
21437
}
215-
216-
return v
21738
}

0 commit comments

Comments
 (0)