Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -144,25 +141,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 || '***' }}
- --git-token "${{ inputs.git-token }}"
- --git-branch "${{ inputs.git-branch }}"
- --git-repository "${{ inputs.git-repository }}"
- --git-file-name "${{ inputs.git-file-name }}"
41 changes: 19 additions & 22 deletions action/source/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -169,25 +166,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 || '***' }}
--git-token "${{ inputs.git-token }}" \
--git-branch "${{ inputs.git-branch }}" \
--git-repository "${{ inputs.git-repository }}" \
--git-file-name "${{ inputs.git-file-name }}"
162 changes: 58 additions & 104 deletions main_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)

Expand All @@ -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)
}
Expand All @@ -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
}
Loading