Skip to content

Commit

Permalink
Update go version to 1.23 and removed some helper methods in favor of…
Browse files Browse the repository at this point in the history
… STD library (#5200)

* update go version

* fix go vet errors

* replaces stringutils with slices std package

* added slices package

* 1.22.4 to 1.23.4

---------

Co-authored-by: Valentin <[email protected]>
  • Loading branch information
bitmaskit and Valentin authored Dec 12, 2024
1 parent e927605 commit dfd947b
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 140 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ indent_style = none
indent_size = none
[{go.mod,go.sum,*.go,*.golden}]
indent_style = tab
indent_size = 8
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-go-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-go-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/verify-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: styfle/[email protected]
- 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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.4 AS build-env
FROM golang:1.23.4 AS build-env
COPY . /build
WORKDIR /build

Expand Down
3 changes: 2 additions & 1 deletion cmd/cloudFoundryDeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"regexp"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cnbBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"slices"

"github.com/SAP/jenkins-library/pkg/buildpacks"
"github.com/SAP/jenkins-library/pkg/buildsettings"
Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmd/fortifyExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fortifyExecuteScan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"strings"
"testing"
"time"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/kanikoExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"slices"
"strings"

"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/newmanExecute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/terraformExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"fmt"
"slices"

"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/example/golang-app

go 1.22.4
go 1.23.4
5 changes: 3 additions & 2 deletions pkg/blackduck/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path/filepath"
"runtime"
"slices"
"strings"

"github.com/SAP/jenkins-library/pkg/format"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/blackduck/reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package blackduck
import (
"fmt"
"path/filepath"
"slices"
"testing"

"github.com/SAP/jenkins-library/pkg/format"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/checkmarx/checkmarx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/checkmarxone/checkmarxone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"path"
"slices"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"regexp"
"slices"
"strings"

"github.com/docker/cli/cli/config"
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit dfd947b

Please sign in to comment.