mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
d47a17c8fc
* update reporting and add todo comments * enhance reporting, allow directory creation for reports * properly pass reports * update templating and increase verbosity of errors * add todo * add detail table * update sorting * add test and improve error message * fix error message in test * extend tests * enhance tests * enhance versioning behavior accoring to #1846 * create markdown overview report * small fix * fix small issue * make sure that report directory exists * align reporting directory with default directory from UA * add missing comments * add policy check incl. tests * enhance logging and tests * update versioning to allow custom version usage properly * fix report paths and golang image * update styling of md * update test
59 lines
2.4 KiB
Go
59 lines
2.4 KiB
Go
package versioning
|
|
|
|
import (
|
|
"github.com/Masterminds/sprig"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
)
|
|
|
|
const (
|
|
// SchemeMajorVersion is the versioning scheme based on the major version only
|
|
SchemeMajorVersion = `{{(split "." (split "-" .Version)._0)._0}}`
|
|
// SchemeMajorMinorVersion is the versioning scheme based on the major version only
|
|
SchemeMajorMinorVersion = `{{(split "." (split "-" .Version)._0)._0}}.{{(split "." (split "-" .Version)._0)._1}}`
|
|
// SchemeSemanticVersion is the versioning scheme based on the major.minor.micro version
|
|
SchemeSemanticVersion = `{{(split "." (split "-" .Version)._0)._0}}.{{(split "." (split "-" .Version)._0)._1}}.{{(split "." (split "-" .Version)._0)._2}}`
|
|
// SchemeFullVersion is the versioning scheme based on the full version
|
|
SchemeFullVersion = "{{.Version}}"
|
|
)
|
|
|
|
// DetermineProjectCoordinatesWithCustomVersion resolves the coordinates of the project for use in 3rd party scan tools
|
|
// It considers a custom version if provided instead of using the GAV version adapted according to the versionScheme
|
|
func DetermineProjectCoordinatesWithCustomVersion(nameTemplate, versionScheme, customVersion string, gav Coordinates) (string, string) {
|
|
name, version := DetermineProjectCoordinates(nameTemplate, versionScheme, gav)
|
|
if len(customVersion) > 0 {
|
|
log.Entry().Infof("Using custom version: %v", customVersion)
|
|
return name, customVersion
|
|
}
|
|
return name, version
|
|
}
|
|
|
|
// DetermineProjectCoordinates resolves the coordinates of the project for use in 3rd party scan tools
|
|
func DetermineProjectCoordinates(nameTemplate, versionScheme string, gav Coordinates) (string, string) {
|
|
projectName, err := piperutils.ExecuteTemplateFunctions(nameTemplate, sprig.HermeticTxtFuncMap(), gav)
|
|
if err != nil {
|
|
log.Entry().Warnf("Unable to resolve project name: %v", err)
|
|
}
|
|
|
|
var versionTemplate string
|
|
if versionScheme == "full" {
|
|
versionTemplate = SchemeFullVersion
|
|
}
|
|
if versionScheme == "major" {
|
|
versionTemplate = SchemeMajorVersion
|
|
}
|
|
if versionScheme == "major-minor" {
|
|
versionTemplate = SchemeMajorMinorVersion
|
|
}
|
|
if versionScheme == "semantic" {
|
|
versionTemplate = SchemeSemanticVersion
|
|
}
|
|
|
|
projectVersion, err := piperutils.ExecuteTemplateFunctions(versionTemplate, sprig.HermeticTxtFuncMap(), gav)
|
|
if err != nil {
|
|
log.Entry().Warnf("Unable to resolve project version: %v", err)
|
|
}
|
|
return projectName, projectVersion
|
|
}
|