Skip to content

Commit

Permalink
Merge branch 'master' into phgermanov/npm-execute-tests-go
Browse files Browse the repository at this point in the history
  • Loading branch information
phgermanov authored Jan 2, 2025
2 parents a205ec9 + 85dfe3e commit d768424
Show file tree
Hide file tree
Showing 52 changed files with 281 additions and 207 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/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:
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
2 changes: 1 addition & 1 deletion cmd/cloudFoundryDeploy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
49 changes: 49 additions & 0 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,62 @@ 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
}
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})
Expand Down
68 changes: 68 additions & 0 deletions cmd/whitesourceExecuteScan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
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
Loading

0 comments on commit d768424

Please sign in to comment.