From d5341d06d9c9bd5f98a70672a32032a4497b5bff Mon Sep 17 00:00:00 2001 From: vlado Date: Sun, 13 Jul 2025 11:58:22 +0200 Subject: [PATCH 1/3] remove magic values --- action.yml | 38 ++++----- action/source/action.yml | 38 ++++----- main_config.go | 162 ++++++++++++++------------------------- 3 files changed, 96 insertions(+), 142 deletions(-) diff --git a/action.yml b/action.yml index b986ecc..d4a6667 100644 --- a/action.yml +++ b/action.yml @@ -144,25 +144,25 @@ runs: # TOOL_VERSION: when changing version update version in other places image: docker://ghcr.io/vladopajic/go-test-coverage:v2.16.0 args: - - --config=${{ inputs.config || '***' }} - - --profile=${{ inputs.profile || '***' }} - - --source-dir=${{ inputs.source-dir || '***' }} + - --config "${{ inputs.config }}" + - --profile "${{ inputs.profile }}" + - --source-dir "${{ inputs.source-dir }}" - --debug=${{ inputs.debug }} - --github-action-output=true - - --threshold-file=${{ inputs.threshold-file }} - - --threshold-package=${{ inputs.threshold-package }} - - --threshold-total=${{ inputs.threshold-total }} - - --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} - - --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} - - --badge-file-name=${{ inputs.badge-file-name || '***' }} - - --cdn-key=${{ inputs.cdn-key || '***' }} - - --cdn-secret=${{ inputs.cdn-secret || '***' }} - - --cdn-region=${{ inputs.cdn-region || '***' }} - - --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} - - --cdn-file-name=${{ inputs.cdn-file-name || '***' }} - - --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} + - --threshold-file ${{ inputs.threshold-file }} + - --threshold-package ${{ inputs.threshold-package }} + - --threshold-total ${{ inputs.threshold-total }} + - --breakdown-file-name "${{ inputs.breakdown-file-name }}" + - --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" + - --badge-file-name "${{ inputs.badge-file-name }}" + - --cdn-key "${{ inputs.cdn-key }}" + - --cdn-secret "${{ inputs.cdn-secret }}" + - --cdn-region "${{ inputs.cdn-region }}" + - --cdn-endpoint "${{ inputs.cdn-endpoint }}" + - --cdn-file-name "${{ inputs.cdn-file-name }}" + - --cdn-bucket-name "${{ inputs.cdn-bucket-name }}" - --cdn-force-path-style=${{ inputs.cdn-force-path-style }} - - --git-token=${{ inputs.git-token || '***' }} - - --git-branch=${{ inputs.git-branch || '***' }} - - --git-repository=${{ inputs.git-repository || '***'}} - - --git-file-name=${{ inputs.git-file-name || '***' }} \ No newline at end of file + - --git-token "${{ inputs.git-token }}" + - --git-branch "${{ inputs.git-branch }}" + - --git-repository "${{ inputs.git-repository }}" + - --git-file-name "${{ inputs.git-file-name }}" \ No newline at end of file diff --git a/action/source/action.yml b/action/source/action.yml index e1cdabb..253c238 100644 --- a/action/source/action.yml +++ b/action/source/action.yml @@ -169,25 +169,25 @@ runs: shell: bash run: | go run github.com/vladopajic/go-test-coverage/v2@${{ inputs.version }} \ - --config=${{ inputs.config || '***' }} \ - --profile=${{ inputs.profile || '***' }} \ - --source-dir=${{ inputs.source-dir || '***' }} \ + --config "${{ inputs.config }}" \ + --profile "${{ inputs.profile }}" \ + --source-dir "${{ inputs.source-dir }}" \ --debug=${{ inputs.debug }} \ --github-action-output=true \ - --threshold-file=${{ inputs.threshold-file }} \ - --threshold-package=${{ inputs.threshold-package }} \ - --threshold-total=${{ inputs.threshold-total }} \ - --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} \ - --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} \ - --badge-file-name=${{ inputs.badge-file-name || '***' }} \ - --cdn-key=${{ inputs.cdn-key || '***' }} \ - --cdn-secret=${{ inputs.cdn-secret || '***' }} \ - --cdn-region=${{ inputs.cdn-region || '***' }} \ - --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} \ - --cdn-file-name=${{ inputs.cdn-file-name || '***' }} \ - --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} \ + --threshold-file ${{ inputs.threshold-file }} \ + --threshold-package ${{ inputs.threshold-package }} \ + --threshold-total ${{ inputs.threshold-total }} \ + --breakdown-file-name "${{ inputs.breakdown-file-name }}" \ + --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" \ + --badge-file-name "${{ inputs.badge-file-name }}" \ + --cdn-key "${{ inputs.cdn-key }}" \ + --cdn-secret "${{ inputs.cdn-secret }}" \ + --cdn-region "${{ inputs.cdn-region }}" \ + --cdn-endpoint "${{ inputs.cdn-endpoint }}" \ + --cdn-file-name "${{ inputs.cdn-file-name }}" \ + --cdn-bucket-name "${{ inputs.cdn-bucket-name }}" \ --cdn-force-path-style=${{ inputs.cdn-force-path-style }} \ - --git-token=${{ inputs.git-token || '***' }} \ - --git-branch=${{ inputs.git-branch || '***' }} \ - --git-repository=${{ inputs.git-repository || '***'}} \ - --git-file-name=${{ inputs.git-file-name || '***' }} \ No newline at end of file + --git-token "${{ inputs.git-token }}" \ + --git-branch "${{ inputs.git-branch }}" \ + --git-repository "${{ inputs.git-repository }}" \ + --git-file-name "${{ inputs.git-file-name }}" \ No newline at end of file diff --git a/main_config.go b/main_config.go index fd2061a..5b9d669 100644 --- a/main_config.go +++ b/main_config.go @@ -10,76 +10,34 @@ import ( "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage" ) -const ( - // default value of string variables passed by CI - ciDefaultString = `***` - // default value of int variables passed by CI - ciDefaultInt = -1 -) - type args struct { - ConfigPath string `arg:"-c,--config"` - Profile string `arg:"-p,--profile" help:"path to coverage profile"` - Debug bool `arg:"-d,--debug"` - LocalPrefix string `arg:"-l,--local-prefix"` // deprecated - SourceDir string `arg:"-s,--source-dir"` - GithubActionOutput bool `arg:"-o,--github-action-output"` - ThresholdFile int `arg:"-f,--threshold-file"` - ThresholdPackage int `arg:"-k,--threshold-package"` - ThresholdTotal int `arg:"-t,--threshold-total"` - - BreakdownFileName string `arg:"--breakdown-file-name"` - DiffBaseBreakdownFileName string `arg:"--diff-base-breakdown-file-name"` - - BadgeFileName string `arg:"-b,--badge-file-name"` - - CDNKey string `arg:"--cdn-key"` - CDNSecret string `arg:"--cdn-secret"` - CDNRegion string `arg:"--cdn-region"` - CDNEndpoint string `arg:"--cdn-endpoint"` - CDNFileName string `arg:"--cdn-file-name"` - CDNBucketName string `arg:"--cdn-bucket-name"` - CDNForcePathStyle bool `arg:"--cdn-force-path-style"` - - GitToken string `arg:"--git-token"` - GitRepository string `arg:"--git-repository"` - GitBranch string `arg:"--git-branch"` - GitFileName string `arg:"--git-file-name"` -} - -func newArgs() args { - return args{ - ConfigPath: ciDefaultString, - Profile: ciDefaultString, - Debug: false, - LocalPrefix: ciDefaultString, - SourceDir: ciDefaultString, - GithubActionOutput: false, - ThresholdFile: ciDefaultInt, - ThresholdPackage: ciDefaultInt, - ThresholdTotal: ciDefaultInt, - - BreakdownFileName: ciDefaultString, - DiffBaseBreakdownFileName: ciDefaultString, - - // Badge - BadgeFileName: ciDefaultString, - - // CDN - CDNKey: ciDefaultString, - CDNSecret: ciDefaultString, - CDNRegion: ciDefaultString, - CDNEndpoint: ciDefaultString, - CDNFileName: ciDefaultString, - CDNBucketName: ciDefaultString, - CDNForcePathStyle: false, - - // Git - GitToken: ciDefaultString, - GitRepository: ciDefaultString, - GitBranch: ciDefaultString, - GitFileName: ciDefaultString, - } + ConfigPath *string `arg:"-c,--config"` + Profile *string `arg:"-p,--profile" help:"path to coverage profile"` + Debug bool `arg:"-d,--debug"` + LocalPrefix *string `arg:"-l,--local-prefix"` // deprecated + SourceDir *string `arg:"-s,--source-dir"` + GithubActionOutput bool `arg:"-o,--github-action-output"` + ThresholdFile *int `arg:"-f,--threshold-file"` + ThresholdPackage *int `arg:"-k,--threshold-package"` + ThresholdTotal *int `arg:"-t,--threshold-total"` + + BreakdownFileName *string `arg:"--breakdown-file-name"` + DiffBaseBreakdownFileName *string `arg:"--diff-base-breakdown-file-name"` + + BadgeFileName *string `arg:"-b,--badge-file-name"` + + CDNKey *string `arg:"--cdn-key"` + CDNSecret *string `arg:"--cdn-secret"` + CDNRegion *string `arg:"--cdn-region"` + CDNEndpoint *string `arg:"--cdn-endpoint"` + CDNFileName *string `arg:"--cdn-file-name"` + CDNBucketName *string `arg:"--cdn-bucket-name"` + CDNForcePathStyle bool `arg:"--cdn-force-path-style"` + + GitToken *string `arg:"--git-token"` + GitRepository *string `arg:"--git-repository"` + GitBranch *string `arg:"--git-branch"` + GitFileName *string `arg:"--git-file-name"` } func (*args) Version() string { @@ -88,8 +46,8 @@ func (*args) Version() string { //nolint:cyclop,maintidx,mnd,funlen // relax func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, error) { - if !isCIDefaultString(a.Profile) { - cfg.Profile = a.Profile + if a.Profile != nil { + cfg.Profile = *a.Profile } if a.Debug { @@ -100,53 +58,53 @@ func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, err cfg.GithubActionOutput = true } - if !isCIDefaultString(a.LocalPrefix) { - cfg.LocalPrefixDeprecated = a.LocalPrefix + if a.LocalPrefix != nil { + cfg.LocalPrefixDeprecated = *a.LocalPrefix } - if !isCIDefaultString(a.SourceDir) { - cfg.SourceDir = a.SourceDir + if a.SourceDir != nil { + cfg.SourceDir = *a.SourceDir } - if !isCIDefaultInt(a.ThresholdFile) { - cfg.Threshold.File = a.ThresholdFile + if a.ThresholdFile != nil { + cfg.Threshold.File = *a.ThresholdFile } - if !isCIDefaultInt(a.ThresholdPackage) { - cfg.Threshold.Package = a.ThresholdPackage + if a.ThresholdPackage != nil { + cfg.Threshold.Package = *a.ThresholdPackage } - if !isCIDefaultInt(a.ThresholdTotal) { - cfg.Threshold.Total = a.ThresholdTotal + if a.ThresholdTotal != nil { + cfg.Threshold.Total = *a.ThresholdTotal } - if !isCIDefaultString(a.BreakdownFileName) { - cfg.BreakdownFileName = a.BreakdownFileName + if a.BreakdownFileName != nil { + cfg.BreakdownFileName = *a.BreakdownFileName } - if !isCIDefaultString(a.DiffBaseBreakdownFileName) { - cfg.Diff.BaseBreakdownFileName = a.DiffBaseBreakdownFileName + if a.DiffBaseBreakdownFileName != nil { + cfg.Diff.BaseBreakdownFileName = *a.DiffBaseBreakdownFileName } - if !isCIDefaultString(a.BadgeFileName) { - cfg.Badge.FileName = a.BadgeFileName + if a.BadgeFileName != nil { + cfg.Badge.FileName = *a.BadgeFileName } - if !isCIDefaultString(a.CDNSecret) { - cfg.Badge.CDN.Secret = a.CDNSecret + if a.CDNSecret != nil { + cfg.Badge.CDN.Secret = *a.CDNSecret cfg.Badge.CDN.Key = escapeCiDefaultString(a.CDNKey) cfg.Badge.CDN.Region = escapeCiDefaultString(a.CDNRegion) cfg.Badge.CDN.FileName = escapeCiDefaultString(a.CDNFileName) cfg.Badge.CDN.BucketName = escapeCiDefaultString(a.CDNBucketName) cfg.Badge.CDN.ForcePathStyle = a.CDNForcePathStyle - if !isCIDefaultString(a.CDNEndpoint) { - cfg.Badge.CDN.Endpoint = a.CDNEndpoint + if a.CDNEndpoint != nil { + cfg.Badge.CDN.Endpoint = *a.CDNEndpoint } } - if !isCIDefaultString(a.GitToken) { - cfg.Badge.Git.Token = a.GitToken + if a.GitToken != nil { + cfg.Badge.Git.Token = *a.GitToken cfg.Badge.Git.Branch = escapeCiDefaultString(a.GitBranch) cfg.Badge.Git.FileName = escapeCiDefaultString(a.GitFileName) @@ -163,14 +121,14 @@ func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, err } func readConfig() (testcoverage.Config, error) { - cmdArgs := newArgs() - arg.MustParse(&cmdArgs) + cmdArgs := &args{} + arg.MustParse(cmdArgs) cfg := testcoverage.Config{} // Load config from file - if !isCIDefaultString(cmdArgs.ConfigPath) { - err := testcoverage.ConfigFromFile(&cfg, cmdArgs.ConfigPath) + if cmdArgs.ConfigPath != nil { + err := testcoverage.ConfigFromFile(&cfg, *cmdArgs.ConfigPath) if err != nil { return testcoverage.Config{}, fmt.Errorf("failed loading config from file: %w", err) } @@ -190,14 +148,10 @@ func readConfig() (testcoverage.Config, error) { return cfg, nil } -func isCIDefaultString(v string) bool { return v == ciDefaultString } - -func isCIDefaultInt(v int) bool { return v == ciDefaultInt } - -func escapeCiDefaultString(v string) string { - if v == ciDefaultString { +func escapeCiDefaultString(str *string) string { + if str == nil { return "" } - return v + return *str } From 3d825deda1dfc5d80567b37a45fff8649eb680d4 Mon Sep 17 00:00:00 2001 From: vlado Date: Sun, 13 Jul 2025 12:06:51 +0200 Subject: [PATCH 2/3] update --- action.yml | 9 +++------ action/source/action.yml | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index d4a6667..43250b0 100644 --- a/action.yml +++ b/action.yml @@ -38,17 +38,14 @@ inputs: threshold-file: description: Minimum coverage percentage required for individual files. Overrides value from configuration. required: false - default: -1 type: number threshold-package: description: Minimum coverage percentage required for each package. Overrides value from configuration. required: false - default: -1 type: number threshold-total: description: Minimum overall project coverage percentage required. Overrides value from configuration. required: false - default: -1 type: number breakdown-file-name: @@ -149,9 +146,9 @@ runs: - --source-dir "${{ inputs.source-dir }}" - --debug=${{ inputs.debug }} - --github-action-output=true - - --threshold-file ${{ inputs.threshold-file }} - - --threshold-package ${{ inputs.threshold-package }} - - --threshold-total ${{ inputs.threshold-total }} + - --threshold-file "${{ inputs.threshold-file }}" + - --threshold-package "${{ inputs.threshold-package }}" + - --threshold-total "${{ inputs.threshold-total }}" - --breakdown-file-name "${{ inputs.breakdown-file-name }}" - --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" - --badge-file-name "${{ inputs.badge-file-name }}" diff --git a/action/source/action.yml b/action/source/action.yml index 253c238..2d00ce4 100644 --- a/action/source/action.yml +++ b/action/source/action.yml @@ -38,17 +38,14 @@ inputs: threshold-file: description: Minimum coverage percentage required for individual files. Overrides value from configuration. required: false - default: -1 type: number threshold-package: description: Minimum coverage percentage required for each package. Overrides value from configuration. required: false - default: -1 type: number threshold-total: description: Minimum overall project coverage percentage required. Overrides value from configuration. required: false - default: -1 type: number breakdown-file-name: @@ -174,9 +171,9 @@ runs: --source-dir "${{ inputs.source-dir }}" \ --debug=${{ inputs.debug }} \ --github-action-output=true \ - --threshold-file ${{ inputs.threshold-file }} \ - --threshold-package ${{ inputs.threshold-package }} \ - --threshold-total ${{ inputs.threshold-total }} \ + --threshold-file "${{ inputs.threshold-file }}" \ + --threshold-package "${{ inputs.threshold-package }}" \ + --threshold-total "${{ inputs.threshold-total }}" \ --breakdown-file-name "${{ inputs.breakdown-file-name }}" \ --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" \ --badge-file-name "${{ inputs.badge-file-name }}" \ From 524539efd2f3fe9cbd3f4fc82b09bccda724c8b4 Mon Sep 17 00:00:00 2001 From: vlado Date: Sun, 13 Jul 2025 12:10:52 +0200 Subject: [PATCH 3/3] update --- action.yml | 6 +++--- action/source/action.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 43250b0..7130e70 100644 --- a/action.yml +++ b/action.yml @@ -146,9 +146,9 @@ runs: - --source-dir "${{ inputs.source-dir }}" - --debug=${{ inputs.debug }} - --github-action-output=true - - --threshold-file "${{ inputs.threshold-file }}" - - --threshold-package "${{ inputs.threshold-package }}" - - --threshold-total "${{ inputs.threshold-total }}" + - --threshold-file ${{ inputs.threshold-file }} + - --threshold-package ${{ inputs.threshold-package }} + - --threshold-total ${{ inputs.threshold-total }} - --breakdown-file-name "${{ inputs.breakdown-file-name }}" - --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" - --badge-file-name "${{ inputs.badge-file-name }}" diff --git a/action/source/action.yml b/action/source/action.yml index 2d00ce4..ee2967c 100644 --- a/action/source/action.yml +++ b/action/source/action.yml @@ -171,9 +171,9 @@ runs: --source-dir "${{ inputs.source-dir }}" \ --debug=${{ inputs.debug }} \ --github-action-output=true \ - --threshold-file "${{ inputs.threshold-file }}" \ - --threshold-package "${{ inputs.threshold-package }}" \ - --threshold-total "${{ inputs.threshold-total }}" \ + --threshold-file ${{ inputs.threshold-file }} \ + --threshold-package ${{ inputs.threshold-package }} \ + --threshold-total ${{ inputs.threshold-total }} \ --breakdown-file-name "${{ inputs.breakdown-file-name }}" \ --diff-base-breakdown-file-name "${{ inputs.diff-base-breakdown-file-name }}" \ --badge-file-name "${{ inputs.badge-file-name }}" \