mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-16 05:16:08 +02:00
refactor(versioning): simplify versioning model method (#2825)
* rename artifactVersion to version * simplify versioningModel
This commit is contained in:
parent
56ef1201b9
commit
3a14a91ae5
@ -127,16 +127,11 @@ func getDetectScript(config detectExecuteScanOptions, utils detectUtils) error {
|
||||
}
|
||||
|
||||
func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectUtils) ([]string, error) {
|
||||
|
||||
coordinates := versioning.Coordinates{
|
||||
Version: config.Version,
|
||||
}
|
||||
|
||||
detectVersionName := config.CustomScanVersion
|
||||
if len(detectVersionName) > 0 {
|
||||
log.Entry().Infof("Using custom version: %v", detectVersionName)
|
||||
} else {
|
||||
detectVersionName = versioning.ApplyVersioningModel(config.VersioningModel, coordinates)
|
||||
detectVersionName = versioning.ApplyVersioningModel(config.VersioningModel, config.Version)
|
||||
}
|
||||
//Split on spaces, the scanPropeties, so that each property is available as a single string
|
||||
//instead of all properties being part of a single string
|
||||
|
@ -128,7 +128,7 @@ func runSonar(config sonarExecuteScanOptions, client piperhttp.Downloader, runne
|
||||
if len(version) > 0 {
|
||||
log.Entry().Infof("Using custom version: %v", version)
|
||||
} else {
|
||||
version = versioning.ApplyVersioningModel(config.VersioningModel, versioning.Coordinates{Version: config.Version})
|
||||
version = versioning.ApplyVersioningModel(config.VersioningModel, config.Version)
|
||||
}
|
||||
sonar.addOption("sonar.projectVersion=" + version)
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ func DetermineProjectCoordinates(nameTemplate, versionScheme string, gav Coordin
|
||||
log.Entry().Warnf("Unable to resolve project name: %v", err)
|
||||
}
|
||||
|
||||
projectVersion := ApplyVersioningModel(versionScheme, gav)
|
||||
projectVersion := ApplyVersioningModel(versionScheme, gav.Version)
|
||||
return projectName, projectVersion
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ const (
|
||||
VersioningModelMajor string = "major"
|
||||
)
|
||||
|
||||
func ApplyVersioningModel(model string, projectCoordinates Coordinates) string {
|
||||
func ApplyVersioningModel(model, projectVersion string) string {
|
||||
var versioningScheme string
|
||||
|
||||
switch model {
|
||||
@ -40,7 +40,7 @@ func ApplyVersioningModel(model string, projectCoordinates Coordinates) string {
|
||||
log.Entry().Warnf("versioning model not supported: %s", model)
|
||||
}
|
||||
|
||||
version, err := piperutils.ExecuteTemplateFunctions(versioningScheme, sprig.HermeticTxtFuncMap(), projectCoordinates)
|
||||
version, err := piperutils.ExecuteTemplateFunctions(versioningScheme, sprig.HermeticTxtFuncMap(), Coordinates{Version: projectVersion})
|
||||
if err != nil {
|
||||
log.Entry().Warnf("unable to resolve project version: %v", err)
|
||||
}
|
||||
|
@ -7,23 +7,23 @@ import (
|
||||
func Test_applyVersioningModel(t *testing.T) {
|
||||
type args struct {
|
||||
model string
|
||||
version Coordinates
|
||||
version string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{"maven - major", args{VersioningModelMajor, Coordinates{Version: "1.2.3-7864387648746"}}, "1"},
|
||||
{"maven - major-minor", args{VersioningModelMajorMinor, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2"},
|
||||
{"maven - semantic", args{VersioningModelSemantic, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2.3"},
|
||||
{"maven - full", args{VersioningModelFull, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2.3-7864387648746"},
|
||||
{"python - major-minor", args{VersioningModelMajorMinor, Coordinates{Version: "2.2.3.20200101"}}, "2.2"},
|
||||
{"leading zero", args{VersioningModelMajor, Coordinates{Version: "0.0.1"}}, "0"},
|
||||
{"trailing zero", args{VersioningModelMajorMinor, Coordinates{Version: "2.0"}}, "2.0"},
|
||||
{"invalid - unknown versioning model", args{"snapshot", Coordinates{Version: "1.2.3-SNAPSHOT"}}, ""},
|
||||
{"invalid - incorrect version", args{VersioningModelMajor, Coordinates{Version: ".2.3"}}, ""},
|
||||
{"invalid - version to short", args{VersioningModelSemantic, Coordinates{Version: "1.2"}}, "1.2.<no value>"},
|
||||
{"maven - major", args{VersioningModelMajor, "1.2.3-7864387648746"}, "1"},
|
||||
{"maven - major-minor", args{VersioningModelMajorMinor, "1.2.3-7864387648746"}, "1.2"},
|
||||
{"maven - semantic", args{VersioningModelSemantic, "1.2.3-7864387648746"}, "1.2.3"},
|
||||
{"maven - full", args{VersioningModelFull, "1.2.3-7864387648746"}, "1.2.3-7864387648746"},
|
||||
{"python - major-minor", args{VersioningModelMajorMinor, "2.2.3.20200101"}, "2.2"},
|
||||
{"leading zero", args{VersioningModelMajor, "0.0.1"}, "0"},
|
||||
{"trailing zero", args{VersioningModelMajorMinor, "2.0"}, "2.0"},
|
||||
{"invalid - unknown versioning model", args{"snapshot", "1.2.3-SNAPSHOT"}, ""},
|
||||
{"invalid - incorrect version", args{VersioningModelMajor, ".2.3"}, ""},
|
||||
{"invalid - version to short", args{VersioningModelSemantic, "1.2"}, "1.2.<no value>"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user