diff --git a/.editorconfig b/.editorconfig index 0aa9c24746..fb326c32c8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -24,4 +24,3 @@ indent_style = none indent_size = none [{go.mod,go.sum,*.go,*.golden}] indent_style = tab -indent_size = 8 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 10febb1bb3..132997c45b 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Install Groovy run: sudo apt-get update && sudo apt-get install groovy -y diff --git a/.github/workflows/update-go-dependencies.yml b/.github/workflows/update-go-dependencies.yml index fe7f350d3a..0157cbb697 100644 --- a/.github/workflows/update-go-dependencies.yml +++ b/.github/workflows/update-go-dependencies.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Perform update run: | git checkout -B gh-action-update-golang-dependencies diff --git a/.github/workflows/upload-go-master.yml b/.github/workflows/upload-go-master.yml index 9f88021517..b56c1f8771 100644 --- a/.github/workflows/upload-go-master.yml +++ b/.github/workflows/upload-go-master.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - env: CGO_ENABLED: 0 run: | diff --git a/.github/workflows/verify-go.yml b/.github/workflows/verify-go.yml index 8226c83165..715e87f990 100644 --- a/.github/workflows/verify-go.yml +++ b/.github/workflows/verify-go.yml @@ -15,7 +15,7 @@ jobs: - uses: styfle/cancel-workflow-action@0.11.0 - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Cache Golang Packages uses: actions/cache@v3 with: @@ -43,7 +43,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Cache Golang Packages uses: actions/cache@v3 with: @@ -63,7 +63,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: checkout uses: actions/checkout@v4 with: @@ -78,7 +78,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Cache Golang Packages uses: actions/cache@v3 with: @@ -98,7 +98,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.23.4' - name: Cache Golang Packages uses: actions/cache@v3 with: diff --git a/Dockerfile b/Dockerfile index 7a44ad5c56..1b6639dcb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.4 AS build-env +FROM golang:1.23.4 AS build-env COPY . /build WORKDIR /build diff --git a/cmd/cloudFoundryDeploy.go b/cmd/cloudFoundryDeploy.go index 79a4e19aa2..6e9ac13662 100644 --- a/cmd/cloudFoundryDeploy.go +++ b/cmd/cloudFoundryDeploy.go @@ -6,6 +6,7 @@ import ( "io" "os" "regexp" + "slices" "sort" "strings" "time" @@ -414,7 +415,7 @@ func deployMta(config *cloudFoundryDeployOptions, mtarFilePath string, command c deployCommand = "bg-deploy" const noConfirmFlag = "--no-confirm" - if !piperutils.ContainsString(deployParams, noConfirmFlag) { + if !slices.Contains(deployParams, noConfirmFlag) { deployParams = append(deployParams, noConfirmFlag) } } diff --git a/cmd/cloudFoundryDeploy_generated.go b/cmd/cloudFoundryDeploy_generated.go index 51c4c51d7c..3c5b774990 100644 --- a/cmd/cloudFoundryDeploy_generated.go +++ b/cmd/cloudFoundryDeploy_generated.go @@ -565,7 +565,7 @@ func cloudFoundryDeployMetadata() config.StepData { }, }, Containers: []config.Container{ - {Name: "cfDeploy", Image: "ppiper/cf-cli:latest"}, + {Name: "cfDeploy", Image: "ppiper/cf-cli:latest", Options: []config.Option{{Name: "--ulimit", Value: "stack=67108864:67108864"}, {Name: "--ulimit", Value: "nofile=65536:65536"}}}, }, Outputs: config.StepOutputs{ Resources: []config.StepResources{ diff --git a/cmd/cnbBuild.go b/cmd/cnbBuild.go index 1bc012df79..3fea419bf9 100644 --- a/cmd/cnbBuild.go +++ b/cmd/cnbBuild.go @@ -6,6 +6,7 @@ import ( "os" "path" "path/filepath" + "slices" "github.com/SAP/jenkins-library/pkg/buildpacks" "github.com/SAP/jenkins-library/pkg/buildsettings" @@ -594,7 +595,7 @@ func runCnbBuild(config *cnbBuildOptions, telemetry *buildpacks.Telemetry, image } for _, tag := range config.AdditionalTags { target := fmt.Sprintf("%s:%s", containerImage, tag) - if !piperutils.ContainsString(creatorArgs, target) { + if !slices.Contains(creatorArgs, target) { creatorArgs = append(creatorArgs, "-tag", target) } } diff --git a/cmd/detectExecuteScan.go b/cmd/detectExecuteScan.go index 5fc5561a10..9dd948f7a8 100644 --- a/cmd/detectExecuteScan.go +++ b/cmd/detectExecuteScan.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "path/filepath" + "slices" "sort" "strconv" "strings" @@ -467,7 +468,7 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU handleExcludedDirectories(&args, &config) if config.Unmap { - if !piperutils.ContainsString(config.ScanProperties, "--detect.project.codelocation.unmap=true") { + if !slices.Contains(config.ScanProperties, "--detect.project.codelocation.unmap=true") { args = append(args, "--detect.project.codelocation.unmap=true") } config.ScanProperties, _ = piperutils.RemoveAll(config.ScanProperties, "--detect.project.codelocation.unmap=false") diff --git a/cmd/fortifyExecuteScan.go b/cmd/fortifyExecuteScan.go index f2110fa552..ac8898a728 100644 --- a/cmd/fortifyExecuteScan.go +++ b/cmd/fortifyExecuteScan.go @@ -11,6 +11,7 @@ import ( "path/filepath" "regexp" "runtime" + "slices" "strconv" "strings" "time" @@ -211,7 +212,7 @@ func runFortifyScan(ctx context.Context, config fortifyExecuteScanOptions, sys f prID, prAuthor := determinePullRequestMerge(config) if prID != "0" { log.Entry().Debugf("Determined PR ID '%v' for merge check", prID) - if len(prAuthor) > 0 && !piperutils.ContainsString(config.Assignees, prAuthor) { + if len(prAuthor) > 0 && !slices.Contains(config.Assignees, prAuthor) { log.Entry().Debugf("Determined PR Author '%v' for result assignment", prAuthor) config.Assignees = append(config.Assignees, prAuthor) } else { diff --git a/cmd/fortifyExecuteScan_test.go b/cmd/fortifyExecuteScan_test.go index 3f47ec3a9d..b5933e46c7 100644 --- a/cmd/fortifyExecuteScan_test.go +++ b/cmd/fortifyExecuteScan_test.go @@ -13,6 +13,7 @@ import ( "os" "path/filepath" "reflect" + "slices" "strings" "testing" "time" @@ -21,7 +22,6 @@ import ( "github.com/SAP/jenkins-library/pkg/fortify" "github.com/SAP/jenkins-library/pkg/log" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/SAP/jenkins-library/pkg/versioning" "github.com/google/go-github/v45/github" @@ -421,7 +421,7 @@ func (er *execRunnerMock) Stderr(err io.Writer) { func (er *execRunnerMock) RunExecutable(e string, p ...string) error { er.numExecutions++ er.currentExecution().executable = e - if len(p) > 0 && piperutils.ContainsString(p, "--failTranslate") { + if len(p) > 0 && slices.Contains(p, "--failTranslate") { return errors.New("Translate failed") } er.currentExecution().parameters = p diff --git a/cmd/kanikoExecute.go b/cmd/kanikoExecute.go index 1937dd66af..3eaf4c9180 100644 --- a/cmd/kanikoExecute.go +++ b/cmd/kanikoExecute.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "slices" "strings" "github.com/mitchellh/mapstructure" @@ -287,7 +288,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus } return nil - case piperutils.ContainsString(config.BuildOptions, "--destination"): + case slices.Contains(config.BuildOptions, "--destination"): log.Entry().Infof("Running Kaniko build with destination defined via buildOptions: %v", config.BuildOptions) for i, o := range config.BuildOptions { diff --git a/cmd/newmanExecute_test.go b/cmd/newmanExecute_test.go index f209005dbf..ffb7429883 100644 --- a/cmd/newmanExecute_test.go +++ b/cmd/newmanExecute_test.go @@ -6,10 +6,10 @@ package cmd import ( "os" "path/filepath" + "slices" "strings" "testing" - sliceUtils "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/google/uuid" "github.com/pkg/errors" "github.com/stretchr/testify/assert" @@ -317,7 +317,7 @@ func (e *newmanExecuteMockUtils) RunExecutable(executable string, params ...stri if e.errorOnNewmanExecution && strings.Contains(executable, "newman") { return errors.New("error on newman execution") } - if e.errorOnNewmanInstall && sliceUtils.ContainsString(params, "install") { + if e.errorOnNewmanInstall && slices.Contains(params, "install") { return errors.New("error on newman install") } diff --git a/cmd/terraformExecute.go b/cmd/terraformExecute.go index e85344b729..bd2b8fa4fe 100644 --- a/cmd/terraformExecute.go +++ b/cmd/terraformExecute.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "fmt" + "slices" "github.com/SAP/jenkins-library/pkg/command" "github.com/SAP/jenkins-library/pkg/log" @@ -53,15 +54,15 @@ func runTerraformExecute(config *terraformExecuteOptions, telemetryData *telemet args := []string{} - if piperutils.ContainsString([]string{"apply", "destroy"}, config.Command) { + if slices.Contains([]string{"apply", "destroy"}, config.Command) { args = append(args, "-auto-approve") } - if piperutils.ContainsString([]string{"apply", "plan"}, config.Command) && config.TerraformSecrets != "" { + if slices.Contains([]string{"apply", "plan"}, config.Command) && config.TerraformSecrets != "" { args = append(args, fmt.Sprintf("-var-file=%s", config.TerraformSecrets)) } - if piperutils.ContainsString([]string{"init", "validate", "plan", "apply", "destroy"}, config.Command) { + if slices.Contains([]string{"init", "validate", "plan", "apply", "destroy"}, config.Command) { args = append(args, "-no-color") } diff --git a/cmd/whitesourceExecuteScan.go b/cmd/whitesourceExecuteScan.go index 14772ec8f6..16c9f09d2a 100644 --- a/cmd/whitesourceExecuteScan.go +++ b/cmd/whitesourceExecuteScan.go @@ -76,6 +76,9 @@ func (w *whitesourceUtilsBundle) FileOpen(name string, flag int, perm os.FileMod } func (w *whitesourceUtilsBundle) GetArtifactCoordinates(buildTool, buildDescriptorFile string, options *versioning.Options) (versioning.Coordinates, error) { + if err := validationBuildDescriptorFile(buildTool, buildDescriptorFile); err != nil { + return versioning.Coordinates{}, err + } artifact, err := versioning.GetArtifact(buildTool, buildDescriptorFile, options, w) if err != nil { return versioning.Coordinates{}, err @@ -83,6 +86,52 @@ func (w *whitesourceUtilsBundle) GetArtifactCoordinates(buildTool, buildDescript return artifact.GetCoordinates() } +func validationBuildDescriptorFile(buildTool, buildDescriptorFile string) error { + if buildDescriptorFile == "" { + return nil + } + switch buildTool { + case "dub": + if filepath.Ext(buildDescriptorFile) != ".json" { + return errors.New("extension of buildDescriptorFile must be in '*.json'") + } + case "gradle": + if filepath.Ext(buildDescriptorFile) != ".properties" { + return errors.New("extension of buildDescriptorFile must be in '*.properties'") + } + case "golang": + if !strings.HasSuffix(buildDescriptorFile, "go.mod") && + !strings.HasSuffix(buildDescriptorFile, "VERSION") && + !strings.HasSuffix(buildDescriptorFile, "version.txt") { + return errors.New("buildDescriptorFile must be one of [\"go.mod\",\"VERSION\", \"version.txt\"]") + } + case "maven": + if filepath.Ext(buildDescriptorFile) != ".xml" { + return errors.New("extension of buildDescriptorFile must be in '*.xml'") + } + case "mta": + if filepath.Ext(buildDescriptorFile) != ".yaml" { + return errors.New("extension of buildDescriptorFile must be in '*.yaml'") + } + case "npm", "yarn": + if filepath.Ext(buildDescriptorFile) != ".json" { + return errors.New("extension of buildDescriptorFile must be in '*.json'") + } + case "pip": + if !strings.HasSuffix(buildDescriptorFile, "setup.py") && + !strings.HasSuffix(buildDescriptorFile, "version.txt") && + !strings.HasSuffix(buildDescriptorFile, "VERSION") { + return errors.New("buildDescriptorFile must be one of [\"setup.py\",\"version.txt\", \"VERSION\"]") + } + case "sbt": + if !strings.HasSuffix(buildDescriptorFile, "sbtDescriptor.json") && + !strings.HasSuffix(buildDescriptorFile, "build.sbt") { + return errors.New("extension of buildDescriptorFile must be in '*.json' or '*sbt'") + } + } + return nil +} + func (w *whitesourceUtilsBundle) getNpmExecutor(config *ws.ScanOptions) npm.Executor { if w.npmExecutor == nil { w.npmExecutor = npm.NewExecutor(npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}) diff --git a/cmd/whitesourceExecuteScan_test.go b/cmd/whitesourceExecuteScan_test.go index b9c7e22b59..d1383c17ae 100644 --- a/cmd/whitesourceExecuteScan_test.go +++ b/cmd/whitesourceExecuteScan_test.go @@ -871,3 +871,71 @@ func TestPersistScannedProjects(t *testing.T) { assert.Equal(t, []string{"project - 1"}, cpe.custom.whitesourceProjectNames) }) } + +func TestBuildToolFiles(t *testing.T) { + t.Parallel() + t.Run("buildTool = dub", func(t *testing.T) { + err := validationBuildDescriptorFile("dub", "/home/mta.yaml") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.json'") + err = validationBuildDescriptorFile("dub", "/home/dub.json") + assert.NoError(t, err) + }) + t.Run("buildTool = gradle", func(t *testing.T) { + err := validationBuildDescriptorFile("gradle", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.properties'") + err = validationBuildDescriptorFile("gradle", "/home/gradle.properties") + assert.NoError(t, err) + }) + t.Run("buildTool = golang", func(t *testing.T) { + err := validationBuildDescriptorFile("golang", "/home/go.json") + assert.ErrorContains(t, err, "buildDescriptorFile must be one of [\"go.mod\",\"VERSION\", \"version.txt\"]") + err = validationBuildDescriptorFile("golang", "/home/go.mod") + assert.NoError(t, err) + err = validationBuildDescriptorFile("golang", "/home/VERSION") + assert.NoError(t, err) + err = validationBuildDescriptorFile("golang", "/home/version.txt") + assert.NoError(t, err) + }) + t.Run("buildTool = maven", func(t *testing.T) { + err := validationBuildDescriptorFile("maven", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.xml'") + err = validationBuildDescriptorFile("maven", "/home/pom.xml") + assert.NoError(t, err) + }) + t.Run("buildTool = mta", func(t *testing.T) { + err := validationBuildDescriptorFile("mta", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.yaml'") + err = validationBuildDescriptorFile("mta", "/home/mta.yaml") + assert.NoError(t, err) + }) + t.Run("buildTool = npm", func(t *testing.T) { + err := validationBuildDescriptorFile("npm", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.json'") + err = validationBuildDescriptorFile("npm", "/home/package.json") + assert.NoError(t, err) + }) + t.Run("buildTool = yarn", func(t *testing.T) { + err := validationBuildDescriptorFile("yarn", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.json'") + err = validationBuildDescriptorFile("yarn", "/home/package.json") + assert.NoError(t, err) + }) + t.Run("buildTool = pip", func(t *testing.T) { + err := validationBuildDescriptorFile("pip", "/home/go.mod") + assert.ErrorContains(t, err, "buildDescriptorFile must be one of [\"setup.py\",\"version.txt\", \"VERSION\"]") + err = validationBuildDescriptorFile("pip", "/home/setup.py") + assert.NoError(t, err) + err = validationBuildDescriptorFile("pip", "/home/version.txt") + assert.NoError(t, err) + err = validationBuildDescriptorFile("pip", "/home/VERSION") + assert.NoError(t, err) + }) + t.Run("buildTool = sbt", func(t *testing.T) { + err := validationBuildDescriptorFile("sbt", "/home/go.mod") + assert.ErrorContains(t, err, "extension of buildDescriptorFile must be in '*.json'") + err = validationBuildDescriptorFile("sbt", "/home/sbtDescriptor.json") + assert.NoError(t, err) + err = validationBuildDescriptorFile("sbt", "/home/build.sbt") + assert.NoError(t, err) + }) +} diff --git a/go.mod b/go.mod index 426478796e..847e98c055 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/SAP/jenkins-library -go 1.22.4 +go 1.23.4 require ( cloud.google.com/go/pubsub v1.36.1 diff --git a/integration/testdata/TestGolangIntegration/golang-project1/go.mod b/integration/testdata/TestGolangIntegration/golang-project1/go.mod index abe4430d88..c538e6fc76 100644 --- a/integration/testdata/TestGolangIntegration/golang-project1/go.mod +++ b/integration/testdata/TestGolangIntegration/golang-project1/go.mod @@ -1,5 +1,5 @@ module github.com/example/golang-app -go 1.22.4 +go 1.23.4 require github.com/gorilla/mux v1.8.0 diff --git a/integration/testdata/TestGolangIntegration/golang-project2/go.mod b/integration/testdata/TestGolangIntegration/golang-project2/go.mod index e0e21c40a1..d07e0384a1 100644 --- a/integration/testdata/TestGolangIntegration/golang-project2/go.mod +++ b/integration/testdata/TestGolangIntegration/golang-project2/go.mod @@ -1,3 +1,3 @@ module github.com/example/golang-app -go 1.22.4 +go 1.23.4 diff --git a/pkg/blackduck/reporting.go b/pkg/blackduck/reporting.go index 960c0c3357..a1faa41f90 100644 --- a/pkg/blackduck/reporting.go +++ b/pkg/blackduck/reporting.go @@ -6,6 +6,7 @@ import ( "fmt" "path/filepath" "runtime" + "slices" "strings" "github.com/SAP/jenkins-library/pkg/format" @@ -89,12 +90,12 @@ func CreateSarifResultFile(vulns *Vulnerabilities, projectName, projectVersion, results = append(results, result) // append taxonomies - if len(v.VulnerabilityWithRemediation.CweID) > 0 && !piperutils.ContainsString(cweIdsForTaxonomies, v.VulnerabilityWithRemediation.CweID) { + if len(v.VulnerabilityWithRemediation.CweID) > 0 && !slices.Contains(cweIdsForTaxonomies, v.VulnerabilityWithRemediation.CweID) { cweIdsForTaxonomies = append(cweIdsForTaxonomies, v.VulnerabilityWithRemediation.CweID) } // only create rule on new CVE - if !piperutils.ContainsString(collectedRules, result.RuleID) { + if !slices.Contains(collectedRules, result.RuleID) { collectedRules = append(collectedRules, result.RuleID) // set information about BlackDuck project diff --git a/pkg/blackduck/reporting_test.go b/pkg/blackduck/reporting_test.go index e0c86bc35e..6e29d3c952 100644 --- a/pkg/blackduck/reporting_test.go +++ b/pkg/blackduck/reporting_test.go @@ -6,6 +6,7 @@ package blackduck import ( "fmt" "path/filepath" + "slices" "testing" "github.com/SAP/jenkins-library/pkg/format" @@ -132,13 +133,13 @@ func TestCreateSarifResultFile(t *testing.T) { collectedRules := []string{} for _, rule := range sarif.Runs[0].Tool.Driver.Rules { - piperutils.ContainsString(vulnerabilities, rule.ID) + slices.Contains(vulnerabilities, rule.ID) collectedRules = append(collectedRules, rule.ID) } collectedResults := []string{} for _, result := range sarif.Runs[0].Results { - piperutils.ContainsString(vulnerabilities, result.RuleID) + slices.Contains(vulnerabilities, result.RuleID) collectedResults = append(collectedResults, result.RuleID) } diff --git a/pkg/checkmarx/checkmarx.go b/pkg/checkmarx/checkmarx.go index e8c4c552df..bccc87a463 100644 --- a/pkg/checkmarx/checkmarx.go +++ b/pkg/checkmarx/checkmarx.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "net/url" + "slices" "strconv" "strings" "time" @@ -15,7 +16,6 @@ import ( piperHttp "github.com/SAP/jenkins-library/pkg/http" "github.com/SAP/jenkins-library/pkg/log" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -301,7 +301,7 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader defer closer.Close() } response, err := sys.client.SendRequest(method, fmt.Sprintf("%v/cxrestapi%v", sys.serverURL, url), requestBody, header, nil) - if err != nil && (response == nil || !piperutils.ContainsInt(acceptedErrorCodes, response.StatusCode)) { + if err != nil && (response == nil || !slices.Contains(acceptedErrorCodes, response.StatusCode)) { sys.recordRequestDetailsInErrorCase(requestBodyCopy, response) sys.logger.Errorf("HTTP request failed with error: %s", err) return nil, err diff --git a/pkg/checkmarxone/checkmarxone.go b/pkg/checkmarxone/checkmarxone.go index 6d5d14ab54..8f63053fb2 100644 --- a/pkg/checkmarxone/checkmarxone.go +++ b/pkg/checkmarxone/checkmarxone.go @@ -8,13 +8,13 @@ import ( "net/http" "net/url" "os" + "slices" "strconv" "strings" "time" piperHttp "github.com/SAP/jenkins-library/pkg/http" "github.com/SAP/jenkins-library/pkg/log" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -410,7 +410,7 @@ func sendRequestInternal(sys *SystemInstance, method, url string, body io.Reader //header.Set("User-Agent", "Project-Piper.io cicd pipeline") // currently this causes some requests to fail due to unknown UA validation in the backend. response, err := sys.client.SendRequest(method, url, requestBody, header, nil) - if err != nil && (response == nil || !piperutils.ContainsInt(acceptedErrorCodes, response.StatusCode)) { + if err != nil && (response == nil || !slices.Contains(acceptedErrorCodes, response.StatusCode)) { var resBodyBytes []byte if response != nil && response.Body != nil { diff --git a/pkg/config/config.go b/pkg/config/config.go index ddfaf50c4e..32e967271d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -72,9 +72,9 @@ func (c *Config) ApplyAliasConfig(parameters []StepParameters, secrets []StepSec if c.Steps[stepName] != nil { c.Steps[stepName] = setParamValueFromAlias(stepName, c.Steps[stepName], filters.Steps, p.Name, p.Aliases) } + //copy stage configuration with Build name if centralBuild, ok := c.Stages["Central Build"]; ok { c.Stages["Build"] = centralBuild - delete(c.Stages, "Central Build") } } for _, s := range secrets { @@ -85,9 +85,9 @@ func (c *Config) ApplyAliasConfig(parameters []StepParameters, secrets []StepSec if c.Steps[stepName] != nil { c.Steps[stepName] = setParamValueFromAlias(stepName, c.Steps[stepName], filters.Steps, s.Name, s.Aliases) } + //copy stage secrets configuration with Build name if centralBuild, ok := c.Stages["Central Build"]; ok { c.Stages["Build"] = centralBuild - delete(c.Stages, "Central Build") } } } @@ -193,9 +193,6 @@ func (c *Config) GetStepConfig(flagValues map[string]interface{}, paramJSON stri } c.ApplyAliasConfig(parameters, secrets, filters, stageName, stepName, stepAliases) - if stageName == "Central Build" { - stageName = "Build" - } // initialize with defaults from step.yaml stepConfig.mixInStepDefaults(parameters) @@ -300,7 +297,7 @@ func (c *Config) GetStepConfig(flagValues map[string]interface{}, paramJSON stri // hooks need to have been loaded from the defaults before the server URL is known err = c.setTrustEngineConfiguration(stepConfig.HookConfig) if err != nil { - log.Entry().WithError(err).Debug("Trust Engine lookup skipped due to missing or incorrect configuration") + log.Entry().WithError(err).Debug("System Trust lookup skipped due to missing or incorrect configuration") } else { trustengineClient := trustengine.PrepareClient(&piperhttp.Client{}, c.trustEngineConfiguration) resolveAllTrustEngineReferences(&stepConfig, append(parameters, ReportingParameters.Parameters...), c.trustEngineConfiguration, trustengineClient) diff --git a/pkg/config/evaluation.go b/pkg/config/evaluation.go index 4482a2d296..af90ac9059 100644 --- a/pkg/config/evaluation.go +++ b/pkg/config/evaluation.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "path" + "slices" "strings" "github.com/pkg/errors" @@ -49,7 +50,7 @@ func (r *RunConfigV1) evaluateConditionsV1(config *Config, utils piperutils.File stepConfigCache := make(map[string]StepConfig, len(stage.Steps)) for _, step := range stage.Steps { // Consider only orchestrator-specific steps if the orchestrator limitation is set. - if len(step.Orchestrators) > 0 && !piperutils.ContainsString(step.Orchestrators, currentOrchestrator) { + if len(step.Orchestrators) > 0 && !slices.Contains(step.Orchestrators, currentOrchestrator) { continue } diff --git a/pkg/config/trustengine.go b/pkg/config/trustengine.go index 2cd3e00010..5bb4e238ef 100644 --- a/pkg/config/trustengine.go +++ b/pkg/config/trustengine.go @@ -11,57 +11,57 @@ import ( // const RefTypeTrustengineSecretFile = "trustengineSecretFile" const RefTypeTrustengineSecret = "trustengineSecret" -// resolveAllTrustEngineReferences retrieves all the step's secrets from the Trust Engine +// resolveAllTrustEngineReferences retrieves all the step's secrets from the System Trust func resolveAllTrustEngineReferences(config *StepConfig, params []StepParameters, trustEngineConfiguration trustengine.Configuration, client *piperhttp.Client) { for _, param := range params { if ref := param.GetReference(RefTypeTrustengineSecret); ref != nil { if config.Config[param.Name] == "" { - log.Entry().Infof("Getting '%s' from Trust Engine", param.Name) + log.Entry().Infof("Getting '%s' from System Trust", param.Name) token, err := trustengine.GetToken(ref.Default, client, trustEngineConfiguration) if err != nil { log.Entry().Info(" failed") - log.Entry().WithError(err).Debugf("Couldn't get '%s' token from Trust Engine", ref.Default) + log.Entry().WithError(err).Debugf("Couldn't get '%s' token from System Trust", ref.Default) continue } log.RegisterSecret(token) config.Config[param.Name] = token log.Entry().Info(" succeeded") } else { - log.Entry().Debugf("Skipping retrieval of '%s' from Trust Engine: parameter already set", param.Name) + log.Entry().Debugf("Skipping retrieval of '%s' from System Trust: parameter already set", param.Name) } } } } -// setTrustEngineConfiguration sets the server URL for the Trust Engine by taking it from the hooks +// setTrustEngineConfiguration sets the server URL for the System Trust by taking it from the hooks func (c *Config) setTrustEngineConfiguration(hookConfig map[string]interface{}) error { trustEngineHook, ok := hookConfig["trustengine"].(map[string]interface{}) if !ok { - return errors.New("no Trust Engine hook configuration found") + return errors.New("no System Trust hook configuration found") } if serverURL, ok := trustEngineHook["serverURL"].(string); ok { c.trustEngineConfiguration.ServerURL = serverURL } else { - return errors.New("no Trust Engine server URL found") + return errors.New("no System Trust server URL found") } if tokenEndPoint, ok := trustEngineHook["tokenEndPoint"].(string); ok { c.trustEngineConfiguration.TokenEndPoint = tokenEndPoint } else { - return errors.New("no Trust Engine service endpoint found") + return errors.New("no System Trust service endpoint found") } if tokenQueryParamName, ok := trustEngineHook["tokenQueryParamName"].(string); ok { c.trustEngineConfiguration.TokenQueryParamName = tokenQueryParamName } else { - return errors.New("no Trust Engine query parameter name found") + return errors.New("no System Trust query parameter name found") } if len(c.trustEngineConfiguration.Token) == 0 { - return errors.New("no Trust Engine token found and envvar is empty") + return errors.New("no System Trust token found and envvar is empty") } return nil } -// SetTrustEngineToken sets the token for the Trust Engine +// SetTrustEngineToken sets the token for the System Trust func (c *Config) SetTrustEngineToken(token string) { c.trustEngineConfiguration.Token = token } diff --git a/pkg/config/trustengine_test.go b/pkg/config/trustengine_test.go index c475a9e8b2..0ba9827fc7 100644 --- a/pkg/config/trustengine_test.go +++ b/pkg/config/trustengine_test.go @@ -5,11 +5,12 @@ package config import ( "fmt" + "net/http" + "testing" + piperhttp "github.com/SAP/jenkins-library/pkg/http" "github.com/SAP/jenkins-library/pkg/trustengine" "github.com/jarcoal/httpmock" - "net/http" - "testing" "github.com/stretchr/testify/assert" ) @@ -40,7 +41,7 @@ func TestTrustEngineConfig(t *testing.T) { client := &piperhttp.Client{} client.SetOptions(piperhttp.ClientOptions{MaxRetries: -1, UseDefaultTransport: true}) - t.Run("Load secret from Trust Engine - secret not set yet by Vault or config.yml", func(t *testing.T) { + t.Run("Load secret from System Trust - secret not set yet by Vault or config.yml", func(t *testing.T) { stepConfig := &StepConfig{Config: map[string]interface{}{ secretName: "", }} @@ -49,7 +50,7 @@ func TestTrustEngineConfig(t *testing.T) { assert.Equal(t, mockSonarToken, stepConfig.Config[secretName]) }) - t.Run("Load secret from Trust Engine - secret already by Vault or config.yml", func(t *testing.T) { + t.Run("Load secret from System Trust - secret already by Vault or config.yml", func(t *testing.T) { stepConfig := &StepConfig{Config: map[string]interface{}{ secretName: "aMockTokenFromVault", }} diff --git a/pkg/docker/docker.go b/pkg/docker/docker.go index d4f757e00c..30e287abf4 100644 --- a/pkg/docker/docker.go +++ b/pkg/docker/docker.go @@ -9,6 +9,7 @@ import ( "path" "path/filepath" "regexp" + "slices" "strings" "github.com/docker/cli/cli/config" @@ -306,7 +307,7 @@ func ImageListWithFilePath(imageName string, excludes []string, trimDir string, // ToDo: needs rework // dockerfilePath = strings.ReplaceAll(dockerfilePath, cwd, ".") - if piperutils.ContainsString(excludes, dockerfilePath) { + if slices.Contains(excludes, dockerfilePath) { log.Entry().Infof("Discard %v since it is in the exclude list %v", dockerfilePath, excludes) continue } diff --git a/pkg/documentation/generator.go b/pkg/documentation/generator.go index 7f595aeb63..5e601068a4 100644 --- a/pkg/documentation/generator.go +++ b/pkg/documentation/generator.go @@ -32,12 +32,13 @@ func main() { var docTemplatePath string var customLibraryStepFile string var customDefaultFiles sliceFlags - var includeAzure bool + var includeAzure, includeGHA bool flag.StringVar(&metadataPath, "metadataDir", "./resources/metadata", "The directory containing the step metadata. Default points to \\'resources/metadata\\'.") flag.StringVar(&docTemplatePath, "docuDir", "./documentation/docs/steps/", "The directory containing the docu stubs. Default points to \\'documentation/docs/steps/\\'.") flag.StringVar(&customLibraryStepFile, "customLibraryStepFile", "", "") flag.Var(&customDefaultFiles, "customDefaultFile", "Path to a custom default configuration file.") flag.BoolVar(&includeAzure, "includeAzure", false, "Include Azure-specifics in step documentation.") + flag.BoolVar(&includeGHA, "includeGHA", false, "Include GitHub Actions-specifics in step documentation.") // flags for stage documentation var generateStageConfig bool @@ -85,7 +86,7 @@ func main() { OpenDocTemplateFile: openDocTemplateFile, DocFileWriter: writeFile, OpenFile: openFile, - }, includeAzure) + }, includeAzure, includeGHA) checkError(err) } } diff --git a/pkg/documentation/generator/description.go b/pkg/documentation/generator/description.go index 9d2301cedd..022833caae 100644 --- a/pkg/documentation/generator/description.go +++ b/pkg/documentation/generator/description.go @@ -13,7 +13,8 @@ const ( headlineUsage = "## Usage\n\n" headlineJenkinsPipeline = " === \"Jenkins\"\n\n" headlineCommandLine = " === \"Command Line\"\n\n" - headlineAzure = " === \"Azure\"\n\n" + headlineAzure = " === \"Azure DevOps\"\n\n" + headlineGHA = " === \"GitHub Actions\"\n\n" spacingTabBox = " " ) @@ -28,10 +29,10 @@ var CustomLibrarySteps = []CustomLibrary{} // CustomLibrary represents a custom library with it's custom step names, binary name and library name. type CustomLibrary struct { - Name string `yaml: "name,omitempty"` - BinaryName string `yaml: "binaryName,omitempty"` - LibraryName string `yaml: "libraryName,omitempty"` - Steps []string `yaml: "steps,omitempty"` + Name string `yaml:"name,omitempty"` + BinaryName string `yaml:"binaryName,omitempty"` + LibraryName string `yaml:"libraryName,omitempty"` + Steps []string `yaml:"steps,omitempty"` } // Replaces the StepName placeholder with the content from the yaml @@ -64,6 +65,20 @@ func createDescriptionSection(stepData *config.StepData) string { description += fmt.Sprintf("%v name: %v\n", spacingTabBox, stepData.Metadata.Name) description += fmt.Sprintf("%v inputs:\n", spacingTabBox) description += fmt.Sprintf("%v stepName: %v\n", spacingTabBox, stepData.Metadata.Name) + description += fmt.Sprintf("%v flags: --anyStepParameter\n", spacingTabBox) + description += fmt.Sprintf("%v```\n\n", spacingTabBox) + } + + // add GiHub Actions specific information if activated + if includeGHA { + description += headlineGHA + description += fmt.Sprintf("%v```\n", spacingTabBox) + description += fmt.Sprintf("%vsteps:\n", spacingTabBox) + description += fmt.Sprintf("%v - uses: SAP/project-piper-action@releaseCommitSHA\n", spacingTabBox) + description += fmt.Sprintf("%v name: %v\n", spacingTabBox, stepData.Metadata.Name) + description += fmt.Sprintf("%v with:\n", spacingTabBox) + description += fmt.Sprintf("%v step-name: %v\n", spacingTabBox, stepData.Metadata.Name) + description += fmt.Sprintf("%v flags: --anyStepParameter\n", spacingTabBox) description += fmt.Sprintf("%v```\n\n", spacingTabBox) } diff --git a/pkg/documentation/generator/main.go b/pkg/documentation/generator/main.go index 77328c2392..067ffd3cc7 100644 --- a/pkg/documentation/generator/main.go +++ b/pkg/documentation/generator/main.go @@ -25,7 +25,7 @@ type DocuHelperData struct { } var stepParameterNames []string -var includeAzure bool +var includeAzure, includeGHA bool func readStepConfiguration(stepMetadata config.StepData, customDefaultFiles []string, docuHelperData DocuHelperData) config.StepConfig { filters := stepMetadata.GetParameterFilters() @@ -58,8 +58,9 @@ func readStepConfiguration(stepMetadata config.StepData, customDefaultFiles []st } // GenerateStepDocumentation generates step coding based on step configuration provided in yaml files -func GenerateStepDocumentation(metadataFiles []string, customDefaultFiles []string, docuHelperData DocuHelperData, azure bool) error { +func GenerateStepDocumentation(metadataFiles []string, customDefaultFiles []string, docuHelperData DocuHelperData, azure bool, githubAction bool) error { includeAzure = azure + includeGHA = githubAction for key := range metadataFiles { stepMetadata := readStepMetadata(metadataFiles[key], docuHelperData) diff --git a/pkg/documentation/generator/parameters.go b/pkg/documentation/generator/parameters.go index 1c9e9f6848..e7aa5bc547 100644 --- a/pkg/documentation/generator/parameters.go +++ b/pkg/documentation/generator/parameters.go @@ -13,10 +13,12 @@ const ( vaultBadge = "![Vault](https://img.shields.io/badge/-Vault-lightgrey)" jenkinsOnlyBadge = "![Jenkins only](https://img.shields.io/badge/-Jenkins%20only-yellowgreen)" secretBadge = "![Secret](https://img.shields.io/badge/-Secret-yellowgreen)" - trustengineBadge = "![Trust Engine](https://img.shields.io/badge/-Trust%20Engine-lightblue)" + trustengineBadge = "![System Trust](https://img.shields.io/badge/-System%20Trust-lightblue)" deprecatedBadge = "![deprecated](https://img.shields.io/badge/-deprecated-red)" ) +var jenkinsParams = []string{"containerCommand", "containerName", "containerShell", "dockerVolumeBind", "dockerWorkspace", "sidecarReadyCommand", "sidecarWorkspace", "stashContent"} + // Replaces the Parameters placeholder with the content from the yaml func createParametersSection(stepData *config.StepData) string { @@ -97,7 +99,6 @@ func parameterFurtherInfo(paramName string, stepData *config.StepData, execution } // handle non-step parameters (e.g. Jenkins-specific parameters as well as execution environment parameters) - jenkinsParams := []string{"containerCommand", "containerName", "containerShell", "dockerVolumeBind", "dockerWorkspace", "sidecarReadyCommand", "sidecarWorkspace", "stashContent"} if !contains(stepParameterNames, paramName) { for _, secret := range stepData.Spec.Inputs.Secrets { if paramName == secret.Name && secret.Type == "jenkins" { @@ -123,7 +124,7 @@ func parameterFurtherInfo(paramName string, stepData *config.StepData, execution isVaultSecret := param.GetReference("vaultSecret") != nil || param.GetReference("vaultSecretFile") != nil isTrustengineSecret := param.GetReference(config.RefTypeTrustengineSecret) != nil if isVaultSecret && isTrustengineSecret { - secretInfo = fmt.Sprintf(" %s %s %s pass via ENV, Vault, Trust Engine or Jenkins credentials", vaultBadge, trustengineBadge, secretBadge) + secretInfo = fmt.Sprintf(" %s %s %s pass via ENV, Vault, System Trust or Jenkins credentials", vaultBadge, trustengineBadge, secretBadge) } else if isVaultSecret { secretInfo = fmt.Sprintf(" %s %s pass via ENV, Vault or Jenkins credentials", vaultBadge, secretBadge) } @@ -161,7 +162,7 @@ func createParameterDetails(stepData *config.StepData) string { for _, param := range stepData.Spec.Inputs.Parameters { details += fmt.Sprintf("#### %v\n\n", param.Name) - if !contains(stepParameterNames, param.Name) { + if !contains(stepParameterNames, param.Name) && contains(jenkinsParams, param.Name) { details += "**Jenkins-specific:** Used for proper environment setup.\n\n" } @@ -200,7 +201,7 @@ func createParameterDetails(stepData *config.StepData) string { for _, secret := range stepData.Spec.Inputs.Secrets { details += fmt.Sprintf("#### %v\n\n", secret.Name) - if !contains(stepParameterNames, secret.Name) { + if !contains(stepParameterNames, secret.Name) && contains(jenkinsParams, secret.Name) { details += "**Jenkins-specific:** Used for proper environment setup. See *[using credentials](https://www.jenkins.io/doc/book/using/using-credentials/)* for details.\n\n" } @@ -369,7 +370,7 @@ func addVaultResourceDetails(resource config.ResourceReference, resourceDetails } func addTrustEngineResourceDetails(resource config.ResourceReference, resourceDetails string) string { - resourceDetails += "
Trust Engine resource:
" + resourceDetails += "
System Trust resource:
" resourceDetails += fmt.Sprintf("  name: `%v`
", resource.Name) resourceDetails += fmt.Sprintf("  value: `%v`
", resource.Default) diff --git a/pkg/fortify/fortify.go b/pkg/fortify/fortify.go index 6d03e8e3fd..58952311d2 100644 --- a/pkg/fortify/fortify.go +++ b/pkg/fortify/fortify.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "os" + "slices" "strings" "time" @@ -30,7 +31,6 @@ import ( piperHttp "github.com/SAP/jenkins-library/pkg/http" "github.com/SAP/jenkins-library/pkg/log" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/go-openapi/runtime" "github.com/go-openapi/strfmt" @@ -529,7 +529,7 @@ func (sys *SystemInstance) ReduceIssueFilterSelectorSet(issueFilterSelectorSet * groupingList := []*models.IssueSelector{} if issueFilterSelectorSet.GroupBySet != nil { for _, group := range issueFilterSelectorSet.GroupBySet { - if piperutils.ContainsString(names, *group.DisplayName) { + if slices.Contains(names, *group.DisplayName) { log.Entry().Debugf("adding new grouping '%v' to reduced list", *group.DisplayName) groupingList = append(groupingList, group) } @@ -538,7 +538,7 @@ func (sys *SystemInstance) ReduceIssueFilterSelectorSet(issueFilterSelectorSet * filterList := []*models.IssueFilterSelector{} if issueFilterSelectorSet.FilterBySet != nil { for _, filter := range issueFilterSelectorSet.FilterBySet { - if piperutils.ContainsString(names, filter.DisplayName) { + if slices.Contains(names, filter.DisplayName) { newFilter := &models.IssueFilterSelector{} newFilter.DisplayName = filter.DisplayName newFilter.Description = filter.Description @@ -548,7 +548,7 @@ func (sys *SystemInstance) ReduceIssueFilterSelectorSet(issueFilterSelectorSet * newFilter.Value = filter.Value newFilter.SelectorOptions = []*models.SelectorOption{} for _, option := range filter.SelectorOptions { - if (nil != options && piperutils.ContainsString(options, option.DisplayName)) || options == nil || len(options) == 0 { + if (nil != options && slices.Contains(options, option.DisplayName)) || options == nil || len(options) == 0 { log.Entry().Debugf("adding selector option '%v' to list for filter selector '%v'", option.DisplayName, newFilter.DisplayName) newFilter.SelectorOptions = append(newFilter.SelectorOptions, option) } diff --git a/pkg/generator/helper/helper.go b/pkg/generator/helper/helper.go index 00301040e4..1a29d49a3c 100644 --- a/pkg/generator/helper/helper.go +++ b/pkg/generator/helper/helper.go @@ -7,11 +7,11 @@ import ( "os" "path/filepath" "reflect" + "slices" "strings" "text/template" "github.com/Masterminds/sprig" - "github.com/SAP/jenkins-library/pkg/config" "github.com/SAP/jenkins-library/pkg/piperutils" ) @@ -924,7 +924,7 @@ func mustUniqName(list []config.StepParameters) ([]config.StepParameters, error) var item config.StepParameters for i := 0; i < l; i++ { item = l2.Index(i).Interface().(config.StepParameters) - if !piperutils.ContainsString(names, item.Name) { + if !slices.Contains(names, item.Name) { names = append(names, item.Name) dest = append(dest, item) } diff --git a/pkg/maven/model.go b/pkg/maven/model.go index 2a4f9b74b2..9c5d72c273 100644 --- a/pkg/maven/model.go +++ b/pkg/maven/model.go @@ -3,8 +3,8 @@ package maven import ( "encoding/xml" "fmt" - "github.com/SAP/jenkins-library/pkg/piperutils" "path/filepath" + "slices" ) // Project describes the Maven object model. @@ -71,7 +71,7 @@ type visitUtils interface { // VisitAllMavenModules ... func VisitAllMavenModules(path string, utils visitUtils, excludes []string, callback func(info ModuleInfo) error) error { pomXMLPath := filepath.Join(path, "pom.xml") - if piperutils.ContainsString(excludes, pomXMLPath) { + if slices.Contains(excludes, pomXMLPath) { return nil } diff --git a/pkg/maven/settings.go b/pkg/maven/settings.go index 151b516ca9..880039a08a 100644 --- a/pkg/maven/settings.go +++ b/pkg/maven/settings.go @@ -218,7 +218,7 @@ func addServerTagtoProjectSettingsXML(projectSettingsFile string, altDeploymentR settingsXml, err := xml.MarshalIndent(projectSettings, "", " ") if err != nil { - fmt.Errorf("failed to marshal maven project settings xml: %w", err) + return fmt.Errorf("failed to marshal maven project settings xml: %w", err) } settingsXmlString := string(settingsXml) Replacer := strings.NewReplacer(" ", "", " ", "") @@ -226,12 +226,11 @@ func addServerTagtoProjectSettingsXML(projectSettingsFile string, altDeploymentR xmlstring := []byte(xml.Header + settingsXmlString) - err = utils.FileWrite(projectSettingsFile, xmlstring, 0777) - if err != nil { - fmt.Errorf("failed to write maven Settings xml: %w", err) + if err = utils.FileWrite(projectSettingsFile, xmlstring, 0777); err != nil { + return fmt.Errorf("failed to write maven Settings xml: %w", err) } - log.Entry().Infof("Successfully updated details in maven project settings file : '%s'", projectSettingsFile) + log.Entry().Infof("Successfully updated details in maven project settings file : '%s'", projectSettingsFile) return nil } diff --git a/pkg/mock/fileUtils.go b/pkg/mock/fileUtils.go index b8d13ff6cd..3c368aa67a 100644 --- a/pkg/mock/fileUtils.go +++ b/pkg/mock/fileUtils.go @@ -13,11 +13,11 @@ import ( "io" "os" "path/filepath" + "slices" "sort" "strings" "time" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/bmatcuk/doublestar" ) @@ -158,13 +158,13 @@ func (f *FilesMock) HasFile(path string) bool { // HasRemovedFile returns true if the virtual file system at one point contained an entry for the given path, // and it was removed via FileRemove(). func (f *FilesMock) HasRemovedFile(path string) bool { - return piperutils.ContainsString(f.removedFiles, f.toAbsPath(path)) + return slices.Contains(f.removedFiles, f.toAbsPath(path)) } // HasWrittenFile returns true if the virtual file system at one point contained an entry for the given path, // and it was written via FileWrite(). func (f *FilesMock) HasWrittenFile(path string) bool { - return piperutils.ContainsString(f.writtenFiles, f.toAbsPath(path)) + return slices.Contains(f.writtenFiles, f.toAbsPath(path)) } // HasCopiedFile returns true if the virtual file system at one point contained an entry for the given source and destination, diff --git a/pkg/multiarch/multiarch.go b/pkg/multiarch/multiarch.go index ce9c6cfa00..be2291651f 100644 --- a/pkg/multiarch/multiarch.go +++ b/pkg/multiarch/multiarch.go @@ -3,10 +3,10 @@ package multiarch import ( "fmt" "regexp" + "slices" "strings" "github.com/SAP/jenkins-library/pkg/log" - "github.com/SAP/jenkins-library/pkg/piperutils" ) var knownGoos = []string{"aix", "android", "darwin", "dragonfly", "freebsd", "hurd", "illumos", "ios", "js", "linux", "nacl", "netbsd", "openbsd", "plan9", "solaris", "windows", "zos"} @@ -42,13 +42,13 @@ func ParsePlatformString(s string) (Platform, error) { p.OS = strings.Trim(matches[1], " ") - if !piperutils.ContainsString(knownGoos, p.OS) { + if !slices.Contains(knownGoos, p.OS) { log.Entry().Warningf("OS '%s' is unknown to us", p.OS) } p.Arch = strings.Trim(matches[2], " ") - if !piperutils.ContainsString(knownGoarch, p.Arch) { + if !slices.Contains(knownGoarch, p.Arch) { log.Entry().Warningf("Architecture '%s' is unknown to us", p.Arch) } diff --git a/pkg/npm/publish.go b/pkg/npm/publish.go index a5626281b3..212d62cf84 100644 --- a/pkg/npm/publish.go +++ b/pkg/npm/publish.go @@ -16,8 +16,8 @@ import ( ) type npmMinimalPackageDescriptor struct { - Name string `json:version` - Version string `json:version` + Name string `json:"name"` + Version string `json:"version"` } func (pd *npmMinimalPackageDescriptor) Scope() string { diff --git a/pkg/npm/publish_test.go b/pkg/npm/publish_test.go index bdbdf8b655..a08d7e7db6 100644 --- a/pkg/npm/publish_test.go +++ b/pkg/npm/publish_test.go @@ -6,11 +6,11 @@ package npm import ( "io" "path/filepath" + "slices" "testing" "github.com/SAP/jenkins-library/pkg/mock" - "github.com/SAP/jenkins-library/pkg/piperutils" "github.com/SAP/jenkins-library/pkg/versioning" "github.com/stretchr/testify/assert" ) @@ -548,12 +548,12 @@ func TestNpmPublish(t *testing.T) { assert.Equal(t, "publish", publishCmd.Params[0]) if len(test.wants.tarballPath) > 0 && assert.Contains(t, publishCmd.Params, "--tarball") { - tarballPath := publishCmd.Params[piperutils.FindString(publishCmd.Params, "--tarball")+1] + tarballPath := publishCmd.Params[slices.Index(publishCmd.Params, "--tarball")+1] assert.Equal(t, test.wants.tarballPath, filepath.ToSlash(tarballPath)) } if assert.Contains(t, publishCmd.Params, "--userconfig") { - effectivePublishConfigPath := publishCmd.Params[piperutils.FindString(publishCmd.Params, "--userconfig")+1] + effectivePublishConfigPath := publishCmd.Params[slices.Index(publishCmd.Params, "--userconfig")+1] assert.Regexp(t, test.wants.publishConfigPath, filepath.ToSlash(effectivePublishConfigPath)) diff --git a/pkg/piperutils/maps_test.go b/pkg/piperutils/maps_test.go index f36ab43f5c..af8472ecb0 100644 --- a/pkg/piperutils/maps_test.go +++ b/pkg/piperutils/maps_test.go @@ -4,6 +4,7 @@ package piperutils import ( + "slices" "testing" "github.com/stretchr/testify/assert" @@ -15,10 +16,10 @@ func TestKeys(t *testing.T) { intList := Keys(intStringMap) assert.Equal(t, 4, len(intList)) - assert.Equal(t, true, ContainsInt(intList, 1)) - assert.Equal(t, true, ContainsInt(intList, 2)) - assert.Equal(t, true, ContainsInt(intList, 3)) - assert.Equal(t, true, ContainsInt(intList, 4)) + assert.Equal(t, true, slices.Contains(intList, 1)) + assert.Equal(t, true, slices.Contains(intList, 2)) + assert.Equal(t, true, slices.Contains(intList, 3)) + assert.Equal(t, true, slices.Contains(intList, 4)) } func TestValues(t *testing.T) { @@ -27,8 +28,8 @@ func TestValues(t *testing.T) { intList := Values(intStringMap) assert.Equal(t, 4, len(intList)) - assert.Equal(t, true, ContainsString(intList, "eins")) - assert.Equal(t, true, ContainsString(intList, "zwei")) - assert.Equal(t, true, ContainsString(intList, "drei")) - assert.Equal(t, true, ContainsString(intList, "vier")) + assert.Equal(t, true, slices.Contains(intList, "eins")) + assert.Equal(t, true, slices.Contains(intList, "zwei")) + assert.Equal(t, true, slices.Contains(intList, "drei")) + assert.Equal(t, true, slices.Contains(intList, "vier")) } diff --git a/pkg/piperutils/slices.go b/pkg/piperutils/slices.go index 5b7ea72131..c5f7bbf49b 100644 --- a/pkg/piperutils/slices.go +++ b/pkg/piperutils/slices.go @@ -5,32 +5,6 @@ import ( "strings" ) -// ContainsInt checks whether the element is part of the slice -func ContainsInt(s []int, e int) bool { - for _, a := range s { - if a == e { - return true - } - } - return false -} - -// ContainsString checks whether the element is part of the slice -func ContainsString(s []string, e string) bool { - return FindString(s, e) >= 0 -} - -// FindString returns the position of element e in the given slice or -1 if it's not in -func FindString(s []string, e string) int { - for i, a := range s { - if a == e { - return i - } - } - - return -1 -} - // ContainsStringPart checks whether the element is contained as part of one of the elements of the slice func ContainsStringPart(s []string, part string) bool { for _, a := range s { @@ -43,14 +17,14 @@ func ContainsStringPart(s []string, part string) bool { // RemoveAll removes all instances of element from the slice and returns a truncated slice as well as // a boolean to indicate whether at least one element was found and removed. -func RemoveAll(s []string, e string) ([]string, bool) { - var r []string - for _, a := range s { - if a != e { - r = append(r, a) +func RemoveAll(arr []string, item string) ([]string, bool) { + res := make([]string, 0, len(arr)) + for _, a := range arr { + if a != item { + res = append(res, a) } } - return r, len(s) != len(r) + return res, len(arr) != len(res) } // Prefix adds a prefix to each element of the slice diff --git a/pkg/piperutils/slices_test.go b/pkg/piperutils/slices_test.go index bd10429153..fd156ad019 100644 --- a/pkg/piperutils/slices_test.go +++ b/pkg/piperutils/slices_test.go @@ -9,41 +9,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestContainsInt(t *testing.T) { - var intList []int - assert.Equal(t, false, ContainsInt(intList, 4)) - - intList = append(intList, 1, 2, 3, 4, 5, 6, 20) - assert.Equal(t, true, ContainsInt(intList, 20)) - assert.Equal(t, true, ContainsInt(intList, 1)) - assert.Equal(t, true, ContainsInt(intList, 4)) - assert.Equal(t, false, ContainsInt(intList, 13)) -} - -func TestContainsString(t *testing.T) { - var stringList []string - assert.False(t, ContainsString(stringList, "test")) - assert.False(t, ContainsString(stringList, "")) - - stringList = append(stringList, "", "foo", "bar", "foo") - assert.True(t, ContainsString(stringList, "")) - assert.True(t, ContainsString(stringList, "bar")) - assert.True(t, ContainsString(stringList, "foo")) - assert.False(t, ContainsString(stringList, "baz")) -} - -func TestFindString(t *testing.T) { - var stringList []string - assert.Equal(t, -1, FindString(stringList, "test")) - assert.Equal(t, -1, FindString(stringList, "")) - - stringList = append(stringList, "", "foo", "bar", "foo") - assert.Equal(t, 0, FindString(stringList, "")) - assert.Equal(t, 2, FindString(stringList, "bar")) - assert.Equal(t, 1, FindString(stringList, "foo")) - assert.Equal(t, -1, FindString(stringList, "baz")) -} - func TestRemoveAll(t *testing.T) { t.Parallel() t.Run("empty array", func(t *testing.T) { diff --git a/pkg/trustengine/trustengine.go b/pkg/trustengine/trustengine.go index 99caf500ae..a84738a1e3 100644 --- a/pkg/trustengine/trustengine.go +++ b/pkg/trustengine/trustengine.go @@ -35,17 +35,17 @@ type Configuration struct { func GetToken(refName string, client *piperhttp.Client, trustEngineConfiguration Configuration) (string, error) { secrets, err := GetSecrets([]string{refName}, client, trustEngineConfiguration) if err != nil { - return "", errors.Wrap(err, "couldn't get token from trust engine") + return "", errors.Wrap(err, "couldn't get token from System Trust") } for _, s := range secrets { if s.System == refName { return s.Token, nil } } - return "", errors.New("could not find token in trust engine response") + return "", errors.New("could not find token in System Trust response") } -// GetSecrets transforms the trust engine JSON response into trust engine secrets, and can be used to request multiple tokens +// GetSecrets transforms the System Trust JSON response into System Trust secrets, and can be used to request multiple tokens func GetSecrets(refNames []string, client *piperhttp.Client, trustEngineConfiguration Configuration) ([]Secret, error) { var secrets []Secret query := url.Values{ @@ -55,7 +55,7 @@ func GetSecrets(refNames []string, client *piperhttp.Client, trustEngineConfigur } response, err := getResponse(trustEngineConfiguration.ServerURL, trustEngineConfiguration.TokenEndPoint, query, client) if err != nil { - return secrets, errors.Wrap(err, "getting secrets from trust engine failed") + return secrets, errors.Wrap(err, "getting secrets from System Trust failed") } for k, v := range response { secrets = append(secrets, Secret{ @@ -66,13 +66,13 @@ func GetSecrets(refNames []string, client *piperhttp.Client, trustEngineConfigur return secrets, nil } -// getResponse returns a map of the JSON response that the trust engine puts out +// getResponse returns a map of the JSON response that the System Trust puts out func getResponse(serverURL, endpoint string, query url.Values, client *piperhttp.Client) (map[string]string, error) { var secrets map[string]string rawURL, err := parseURL(serverURL, endpoint, query) if err != nil { - return secrets, errors.Wrap(err, "parsing trust engine url failed") + return secrets, errors.Wrap(err, "parsing System Trust url failed") } header := make(http.Header) header.Add("Accept", "application/json") @@ -88,38 +88,38 @@ func getResponse(serverURL, endpoint string, query url.Values, client *piperhttp err = errors.Wrap(err, string(bodyBytes)) } } - return secrets, errors.Wrap(err, "getting response from trust engine failed") + return secrets, errors.Wrap(err, "getting response from System Trust failed") } defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&secrets) if err != nil { - return secrets, errors.Wrap(err, "getting response from trust engine failed") + return secrets, errors.Wrap(err, "getting response from System Trust failed") } return secrets, nil } -// parseURL creates the full URL for a Trust Engine GET request +// parseURL creates the full URL for a System Trust GET request func parseURL(serverURL, endpoint string, query url.Values) (string, error) { rawFullEndpoint, err := url.JoinPath(serverURL, endpoint) if err != nil { - return "", errors.New("error parsing trust engine URL") + return "", errors.New("error parsing System Trust URL") } fullURL, err := url.Parse(rawFullEndpoint) if err != nil { - return "", errors.New("error parsing trust engine URL") + return "", errors.New("error parsing System Trust URL") } - // commas and spaces shouldn't be escaped since the Trust Engine won't accept it + // commas and spaces shouldn't be escaped since the System Trust won't accept it unescapedRawQuery, err := url.QueryUnescape(query.Encode()) if err != nil { - return "", errors.New("error parsing trust engine URL") + return "", errors.New("error parsing System Trust URL") } fullURL.RawQuery = unescapedRawQuery return fullURL.String(), nil } -// PrepareClient adds the Trust Engine authentication token to the client +// PrepareClient adds the System Trust authentication token to the client func PrepareClient(client *piperhttp.Client, trustEngineConfiguration Configuration) *piperhttp.Client { var logEntry *logrus.Entry if logrus.GetLevel() < logrus.DebugLevel { diff --git a/pkg/whitesource/reporting.go b/pkg/whitesource/reporting.go index 56e5cefa0d..03c956f32f 100644 --- a/pkg/whitesource/reporting.go +++ b/pkg/whitesource/reporting.go @@ -8,6 +8,7 @@ import ( "fmt" "path/filepath" "runtime" + "slices" "sort" "strings" "time" @@ -217,7 +218,7 @@ func CreateSarifResultFile(scan *Scan, alerts *[]Alert) *format.SARIF { sarif.Runs[0].Results = append(sarif.Runs[0].Results, result) // only create rule on new CVE - if !piperutils.ContainsString(collectedRules, ruleId) { + if !slices.Contains(collectedRules, ruleId) { collectedRules = append(collectedRules, ruleId) sarifRule := *new(format.SarifRule) diff --git a/resources/metadata/cloudFoundryDeploy.yaml b/resources/metadata/cloudFoundryDeploy.yaml index c49a5c5a30..921000fdd5 100644 --- a/resources/metadata/cloudFoundryDeploy.yaml +++ b/resources/metadata/cloudFoundryDeploy.yaml @@ -370,6 +370,11 @@ spec: containers: - name: cfDeploy image: ppiper/cf-cli:latest + options: + - name: --ulimit + value: "stack=67108864:67108864" # Stack Size (in bytes). 64mb + - name: --ulimit + value: "nofile=65536:65536" # Number of Open Files outputs: resources: - name: influx diff --git a/src/com/sap/piper/ConfigurationHelper.groovy b/src/com/sap/piper/ConfigurationHelper.groovy index b6b1558ddf..2eeaaf0e6f 100644 --- a/src/com/sap/piper/ConfigurationHelper.groovy +++ b/src/com/sap/piper/ConfigurationHelper.groovy @@ -10,9 +10,6 @@ class ConfigurationHelper implements Serializable { } ConfigurationHelper loadStepDefaults(Map compatibleParameters = [:], String stageName = step.env.STAGE_NAME) { - if (stageName == 'Central Build'){ - stageName = 'Build' - } DefaultValueCache.prepare(step) this.config = ConfigurationLoader.defaultGeneralConfiguration() mixin(ConfigurationLoader.defaultGeneralConfiguration(), null, compatibleParameters) diff --git a/src/com/sap/piper/PiperGoUtils.groovy b/src/com/sap/piper/PiperGoUtils.groovy index 3c2f63036e..f4765de7da 100644 --- a/src/com/sap/piper/PiperGoUtils.groovy +++ b/src/com/sap/piper/PiperGoUtils.groovy @@ -30,7 +30,7 @@ class PiperGoUtils implements Serializable { if (steps.env.REPOSITORY_UNDER_TEST && steps.env.LIBRARY_VERSION_UNDER_TEST) { steps.echo("Running in a consumer test, building unit-under-test binary for verification.") - steps.dockerExecute(script: steps, dockerImage: 'golang:1.22.4', dockerOptions: '-u 0', dockerEnvVars: [ + steps.dockerExecute(script: steps, dockerImage: 'golang:1.23.4', dockerOptions: '-u 0', dockerEnvVars: [ REPOSITORY_UNDER_TEST: steps.env.REPOSITORY_UNDER_TEST, LIBRARY_VERSION_UNDER_TEST: steps.env.LIBRARY_VERSION_UNDER_TEST ]) { diff --git a/src/com/sap/piper/StageNameProvider.groovy b/src/com/sap/piper/StageNameProvider.groovy index cd2fa71f06..ceb7967629 100644 --- a/src/com/sap/piper/StageNameProvider.groovy +++ b/src/com/sap/piper/StageNameProvider.groovy @@ -3,8 +3,6 @@ package com.sap.piper @Singleton class StageNameProvider implements Serializable { static final long serialVersionUID = 1L - static final String CENTRAL_BUILD = "Central Build"; - static final String BUILD = "Build"; /** Stores a feature toggle for defaulting to technical names in stages */ boolean useTechnicalStageNames = false @@ -12,9 +10,7 @@ class StageNameProvider implements Serializable { String getStageName(Script script, Map parameters, Script step) { String stageName = null if (parameters.stageName in CharSequence) { - stageName = parameters.stageName - stageName = replaceCentralBuild(stageName); - return stageName + return parameters.stageName } if (this.useTechnicalStageNames) { String technicalStageName = getTechnicalStageName(step) @@ -22,15 +18,7 @@ class StageNameProvider implements Serializable { return technicalStageName } } - if (stageName == null) { - stageName = script.env.STAGE_NAME - stageName = replaceCentralBuild(stageName); - } - return stageName - } - - private String replaceCentralBuild(String stageName) { - return CENTRAL_BUILD.equals(stageName) ? BUILD : stageName; + return script.env.STAGE_NAME } static String getTechnicalStageName(Script step) { diff --git a/vars/commonPipelineEnvironment.groovy b/vars/commonPipelineEnvironment.groovy index 90e3a871d3..b44842d9ca 100644 --- a/vars/commonPipelineEnvironment.groovy +++ b/vars/commonPipelineEnvironment.groovy @@ -192,9 +192,6 @@ class commonPipelineEnvironment implements Serializable { Map getStepConfiguration(stepName, stageName = env.STAGE_NAME, includeDefaults = true) { Map defaults = [:] - if (stageName == 'Central Build') { - stageName = 'Build' - } if (includeDefaults) { defaults = ConfigurationLoader.defaultGeneralConfiguration() defaults = ConfigurationMerger.merge(ConfigurationLoader.defaultStepConfiguration(null, stepName), null, defaults) diff --git a/vars/piperExecuteBin.groovy b/vars/piperExecuteBin.groovy index 311242c81a..08dec74004 100644 --- a/vars/piperExecuteBin.groovy +++ b/vars/piperExecuteBin.groovy @@ -78,6 +78,11 @@ void call(Map parameters = [:], String stepName, String metadataFile, List crede try { try { credentialWrapper(config, credentialInfo) { + if (config.verbose) { // need to be set on step config + echo "[DEBUG] Current environment limits:" + sh "ulimit -a" + } + sh "${piperGoPath} ${stepName}${defaultConfigArgs}${customConfigArg}" } } finally {