From ab0b489085a3d0741c1a9329b4c1d20140067715 Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:30:59 +0200 Subject: [PATCH 1/6] Adapt moved logic at core (#2362) --- artifactory/cli.go | 44 +++++++------ artifactory_test.go | 13 ++-- buildinfo_test.go | 23 +++---- buildtools/cli.go | 76 +++++++++++----------- docker_test.go | 8 ++- general/cisetup/cisetup.go | 4 +- go.mod | 2 +- go.sum | 4 +- go_test.go | 9 +-- gradle_test.go | 6 +- inttestutils/buildinfo.go | 2 +- main_test.go | 27 ++++---- maven_test.go | 12 ++-- npm_test.go | 19 +++--- nuget_test.go | 21 +++--- scan/cli.go | 14 ++-- utils/cliutils/utils.go | 20 +++--- xray_test.go | 129 +++++++++++++++++++------------------ 18 files changed, 226 insertions(+), 207 deletions(-) diff --git a/artifactory/cli.go b/artifactory/cli.go index 12a639464..bc8a7fded 100644 --- a/artifactory/cli.go +++ b/artifactory/cli.go @@ -30,7 +30,9 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/usersmanagement" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/project" "github.com/jfrog/jfrog-cli-core/v2/common/spec" corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common" coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" @@ -328,7 +330,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", "rt", utils.Maven, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", "rt", project.Maven, c, cliutils.CreateConfigCmd) }, }, { @@ -341,7 +343,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("mvn", utils.Maven, c, buildtools.MvnCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("mvn", project.Maven, c, buildtools.MvnCmd) }, }, { @@ -353,7 +355,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", "rt", utils.Gradle, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", "rt", project.Gradle, c, cliutils.CreateConfigCmd) }, }, { @@ -366,7 +368,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("gradle", utils.Gradle, c, buildtools.GradleCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("gradle", project.Gradle, c, buildtools.GradleCmd) }, }, { @@ -463,7 +465,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("npmc", "rt", utils.Npm, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("npmc", "rt", project.Npm, c, cliutils.CreateConfigCmd) }, }, { @@ -477,7 +479,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("npm install", utils.Npm, c, buildtools.NpmInstallCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("npm install", project.Npm, c, buildtools.NpmInstallCmd) }, }, { @@ -491,7 +493,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("npm ci", utils.Npm, c, buildtools.NpmCiCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("npm ci", project.Npm, c, buildtools.NpmCiCmd) }, }, { @@ -504,7 +506,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("npm p", utils.Npm, c, buildtools.NpmPublishCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("npm p", project.Npm, c, buildtools.NpmPublishCmd) }, }, { @@ -516,7 +518,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", "rt", utils.Yarn, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", "rt", project.Yarn, c, cliutils.CreateConfigCmd) }, }, { @@ -528,7 +530,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("yarn", utils.Yarn, c, buildtools.YarnCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("yarn", project.Yarn, c, buildtools.YarnCmd) }, }, { @@ -540,7 +542,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", "rt", utils.Nuget, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", "rt", project.Nuget, c, cliutils.CreateConfigCmd) }, }, { @@ -553,7 +555,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("nuget", utils.Nuget, c, buildtools.NugetCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("nuget", project.Nuget, c, buildtools.NugetCmd) }, }, { @@ -574,7 +576,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", "rt", utils.Dotnet, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", "rt", project.Dotnet, c, cliutils.CreateConfigCmd) }, }, { @@ -587,7 +589,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("dotnet", utils.Dotnet, c, buildtools.DotnetCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("dotnet", project.Dotnet, c, buildtools.DotnetCmd) }, }, { @@ -598,7 +600,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("go-config", "rt", utils.Go, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("go-config", "rt", project.Go, c, cliutils.CreateConfigCmd) }, }, { @@ -625,7 +627,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("go", utils.Go, c, buildtools.GoCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("go", project.Go, c, buildtools.GoCmd) }, }, { @@ -659,7 +661,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("pipc", "rt", utils.Pip, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("pipc", "rt", project.Pip, c, cliutils.CreateConfigCmd) }, }, { @@ -673,7 +675,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunNativeCmdWithDeprecationWarning("pip install", utils.Pip, c, pipDeprecatedInstallCmd) + return cliutils.RunNativeCmdWithDeprecationWarning("pip install", project.Pip, c, pipDeprecatedInstallCmd) }, }, { @@ -1123,7 +1125,7 @@ func ocStartBuildCmd(c *cli.Context) error { } // Extract build configuration - filteredOcArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(args) + filteredOcArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args) if err != nil { return err } @@ -1855,10 +1857,10 @@ func pipDeprecatedInstallCmd(c *cli.Context) error { } // Get python configuration. - pythonConfig, err := utils.GetResolutionOnlyConfiguration(utils.Pip) + pythonConfig, err := project.GetResolutionOnlyConfiguration(project.Pip) if err != nil { return fmt.Errorf("error occurred while attempting to read %[1]s-configuration file: %[2]s\n"+ - "Please run 'jf %[1]s-config' command prior to running 'jf %[1]s'", utils.Pip.String(), err.Error()) + "Please run 'jf %[1]s-config' command prior to running 'jf %[1]s'", project.Pip.String(), err.Error()) } // Set arg values. diff --git a/artifactory_test.go b/artifactory_test.go index 4330130a7..028321b80 100644 --- a/artifactory_test.go +++ b/artifactory_test.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" "fmt" - biutils "github.com/jfrog/build-info-go/utils" "io" "net" "net/http" @@ -24,15 +23,19 @@ import ( "testing" "time" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/buger/jsonparser" gofrogio "github.com/jfrog/gofrog/io" "github.com/jfrog/gofrog/version" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/project" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" + "github.com/jfrog/jfrog-cli-core/v2/utils/dependencies" coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" "github.com/jfrog/jfrog-cli/inttestutils" "github.com/jfrog/jfrog-cli/utils/cliutils" @@ -4969,7 +4972,7 @@ func TestGetExtractorsRemoteDetails(t *testing.T) { } func validateExtractorRemoteDetails(t *testing.T, downloadPath, expectedRemotePath string) { - serverDetails, remotePath, err := utils.GetExtractorsRemoteDetails(downloadPath) + serverDetails, remotePath, err := dependencies.GetExtractorsRemoteDetails(downloadPath) assert.NoError(t, err) assert.Equal(t, expectedRemotePath, remotePath) assert.False(t, os.Getenv(coreutils.DeprecatedExtractorsRemoteEnv) != "" && serverDetails == nil, "Expected a server to be returned") @@ -4993,7 +4996,7 @@ func TestGetReleasesRemoteDetails(t *testing.T) { } func validateReleasesRemoteDetails(t *testing.T, downloadPath, expectedRemotePath string) { - serverDetails, remotePath, err := utils.GetExtractorsRemoteDetails(downloadPath) + serverDetails, remotePath, err := dependencies.GetExtractorsRemoteDetails(downloadPath) assert.NoError(t, err) assert.Equal(t, expectedRemotePath, remotePath) assert.False(t, os.Getenv(coreutils.ReleasesRemoteEnv) != "" && serverDetails == nil, "Expected a server to be returned") @@ -5658,7 +5661,7 @@ func testProjectInit(t *testing.T, projectExampleName string, technology coreuti } func validateProjectYamlFile(t *testing.T, projectDir, technology string) { - techConfig, err := utils.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", technology+".yaml"), utils.YAML) + techConfig, err := project.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", technology+".yaml"), project.YAML) if assert.NoError(t, err) { assert.Equal(t, technology, techConfig.GetString("type")) assert.Equal(t, tests.ServerId, techConfig.GetString("resolver.serverId")) @@ -5667,7 +5670,7 @@ func validateProjectYamlFile(t *testing.T, projectDir, technology string) { } func validateBuildYamlFile(t *testing.T, projectDir string) { - techConfig, err := utils.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", "build.yaml"), utils.YAML) + techConfig, err := project.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", "build.yaml"), project.YAML) assert.NoError(t, err) assert.Equal(t, "build", techConfig.GetString("type")) assert.Equal(t, filepath.Base(projectDir+"/"), techConfig.GetString("name")) diff --git a/buildinfo_test.go b/buildinfo_test.go index 82a6b611d..a86de6eb9 100644 --- a/buildinfo_test.go +++ b/buildinfo_test.go @@ -14,6 +14,7 @@ import ( clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" buildinfo "github.com/jfrog/build-info-go/entities" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-client-go/utils/log" @@ -153,7 +154,7 @@ func validateArtifactsProperties(resultItems []rtutils.ResultItem, t *testing.T, func TestBuildAddDependenciesDryRun(t *testing.T) { initArtifactoryTest(t, "") // Clean old build tests if exists - assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, "1", "")) + assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, "1", "")) wd, err := os.Getwd() assert.NoError(t, err, "Failed to get current dir") @@ -163,7 +164,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) { noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "") // Execute the bad command on the local file system assert.NoError(t, noCredsCli.Exec("bad", tests.RtBuildName1, "1", "a/*", "--dry-run=true")) - buildDir, err := utils.GetBuildDir(tests.RtBuildName1, "1", "") + buildDir, err := build.GetBuildDir(tests.RtBuildName1, "1", "") assert.NoError(t, err) files, _ := os.ReadDir(buildDir) @@ -176,7 +177,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) { assert.NoError(t, err) defer deleteServerConfig(t) assert.NoError(t, noCredsCli.Exec("bad", tests.RtBuildName1, "2", tests.RtRepo1+"/*", "--from-rt", "--server-id="+tests.ServerId, "--dry-run=true")) - buildDir, err = utils.GetBuildDir(tests.RtBuildName1, "2", "") + buildDir, err = build.GetBuildDir(tests.RtBuildName1, "2", "") assert.NoError(t, err) files, _ = os.ReadDir(buildDir) @@ -192,7 +193,7 @@ func TestBuildPublishDetailedSummary(t *testing.T) { // Clean old build tests if exists. inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) - assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, buildNumber, "")) + assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, buildNumber, "")) // Upload files with build name & number. specFile, err := tests.CreateSpec(tests.UploadFlatNonRecursive) @@ -217,7 +218,7 @@ func TestBuildPublishDryRun(t *testing.T) { buildNumber := "11" // Clean old build tests if exists. inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) - assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, buildNumber, "")) + assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, buildNumber, "")) // Upload files with build name & number. specFile, err := tests.CreateSpec(tests.UploadFlatRecursive) @@ -286,7 +287,7 @@ func verifyBuildPublishOutput(t *testing.T, buffer *bytes.Buffer, dryRun bool) { // //nolint:unparam func getFilesFromBuildDir(t *testing.T, buildName, buildNumber string) []os.DirEntry { - buildDir, err := utils.GetBuildDir(buildName, buildNumber, "") + buildDir, err := build.GetBuildDir(buildName, buildNumber, "") assert.NoError(t, err) files, err := os.ReadDir(buildDir) @@ -312,7 +313,7 @@ func TestBuildAppend(t *testing.T) { runRt(t, "ba", tests.RtBuildName2, buildNumber2, tests.RtBuildName1, buildNumber1) // Assert RtBuildName2/buildNumber2 is appended to RtBuildName1/buildNumber1 locally - partials, err := utils.ReadPartialBuildInfoFiles(tests.RtBuildName2, buildNumber2, "") + partials, err := build.ReadPartialBuildInfoFiles(tests.RtBuildName2, buildNumber2, "") assert.NoError(t, err) assert.Len(t, partials, 1) assert.Equal(t, tests.RtBuildName1+"/"+buildNumber1, partials[0].ModuleId) @@ -473,11 +474,11 @@ func TestBuildAddDependencies(t *testing.T) { collectDepsAndPublishBuild(badTest, true, t) validateBuildAddDepsBuildInfo(t, badTest) - assert.NoError(t, utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")) + assert.NoError(t, build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")) collectDepsAndPublishBuild(badTest, false, t) validateBuildAddDepsBuildInfo(t, badTest) - assert.NoError(t, utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")) + assert.NoError(t, build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")) } inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails) cleanArtifactoryTest() @@ -693,7 +694,7 @@ func testBuildAddGit(t *testing.T, useEnvBuildNameAndNumber bool) { } // Check partials VCS info - partials, err := utils.ReadPartialBuildInfoFiles(tests.RtBuildName1, buildNumber, "") + partials, err := build.ReadPartialBuildInfoFiles(tests.RtBuildName1, buildNumber, "") assert.NoError(t, err) expectedVcsUrl := "https://github.com/jfrog/jfrog-cli-go.git" expectedVcsRevision := "b033a0e508bdb52eee25654c9e12db33ff01b8ff" @@ -844,7 +845,7 @@ func TestModuleName(t *testing.T) { func collectDepsAndPublishBuild(badTest buildAddDepsBuildInfoTestParams, useEnvBuildNameAndNumber bool, t *testing.T) { noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "") // Remove old tests data from fs if exists - err := utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "") + err := build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "") assert.NoError(t, err) command := []string{"bad"} diff --git a/buildtools/cli.go b/buildtools/cli.go index fab86d358..082d79d2f 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -17,9 +17,11 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/terraform" commandsUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/yarn" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + outputFormat "github.com/jfrog/jfrog-cli-core/v2/common/format" + "github.com/jfrog/jfrog-cli-core/v2/common/project" corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common" coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" @@ -71,7 +73,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Maven) + return cliutils.CreateConfigCmd(c, project.Maven) }, }, { @@ -96,7 +98,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Gradle) + return cliutils.CreateConfigCmd(c, project.Gradle) }, }, { @@ -121,7 +123,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Yarn) + return cliutils.CreateConfigCmd(c, project.Yarn) }, }, { @@ -145,7 +147,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Nuget) + return cliutils.CreateConfigCmd(c, project.Nuget) }, }, { @@ -170,7 +172,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Dotnet) + return cliutils.CreateConfigCmd(c, project.Dotnet) }, }, { @@ -195,7 +197,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Go) + return cliutils.CreateConfigCmd(c, project.Go) }, }, { @@ -233,7 +235,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Pip) + return cliutils.CreateConfigCmd(c, project.Pip) }, }, { @@ -258,7 +260,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Pipenv) + return cliutils.CreateConfigCmd(c, project.Pipenv) }, }, { @@ -283,7 +285,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Poetry) + return cliutils.CreateConfigCmd(c, project.Poetry) }, }, { @@ -308,7 +310,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Npm) + return cliutils.CreateConfigCmd(c, project.Npm) }, }, { @@ -353,7 +355,7 @@ func GetCommands() []cli.Command { BashComplete: corecommon.CreateBashCompletionFunc(), Category: buildToolsCategory, Action: func(c *cli.Context) error { - return cliutils.CreateConfigCmd(c, utils.Terraform) + return cliutils.CreateConfigCmd(c, project.Terraform) }, }, { @@ -377,7 +379,7 @@ func MvnCmd(c *cli.Context) (err error) { return err } - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Maven) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Maven) if err != nil { return err } @@ -392,7 +394,7 @@ func MvnCmd(c *cli.Context) (err error) { if err != nil { return err } - filteredMavenArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(filteredMavenArgs) + filteredMavenArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(filteredMavenArgs) if err != nil { return err } @@ -416,7 +418,7 @@ func MvnCmd(c *cli.Context) (err error) { if !xrayScan && format != "" { return cliutils.PrintHelpAndReturnError("The --format option can be sent only with the --scan option", c) } - scanOutputFormat, err := commandsUtils.GetXrayOutputFormat(format) + scanOutputFormat, err := outputFormat.GetOutputFormat(format) if err != nil { return err } @@ -433,7 +435,7 @@ func GradleCmd(c *cli.Context) (err error) { return err } - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Gradle) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Gradle) if err != nil { return err } @@ -445,7 +447,7 @@ func GradleCmd(c *cli.Context) (err error) { return cliutils.WrongNumberOfArgumentsHandler(c) } args := cliutils.ExtractCommand(c) - filteredGradleArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(args) + filteredGradleArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args) if err != nil { return err } @@ -468,7 +470,7 @@ func GradleCmd(c *cli.Context) (err error) { if !xrayScan && format != "" { return cliutils.PrintHelpAndReturnError("The --format option can be sent only with the --scan option", c) } - scanOutputFormat, err := commandsUtils.GetXrayOutputFormat(format) + scanOutputFormat, err := outputFormat.GetOutputFormat(format) if err != nil { return err } @@ -486,7 +488,7 @@ func YarnCmd(c *cli.Context) error { return err } - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Yarn) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Yarn) if err != nil { return err } @@ -505,7 +507,7 @@ func NugetCmd(c *cli.Context) error { if c.NArg() < 1 { return cliutils.WrongNumberOfArgumentsHandler(c) } - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Nuget) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Nuget) if err != nil { return err } @@ -519,7 +521,7 @@ func NugetCmd(c *cli.Context) error { return err } args := cliutils.ExtractCommand(c) - filteredNugetArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(args) + filteredNugetArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args) if err != nil { return err } @@ -545,7 +547,7 @@ func DotnetCmd(c *cli.Context) error { } // Get configuration file path. - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Dotnet) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Dotnet) if err != nil { return err } @@ -560,7 +562,7 @@ func DotnetCmd(c *cli.Context) error { args := cliutils.ExtractCommand(c) - filteredDotnetArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(args) + filteredDotnetArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args) if err != nil { return err } @@ -578,11 +580,11 @@ func DotnetCmd(c *cli.Context) error { } func getNugetAndDotnetConfigFields(configFilePath string) (rtDetails *coreConfig.ServerDetails, targetRepo string, useNugetV2 bool, err error) { - vConfig, err := utils.ReadConfigFile(configFilePath, utils.YAML) + vConfig, err := project.ReadConfigFile(configFilePath, project.YAML) if err != nil { return nil, "", false, fmt.Errorf("error occurred while attempting to read nuget-configuration file: %s", err.Error()) } - projectConfig, err := utils.GetRepoConfigByPrefix(configFilePath, utils.ProjectConfigResolverPrefix, vConfig) + projectConfig, err := project.GetRepoConfigByPrefix(configFilePath, project.ProjectConfigResolverPrefix, vConfig) if err != nil { return nil, "", false, err } @@ -591,7 +593,7 @@ func getNugetAndDotnetConfigFields(configFilePath string) (rtDetails *coreConfig return nil, "", false, err } targetRepo = projectConfig.TargetRepo() - useNugetV2 = vConfig.GetBool(utils.ProjectConfigResolverPrefix + "." + "nugetV2") + useNugetV2 = vConfig.GetBool(project.ProjectConfigResolverPrefix + "." + "nugetV2") return } @@ -651,7 +653,7 @@ func goCmdVerification(c *cli.Context) (string, error) { if c.NArg() < 1 { return "", cliutils.WrongNumberOfArgumentsHandler(c) } - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Go) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Go) if err != nil { return "", err } @@ -836,7 +838,7 @@ func NpmPublishCmd(c *cli.Context) (err error) { } func GetNpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) { - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Npm) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Npm) if err != nil { return "", nil, err } @@ -849,18 +851,18 @@ func GetNpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string, } func PipCmd(c *cli.Context) error { - return pythonCmd(c, utils.Pip) + return pythonCmd(c, project.Pip) } func PipenvCmd(c *cli.Context) error { - return pythonCmd(c, utils.Pipenv) + return pythonCmd(c, project.Pipenv) } func PoetryCmd(c *cli.Context) error { - return pythonCmd(c, utils.Poetry) + return pythonCmd(c, project.Poetry) } -func pythonCmd(c *cli.Context, projectType utils.ProjectType) error { +func pythonCmd(c *cli.Context, projectType project.ProjectType) error { if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil { return err } @@ -869,7 +871,7 @@ func pythonCmd(c *cli.Context, projectType utils.ProjectType) error { } // Get python configuration. - pythonConfig, err := utils.GetResolutionOnlyConfiguration(projectType) + pythonConfig, err := project.GetResolutionOnlyConfiguration(projectType) if err != nil { return fmt.Errorf("error occurred while attempting to read %[1]s-configuration file: %[2]s\n"+ "Please run 'jf %[1]s-config' command prior to running 'jf %[1]s'", projectType.String(), err.Error()) @@ -884,15 +886,15 @@ func pythonCmd(c *cli.Context, projectType utils.ProjectType) error { orgArgs := cliutils.ExtractCommand(c) cmdName, filteredArgs := getCommandName(orgArgs) switch projectType { - case utils.Pip: + case project.Pip: pythonCommand := python.NewPipCommand() pythonCommand.SetServerDetails(rtDetails).SetRepo(pythonConfig.TargetRepo()).SetCommandName(cmdName).SetArgs(filteredArgs) return commands.Exec(pythonCommand) - case utils.Pipenv: + case project.Pipenv: pythonCommand := python.NewPipenvCommand() pythonCommand.SetServerDetails(rtDetails).SetRepo(pythonConfig.TargetRepo()).SetCommandName(cmdName).SetArgs(filteredArgs) return commands.Exec(pythonCommand) - case utils.Poetry: + case project.Poetry: pythonCommand := python.NewPoetryCommand() pythonCommand.SetServerDetails(rtDetails).SetRepo(pythonConfig.TargetRepo()).SetCommandName(cmdName).SetArgs(filteredArgs) return commands.Exec(pythonCommand) @@ -919,7 +921,7 @@ func terraformCmd(c *cli.Context) error { } func getTerraformConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) { - configFilePath, exists, err := utils.GetProjectConfFilePath(utils.Terraform) + configFilePath, exists, err := project.GetProjectConfFilePath(project.Terraform) if err != nil { return "", nil, err } diff --git a/docker_test.go b/docker_test.go index 43b59e310..28a9b79e9 100644 --- a/docker_test.go +++ b/docker_test.go @@ -3,19 +3,21 @@ package main import ( "context" "fmt" - biutils "github.com/jfrog/build-info-go/utils" "os" "path" "path/filepath" "testing" "time" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/jfrog/build-info-go/entities" "github.com/jfrog/gofrog/version" coreContainer "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/container" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli/inttestutils" @@ -106,7 +108,7 @@ func TestContainerPushWithDetailedSummary(t *testing.T) { defer inttestutils.DeleteTestImage(t, imageTag, containerManager) // Testing detailed summary without build-info pushCommand := coreContainer.NewPushCommand(containerManager) - pushCommand.SetThreads(1).SetDetailedSummary(true).SetCmdParams([]string{"push", imageTag}).SetBuildConfiguration(new(utils.BuildConfiguration)).SetRepo(tests.DockerLocalRepo).SetServerDetails(serverDetails).SetImageTag(imageTag) + pushCommand.SetThreads(1).SetDetailedSummary(true).SetCmdParams([]string{"push", imageTag}).SetBuildConfiguration(new(build.BuildConfiguration)).SetRepo(tests.DockerLocalRepo).SetServerDetails(serverDetails).SetImageTag(imageTag) assert.NoError(t, pushCommand.Run()) result := pushCommand.Result() reader := result.Reader() @@ -116,7 +118,7 @@ func TestContainerPushWithDetailedSummary(t *testing.T) { assert.Equal(t, 64, len(transferDetails.Sha256), "Summary validation failed - invalid sha256 has returned from artifactory") } // Testing detailed summary with build-info - pushCommand.SetBuildConfiguration(utils.NewBuildConfiguration(tests.DockerBuildName, buildNumber, "", "")) + pushCommand.SetBuildConfiguration(build.NewBuildConfiguration(tests.DockerBuildName, buildNumber, "", "")) assert.NoError(t, pushCommand.Run()) anotherResult := pushCommand.Result() anotherReader := anotherResult.Reader() diff --git a/general/cisetup/cisetup.go b/general/cisetup/cisetup.go index 450c04ad5..07af9a7c1 100644 --- a/general/cisetup/cisetup.go +++ b/general/cisetup/cisetup.go @@ -18,7 +18,7 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/buildinfo" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/permissiontarget" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/usersmanagement" - rtutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/build" coreCommonCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/general/cisetup" repoutils "github.com/jfrog/jfrog-cli-core/v2/general/project" @@ -522,7 +522,7 @@ func (cc *CiSetupCommand) publishFirstBuild() (err error) { cc.data.BuildName = fmt.Sprintf("%s-%s", cc.data.RepositoryName, cc.data.GitBranch) // Run BAG Command (in order to publish the first, empty, build info) buildAddGitConfigurationCmd := buildinfo.NewBuildAddGitCommand().SetDotGitPath(cc.data.LocalDirPath).SetServerId(cisetup.ConfigServerId) - buildConfiguration := rtutils.NewBuildConfiguration(cc.data.BuildName, DefaultFirstBuildNumber, "", "") + buildConfiguration := build.NewBuildConfiguration(cc.data.BuildName, DefaultFirstBuildNumber, "", "") buildAddGitConfigurationCmd = buildAddGitConfigurationCmd.SetBuildConfiguration(buildConfiguration) log.Info("Generating an initial build-info...") err = coreCommonCommands.Exec(buildAddGitConfigurationCmd) diff --git a/go.mod b/go.mod index 156c3c372..c195963c1 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( // replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231224075754-92c93a2d086e -// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20231220105505-e62769dde9da +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5 // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231220102935-c8776c613ad8 diff --git a/go.sum b/go.sum index dcaa08531..83555e7b3 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,8 @@ github.com/jfrog/gofrog v1.4.0 h1:s7eysVnmIBfVheMs4LPU43MAlxwPa4K8u2N5h7kwzXA= github.com/jfrog/gofrog v1.4.0/go.mod h1:AQo5Fq0G9nDEF6icH7MYQK0iohR4HuEAXl8jaxRuT6Q= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= -github.com/jfrog/jfrog-cli-core/v2 v2.47.9 h1:3MoGn5M5hOzFZx42B3liuVm2GDmhdLeGfc3DQGsz5ZE= -github.com/jfrog/jfrog-cli-core/v2 v2.47.9/go.mod h1:l5y34dJhQ0W16o7OrCUjTQdGikoZPKTRI1NKGneoJ0g= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5 h1:/9SiDpqQ3zVsnzmxiQmYKNLyNdn6+y+EWK+lABEce9o= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5/go.mod h1:l5y34dJhQ0W16o7OrCUjTQdGikoZPKTRI1NKGneoJ0g= github.com/jfrog/jfrog-client-go v1.35.5 h1:1QlrXdMhGi099Cs3mVKIpeVre2w1DiYhU7WGSEH2gQU= github.com/jfrog/jfrog-client-go v1.35.5/go.mod h1:Leua+MdhCV+M4gl746PcTsHF8dDP7+LLJ/NgHCTl/Fo= github.com/jszwec/csvutil v1.8.0 h1:G7vS2LGdpZZDH1HmHeNbxOaJ/ZnJlpwGFvOkTkJzzNk= diff --git a/go_test.go b/go_test.go index 0d558121f..153892df6 100644 --- a/go_test.go +++ b/go_test.go @@ -2,18 +2,19 @@ package main import ( "fmt" - biutils "github.com/jfrog/build-info-go/utils" "os" "os/exec" "path/filepath" "testing" + biutils "github.com/jfrog/build-info-go/utils" + coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" buildinfo "github.com/jfrog/build-info-go/entities" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/golang" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli/inttestutils" @@ -156,12 +157,12 @@ func TestGoPublishWithDetailedSummary(t *testing.T) { // GoPublish with detailed summary without buildinfo. goPublishCmd := golang.NewGoPublishCommand() - goPublishCmd.SetConfigFilePath(filepath.Join(projectPath, ".jfrog", "projects", "go.yaml")).SetBuildConfiguration(new(utils.BuildConfiguration)).SetVersion("v1.0.0").SetDetailedSummary(true) + goPublishCmd.SetConfigFilePath(filepath.Join(projectPath, ".jfrog", "projects", "go.yaml")).SetBuildConfiguration(new(build.BuildConfiguration)).SetVersion("v1.0.0").SetDetailedSummary(true) assert.NoError(t, commands.Exec(goPublishCmd)) tests.VerifySha256DetailedSummaryFromResult(t, goPublishCmd.Result()) // GoPublish with buildinfo configuration - goPublishCmd.SetBuildConfiguration(utils.NewBuildConfiguration(tests.GoBuildName, buildNumber, ModuleNameJFrogTest, "")) + goPublishCmd.SetBuildConfiguration(build.NewBuildConfiguration(tests.GoBuildName, buildNumber, ModuleNameJFrogTest, "")) assert.NoError(t, commands.Exec(goPublishCmd)) tests.VerifySha256DetailedSummaryFromResult(t, goPublishCmd.Result()) diff --git a/gradle_test.go b/gradle_test.go index d651e9ecf..37cd28e42 100644 --- a/gradle_test.go +++ b/gradle_test.go @@ -10,7 +10,7 @@ import ( buildinfo "github.com/jfrog/build-info-go/entities" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/gradle" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/common/spec" @@ -112,7 +112,7 @@ func TestGradleBuildWithServerIDAndDetailedSummary(t *testing.T) { // Test gradle with detailed summary without buildinfo props. filteredGradleArgs := []string{"clean", "artifactoryPublish", "-b" + buildGradlePath} - gradleCmd := gradle.NewGradleCommand().SetConfiguration(new(utils.BuildConfiguration)).SetTasks(filteredGradleArgs).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true) + gradleCmd := gradle.NewGradleCommand().SetConfiguration(new(build.BuildConfiguration)).SetTasks(filteredGradleArgs).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true) assert.NoError(t, commands.Exec(gradleCmd)) // Validate sha256 assert.NotNil(t, gradleCmd.Result()) @@ -121,7 +121,7 @@ func TestGradleBuildWithServerIDAndDetailedSummary(t *testing.T) { } // Test gradle with detailed summary + buildinfo. - gradleCmd = gradle.NewGradleCommand().SetConfiguration(utils.NewBuildConfiguration(tests.GradleBuildName, buildNumber, "", "")).SetTasks(filteredGradleArgs).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true) + gradleCmd = gradle.NewGradleCommand().SetConfiguration(build.NewBuildConfiguration(tests.GradleBuildName, buildNumber, "", "")).SetTasks(filteredGradleArgs).SetConfigPath(filepath.Join(destPath, "gradle.yaml")).SetDetailedSummary(true) assert.NoError(t, commands.Exec(gradleCmd)) // Validate sha256 tests.VerifySha256DetailedSummaryFromResult(t, gradleCmd.Result()) diff --git a/inttestutils/buildinfo.go b/inttestutils/buildinfo.go index 3003172bf..bd4ad6a61 100644 --- a/inttestutils/buildinfo.go +++ b/inttestutils/buildinfo.go @@ -9,7 +9,7 @@ import ( buildinfo "github.com/jfrog/build-info-go/entities" "github.com/jfrog/jfrog-client-go/utils/errorutils" - coreutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + coreutils "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-client-go/http/httpclient" "github.com/jfrog/jfrog-client-go/utils" diff --git a/main_test.go b/main_test.go index 4d42e6107..ca2f51214 100644 --- a/main_test.go +++ b/main_test.go @@ -4,16 +4,22 @@ import ( "errors" "flag" "fmt" + "os" + "path/filepath" + "strconv" + "strings" + "testing" + buildinfo "github.com/jfrog/build-info-go/entities" commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" - artifactoryUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/format" + "github.com/jfrog/jfrog-cli-core/v2/common/project" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli-core/v2/utils/log" coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" - xrayutils "github.com/jfrog/jfrog-cli-core/v2/xray/utils" "github.com/jfrog/jfrog-cli/artifactory" "github.com/jfrog/jfrog-cli/inttestutils" "github.com/jfrog/jfrog-cli/utils/tests" @@ -23,11 +29,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/urfave/cli" "gopkg.in/yaml.v2" - "os" - "path/filepath" - "strconv" - "strings" - "testing" ) func TestMain(m *testing.M) { @@ -192,17 +193,17 @@ func initArtifactoryCli() { } } -func createConfigFileForTest(dirs []string, resolver, deployer string, t *testing.T, confType artifactoryUtils.ProjectType, global bool) error { +func createConfigFileForTest(dirs []string, resolver, deployer string, t *testing.T, confType project.ProjectType, global bool) error { var filePath string for _, atDir := range dirs { - d, err := yaml.Marshal(&commandUtils.ConfigFile{ + d, err := yaml.Marshal(&commands.ConfigFile{ Version: 1, ConfigType: confType.String(), - Resolver: artifactoryUtils.Repository{ + Resolver: project.Repository{ Repo: resolver, ServerId: "default", }, - Deployer: artifactoryUtils.Repository{ + Deployer: project.Repository{ Repo: deployer, ServerId: "default", }, @@ -278,14 +279,14 @@ func validateCmdAliasesUniqueness() { func testConditionalUpload(t *testing.T, execFunc func() error, searchSpec string, expectedDeployed ...string) { // Mock the scan function (failure) and verify the expected error returned. expectedErrMsg := "This error was expected" - commandUtils.ConditionalUploadScanFunc = func(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat xrayutils.OutputFormat) error { + commandUtils.ConditionalUploadScanFunc = func(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat format.OutputFormat) error { return errors.New(expectedErrMsg) } err := execFunc() assert.EqualError(t, err, expectedErrMsg) inttestutils.VerifyExistInArtifactory(nil, searchSpec, serverDetails, t) // Mock the scan function (success) and verify the expected artifacts deployed. - commandUtils.ConditionalUploadScanFunc = func(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat xrayutils.OutputFormat) error { + commandUtils.ConditionalUploadScanFunc = func(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat format.OutputFormat) error { return nil } err = execFunc() diff --git a/maven_test.go b/maven_test.go index d8c2cb783..7d3958ca1 100644 --- a/maven_test.go +++ b/maven_test.go @@ -11,7 +11,7 @@ import ( buildinfo "github.com/jfrog/build-info-go/entities" biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/mvn" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" @@ -49,10 +49,10 @@ func TestMavenBuildWithServerID(t *testing.T) { func TestMavenBuildWithNoProxy(t *testing.T) { initMavenTest(t, false) - setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, utils.HttpProxyEnvKey, "http://login:pass@proxy.mydomain:8888") + setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, buildUtils.HttpProxyEnvKey, "http://login:pass@proxy.mydomain:8888") defer setEnvCallBack() // Set noProxy to match all to skip http proxy configuration - setNoProxyEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, utils.NoProxyEnvKey, "*") + setNoProxyEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, buildUtils.NoProxyEnvKey, "*") defer setNoProxyEnvCallBack() assert.NoError(t, runMaven(t, createSimpleMavenProject, tests.MavenConfig, "install")) // Validate @@ -64,10 +64,10 @@ func TestMavenBuildWithNoProxy(t *testing.T) { func TestMavenBuildWithNoProxyHttps(t *testing.T) { initMavenTest(t, false) - setHttpsEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, utils.HttpsProxyEnvKey, "https://logins:passw@proxys.mydomains:8889") + setHttpsEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, buildUtils.HttpsProxyEnvKey, "https://logins:passw@proxys.mydomains:8889") defer setHttpsEnvCallBack() // Set noProxy to match all to skip https proxy configuration - setNoProxyEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, utils.NoProxyEnvKey, "*") + setNoProxyEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, buildUtils.NoProxyEnvKey, "*") defer setNoProxyEnvCallBack() assert.NoError(t, runMaven(t, createSimpleMavenProject, tests.MavenConfig, "install")) // Validate @@ -104,7 +104,7 @@ func TestMavenBuildWithServerIDAndDetailedSummary(t *testing.T) { defer clientTestUtils.ChangeDirAndAssert(t, oldHomeDir) repoLocalSystemProp := localRepoSystemProperty + localRepoDir filteredMavenArgs := []string{"clean", "install", "-B", repoLocalSystemProp} - mvnCmd := mvn.NewMvnCommand().SetConfiguration(new(utils.BuildConfiguration)).SetConfigPath(filepath.Join(destPath, tests.MavenConfig)).SetGoals(filteredMavenArgs).SetDetailedSummary(true) + mvnCmd := mvn.NewMvnCommand().SetConfiguration(new(buildUtils.BuildConfiguration)).SetConfigPath(filepath.Join(destPath, tests.MavenConfig)).SetGoals(filteredMavenArgs).SetDetailedSummary(true) assert.NoError(t, commands.Exec(mvnCmd)) // Validate assert.NotNil(t, mvnCmd.Result()) diff --git a/npm_test.go b/npm_test.go index 5222e4e03..55e6bc843 100644 --- a/npm_test.go +++ b/npm_test.go @@ -19,14 +19,15 @@ import ( clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" buildinfo "github.com/jfrog/build-info-go/entities" + "github.com/jfrog/jfrog-cli-core/v2/common/build" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/project" "github.com/jfrog/jfrog-cli-core/v2/common/spec" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/npm" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils" "github.com/jfrog/jfrog-cli/inttestutils" "github.com/jfrog/jfrog-cli/utils/tests" @@ -153,7 +154,7 @@ func TestNpmWithGlobalConfig(t *testing.T) { } func validateNpmLocalBuildInfo(t *testing.T, buildName, buildNumber, moduleName string) { - buildInfoService := utils.CreateBuildInfoService() + buildInfoService := build.CreateBuildInfoService() npmBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, "") assert.NoError(t, err) bi, err := npmBuild.ToBuildInfo() @@ -178,7 +179,7 @@ func TestNpmWithoutPackageJson(t *testing.T) { defer chdirCallback() // Run config to allow resolution from Artifactory - err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, "", t, utils.Npm, false) + err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, "", t, project.Npm, false) assert.NoError(t, err) // Run npm install and make sure that package.json and package-lock.json were created @@ -232,7 +233,7 @@ func initNpmFilesTest(t *testing.T) (npmProjectPath, npmScopedProjectPath, npmNp npmPostInstallProjectPath = createNpmProject(t, "npmpostinstall") _ = createNpmProject(t, filepath.Join("npmpostinstall", "subdir")) err := createConfigFileForTest([]string{filepath.Dir(npmProjectPath), filepath.Dir(npmScopedProjectPath), - filepath.Dir(npmNpmrcProjectPath), filepath.Dir(npmProjectCi), filepath.Dir(npmPostInstallProjectPath)}, tests.NpmRemoteRepo, tests.NpmRepo, t, utils.Npm, false) + filepath.Dir(npmNpmrcProjectPath), filepath.Dir(npmProjectCi), filepath.Dir(npmPostInstallProjectPath)}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false) assert.NoError(t, err) prepareArtifactoryForNpmBuild(t, filepath.Dir(npmProjectPath)) prepareArtifactoryForNpmBuild(t, filepath.Dir(npmProjectCi)) @@ -242,7 +243,7 @@ func initNpmFilesTest(t *testing.T) (npmProjectPath, npmScopedProjectPath, npmNp func initNpmProjectTest(t *testing.T) (npmProjectPath string) { npmProjectPath = filepath.Dir(createNpmProject(t, "npmproject")) - err := createConfigFileForTest([]string{npmProjectPath}, tests.NpmRemoteRepo, tests.NpmRepo, t, utils.Npm, false) + err := createConfigFileForTest([]string{npmProjectPath}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false) assert.NoError(t, err) prepareArtifactoryForNpmBuild(t, npmProjectPath) return @@ -252,7 +253,7 @@ func initGlobalNpmFilesTest(t *testing.T) (npmProjectPath string) { npmProjectPath = createNpmProject(t, "npmproject") jfrogHomeDir, err := coreutils.GetJfrogHomeDir() assert.NoError(t, err) - err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NpmRemoteRepo, tests.NpmRepo, t, utils.Npm, true) + err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, true) assert.NoError(t, err) prepareArtifactoryForNpmBuild(t, filepath.Dir(npmProjectPath)) return @@ -444,7 +445,7 @@ func TestNpmPackInstall(t *testing.T) { command := "npm i" testWorkingDir, err := filepath.Abs(createNpmProject(t, "npmnpmrcproject")) assert.NoError(t, err) - err = createConfigFileForTest([]string{filepath.Dir(testWorkingDir)}, tests.NpmRemoteRepo, tests.NpmRepo, t, utils.Npm, false) + err = createConfigFileForTest([]string{filepath.Dir(testWorkingDir)}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false) assert.NoError(t, err) clientTestUtils.ChangeDirAndAssert(t, filepath.Dir(testWorkingDir)) // Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory @@ -461,7 +462,7 @@ func TestNpmPackInstall(t *testing.T) { runJfrogCli(t, commandArgs...) // Validate that no dependencies were collected - buildInfoService := utils.CreateBuildInfoService() + buildInfoService := build.CreateBuildInfoService() npmBuild, err := buildInfoService.GetOrCreateBuild(tests.NpmBuildName, buildNumber) assert.NoError(t, err) defer func() { @@ -486,7 +487,7 @@ func TestYarn(t *testing.T) { assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil)) yarnProjectPath := filepath.Join(testDataTarget, "yarnproject") - assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, utils.Yarn, false)) + assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false)) wd, err := os.Getwd() assert.NoError(t, err, "Failed to get current dir") diff --git a/nuget_test.go b/nuget_test.go index 1f5f498b1..c8bf733d2 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -2,11 +2,17 @@ package main import ( "encoding/xml" + "os" + "path/filepath" + "strconv" + "strings" + "testing" + dotnetUtils "github.com/jfrog/build-info-go/build/utils/dotnet" buildInfo "github.com/jfrog/build-info-go/entities" biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/dotnet" - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/project" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" @@ -17,11 +23,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/exp/slices" - "os" - "path/filepath" - "strconv" - "strings" - "testing" ) func initNugetTest(t *testing.T) { @@ -51,7 +52,7 @@ func TestNugetResolve(t *testing.T) { {"multipackagesconfigsingleprojectdir", "multipackagesconfig", []string{dotnetUtils.Nuget.String(), "restore", "./proj2/", "-SolutionDirectory", "."}, []string{"proj2"}, []int{3}}, {"multipackagesconfigsingleprojectconfig", "multipackagesconfig", []string{dotnetUtils.Nuget.String(), "restore", "./proj1/packages.config", "-SolutionDirectory", "."}, []string{"proj1"}, []int{4}}, } - testNativeNugetDotnetResolve(t, uniqueNugetTests, tests.NuGetBuildName, utils.Nuget) + testNativeNugetDotnetResolve(t, uniqueNugetTests, tests.NuGetBuildName, project.Nuget) } func TestDotnetResolve(t *testing.T) { @@ -59,10 +60,10 @@ func TestDotnetResolve(t *testing.T) { {"dotnetargswithspaces", "multireference", []string{dotnetUtils.DotnetCore.String(), "restore", "src/multireference.proj1/", "--packages", "./packages dir with spaces"}, []string{"proj1"}, []int{5}}, {"multireferencesingleprojectdir", "multireference", []string{dotnetUtils.DotnetCore.String(), "restore", "src/multireference.proj1/"}, []string{"proj1"}, []int{5}}, } - testNativeNugetDotnetResolve(t, uniqueDotnetTests, tests.DotnetBuildName, utils.Dotnet) + testNativeNugetDotnetResolve(t, uniqueDotnetTests, tests.DotnetBuildName, project.Dotnet) } -func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, buildName string, projectType utils.ProjectType) { +func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, buildName string, projectType project.ProjectType) { initNugetTest(t) testDescriptors := append(slices.Clone(uniqueTests), []testDescriptor{ {"referencewithoutmodulechnage", "reference", []string{projectType.String(), "restore"}, []string{"reference"}, []int{6}}, @@ -104,7 +105,7 @@ func TestNuGetWithGlobalConfig(t *testing.T) { projectPath := createNugetProject(t, "packagesconfig") jfrogHomeDir, err := coreutils.GetJfrogHomeDir() assert.NoError(t, err) - err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, utils.Nuget, true) + err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}) diff --git a/scan/cli.go b/scan/cli.go index 371a93af8..43301312c 100644 --- a/scan/cli.go +++ b/scan/cli.go @@ -9,8 +9,8 @@ import ( "github.com/jfrog/jfrog-cli/utils/progressbar" - commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" "github.com/jfrog/jfrog-cli-core/v2/common/commands" + outputFormat "github.com/jfrog/jfrog-cli-core/v2/common/format" "github.com/jfrog/jfrog-cli-core/v2/common/spec" corecommondocs "github.com/jfrog/jfrog-cli-core/v2/docs/common" coreconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" @@ -219,7 +219,7 @@ func CurationCmd(c *cli.Context) error { if err != nil { return err } - format, err := commandsutils.GetCurationOutputFormat(c.String("format")) + format, err := curation.GetCurationOutputFormat(c.String("format")) if err != nil { return err } @@ -243,7 +243,7 @@ func createAuditCmd(c *cli.Context) (*audit.AuditCommand, error) { if err != nil { return nil, err } - format, err := commandsutils.GetXrayOutputFormat(c.String("format")) + format, err := outputFormat.GetOutputFormat(c.String("format")) if err != nil { return nil, err } @@ -308,7 +308,7 @@ func ScanCmd(c *cli.Context) error { if err != nil { return err } - format, err := commandsutils.GetXrayOutputFormat(c.String("format")) + format, err := outputFormat.GetOutputFormat(c.String("format")) if err != nil { return err } @@ -353,7 +353,7 @@ func BuildScan(c *cli.Context) error { if err != nil { return err } - format, err := commandsutils.GetXrayOutputFormat(c.String("format")) + format, err := outputFormat.GetOutputFormat(c.String("format")) if err != nil { return err } @@ -364,7 +364,7 @@ func BuildScan(c *cli.Context) error { SetOutputFormat(format). SetPrintExtendedTable(c.Bool(cliutils.ExtendedTable)). SetRescan(c.Bool("rescan")) - if format != xrutils.Sarif { + if format != outputFormat.Sarif { // Sarif shouldn't include the additional all-vulnerabilities info that received by adding the vuln flag buildScanCmd.SetIncludeVulnerabilities(c.Bool("vuln")) } @@ -387,7 +387,7 @@ func DockerScan(c *cli.Context, image string) error { return err } containerScanCommand := scan.NewDockerScanCommand() - format, err := commandsutils.GetXrayOutputFormat(c.String("format")) + format, err := outputFormat.GetOutputFormat(c.String("format")) if err != nil { return err } diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index e85374443..fe9b7f32e 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -18,7 +18,9 @@ import ( commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" artifactoryUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container" + buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build" coreCommonCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/project" speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec" coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" @@ -635,14 +637,14 @@ func fixWinPathBySource(path string, fromSpec bool) string { return path } -func CreateConfigCmd(c *cli.Context, confType artifactoryUtils.ProjectType) error { +func CreateConfigCmd(c *cli.Context, confType project.ProjectType) error { if c.NArg() != 0 { return WrongNumberOfArgumentsHandler(c) } - return commandUtils.CreateBuildConfig(c, confType) + return coreCommonCommands.CreateBuildConfig(c, confType) } -func RunNativeCmdWithDeprecationWarning(cmdName string, projectType artifactoryUtils.ProjectType, c *cli.Context, cmd func(c *cli.Context) error) error { +func RunNativeCmdWithDeprecationWarning(cmdName string, projectType project.ProjectType, c *cli.Context, cmd func(c *cli.Context) error) error { if shouldLogWarning() { LogNativeCommandDeprecation(cmdName, projectType.String()) } @@ -680,8 +682,8 @@ func NotSupportedNativeDockerCommand(oldCmdName string) error { %s rt %s `, corecontainercmds.MinRtVersionForRepoFetching, coreutils.GetCliExecutableName(), oldCmdName) } -func RunConfigCmdWithDeprecationWarning(cmdName, oldSubcommand string, confType artifactoryUtils.ProjectType, c *cli.Context, - cmd func(c *cli.Context, confType artifactoryUtils.ProjectType) error) error { +func RunConfigCmdWithDeprecationWarning(cmdName, oldSubcommand string, confType project.ProjectType, c *cli.Context, + cmd func(c *cli.Context, confType project.ProjectType) error) error { logNonNativeCommandDeprecation(cmdName, oldSubcommand) return cmd(c, confType) } @@ -724,8 +726,8 @@ func SetCliExecutableName(executablePath string) { // Returns build configuration struct using the args (build name/number) and options (project) provided by the user. // Any empty configuration could be later overridden by environment variables if set. -func CreateBuildConfiguration(c *cli.Context) *artifactoryUtils.BuildConfiguration { - buildConfiguration := new(artifactoryUtils.BuildConfiguration) +func CreateBuildConfiguration(c *cli.Context) *buildUtils.BuildConfiguration { + buildConfiguration := new(buildUtils.BuildConfiguration) buildNameArg, buildNumberArg := c.Args().Get(0), c.Args().Get(1) if buildNameArg == "" || buildNumberArg == "" { buildNameArg = "" @@ -737,8 +739,8 @@ func CreateBuildConfiguration(c *cli.Context) *artifactoryUtils.BuildConfigurati // Returns build configuration struct using the options provided by the user. // Any empty configuration could be later overridden by environment variables if set. -func CreateBuildConfigurationWithModule(c *cli.Context) (buildConfigConfiguration *artifactoryUtils.BuildConfiguration, err error) { - buildConfigConfiguration = new(artifactoryUtils.BuildConfiguration) +func CreateBuildConfigurationWithModule(c *cli.Context) (buildConfigConfiguration *buildUtils.BuildConfiguration, err error) { + buildConfigConfiguration = new(buildUtils.BuildConfiguration) err = buildConfigConfiguration.SetBuildName(c.String("build-name")).SetBuildNumber(c.String("build-number")). SetProject(c.String("project")).SetModule(c.String("module")).ValidateBuildAndModuleParams() return diff --git a/xray_test.go b/xray_test.go index e3c118e0a..0581b383c 100644 --- a/xray_test.go +++ b/xray_test.go @@ -5,8 +5,6 @@ import ( "errors" "flag" "fmt" - biutils "github.com/jfrog/build-info-go/utils" - "github.com/jfrog/jfrog-cli-core/v2/xray/scangraph" "net/http" "net/http/httptest" "os" @@ -19,15 +17,20 @@ import ( "testing" "time" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/jfrog/jfrog-cli-core/v2/xray/scangraph" + "github.com/jfrog/gofrog/version" coreContainer "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/container" - artCmdUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" - artUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container" + "github.com/jfrog/jfrog-cli-core/v2/common/build" coreCmd "github.com/jfrog/jfrog-cli-core/v2/common/commands" + "github.com/jfrog/jfrog-cli-core/v2/common/format" + "github.com/jfrog/jfrog-cli-core/v2/common/project" commontests "github.com/jfrog/jfrog-cli-core/v2/common/tests" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" + "github.com/jfrog/jfrog-cli-core/v2/utils/dependencies" coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" coreCuration "github.com/jfrog/jfrog-cli-core/v2/xray/commands/curation" "github.com/jfrog/jfrog-cli-core/v2/xray/commands/scan" @@ -105,26 +108,26 @@ func initXrayCli() { // Tests basic binary scan by providing pattern (path to testdata binaries) and --licenses flag // and asserts any error. func TestXrayBinaryScanJson(t *testing.T) { - output := testXrayBinaryScan(t, string(utils.Json)) + output := testXrayBinaryScan(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) } func TestXrayBinaryScanSimpleJson(t *testing.T) { - output := testXrayBinaryScan(t, string(utils.SimpleJson)) + output := testXrayBinaryScan(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) } func TestXrayBinaryScanJsonWithProgress(t *testing.T) { callback := tests.MockProgressInitialization() defer callback() - output := testXrayBinaryScan(t, string(utils.Json)) + output := testXrayBinaryScan(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) } func TestXrayBinaryScanSimpleJsonWithProgress(t *testing.T) { callback := tests.MockProgressInitialization() defer callback() - output := testXrayBinaryScan(t, string(utils.SimpleJson)) + output := testXrayBinaryScan(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) } @@ -153,12 +156,12 @@ func TestXrayBinaryScanWithBypassArchiveLimits(t *testing.T) { // Tests npm audit by providing simple npm project and asserts any error. func TestXrayAuditNpmJson(t *testing.T) { - output := testXrayAuditNpm(t, string(utils.Json)) + output := testXrayAuditNpm(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) } func TestXrayAuditNpmSimpleJson(t *testing.T) { - output := testXrayAuditNpm(t, string(utils.SimpleJson)) + output := testXrayAuditNpm(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) } @@ -180,21 +183,21 @@ func testXrayAuditNpm(t *testing.T, format string) string { func TestXrayAuditYarnV2Json(t *testing.T) { testXrayAuditYarn(t, "yarn-v2", func() { - output := runXrayAuditYarnWithOutput(t, string(utils.Json)) + output := runXrayAuditYarnWithOutput(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) }) } func TestXrayAuditYarnV2SimpleJson(t *testing.T) { testXrayAuditYarn(t, "yarn-v2", func() { - output := runXrayAuditYarnWithOutput(t, string(utils.SimpleJson)) + output := runXrayAuditYarnWithOutput(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) }) } func TestXrayAuditYarnV1Json(t *testing.T) { testXrayAuditYarn(t, "yarn-v1", func() { - output := runXrayAuditYarnWithOutput(t, string(utils.Json)) + output := runXrayAuditYarnWithOutput(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) }) } @@ -203,7 +206,7 @@ func TestXrayAuditYarnV1JsonWithoutDevDependencies(t *testing.T) { unsetEnv := clientTestUtils.SetEnvWithCallbackAndAssert(t, "NODE_ENV", "production") defer unsetEnv() testXrayAuditYarn(t, "yarn-v1", func() { - output := runXrayAuditYarnWithOutput(t, string(utils.Json)) + output := runXrayAuditYarnWithOutput(t, string(format.Json)) var results []services.ScanResponse err := json.Unmarshal([]byte(output), &results) assert.NoError(t, err) @@ -213,7 +216,7 @@ func TestXrayAuditYarnV1JsonWithoutDevDependencies(t *testing.T) { func TestXrayAuditYarnV1SimpleJson(t *testing.T) { testXrayAuditYarn(t, "yarn-v1", func() { - output := runXrayAuditYarnWithOutput(t, string(utils.SimpleJson)) + output := runXrayAuditYarnWithOutput(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) }) } @@ -249,35 +252,35 @@ func TestXrayAuditNugetJson(t *testing.T) { }{ { projectName: "single4.0", - format: string(utils.Json), + format: string(format.Json), restoreTech: "nuget", minVulnerabilities: 2, minLicences: 0, }, { projectName: "single5.0", - format: string(utils.Json), + format: string(format.Json), restoreTech: "dotnet", minVulnerabilities: 3, minLicences: 2, }, { projectName: "single5.0", - format: string(utils.Json), + format: string(format.Json), restoreTech: "", minVulnerabilities: 3, minLicences: 2, }, { projectName: "multi", - format: string(utils.Json), + format: string(format.Json), restoreTech: "dotnet", minVulnerabilities: 4, minLicences: 3, }, { projectName: "multi", - format: string(utils.Json), + format: string(format.Json), restoreTech: "", minVulnerabilities: 4, minLicences: 3, @@ -303,21 +306,21 @@ func TestXrayAuditNugetSimpleJson(t *testing.T) { }{ { projectName: "single4.0", - format: string(utils.SimpleJson), + format: string(format.SimpleJson), restoreTech: "nuget", minVulnerabilities: 2, minLicences: 0, }, { projectName: "single5.0", - format: string(utils.SimpleJson), + format: string(format.SimpleJson), restoreTech: "dotnet", minVulnerabilities: 3, minLicences: 2, }, { projectName: "single5.0", - format: string(utils.SimpleJson), + format: string(format.SimpleJson), restoreTech: "", minVulnerabilities: 3, minLicences: 2, @@ -353,12 +356,12 @@ func testXrayAuditNuget(t *testing.T, projectName, format string, restoreTech st } func TestXrayAuditGradleJson(t *testing.T) { - output := testXrayAuditGradle(t, string(utils.Json)) + output := testXrayAuditGradle(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 3, 3) } func TestXrayAuditGradleSimpleJson(t *testing.T) { - output := testXrayAuditGradle(t, string(utils.SimpleJson)) + output := testXrayAuditGradle(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 3, 3) } @@ -377,12 +380,12 @@ func testXrayAuditGradle(t *testing.T, format string) string { } func TestXrayAuditMavenJson(t *testing.T) { - output := testXrayAuditMaven(t, string(utils.Json)) + output := testXrayAuditMaven(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 1, 1) } func TestXrayAuditMavenSimpleJson(t *testing.T) { - output := testXrayAuditMaven(t, string(utils.SimpleJson)) + output := testXrayAuditMaven(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 1, 1) } @@ -421,7 +424,7 @@ func TestXrayAuditDetectTech(t *testing.T) { prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Run generic audit on mvn project with a vulnerable dependency - output := xrayCli.RunCliCmdWithOutput(t, "audit", "--licenses", "--format="+string(utils.SimpleJson)) + output := xrayCli.RunCliCmdWithOutput(t, "audit", "--licenses", "--format="+string(format.SimpleJson)) var results formats.SimpleJsonResults err := json.Unmarshal([]byte(output), &results) assert.NoError(t, err) @@ -444,28 +447,28 @@ func TestXrayAuditMultiProjects(t *testing.T) { // Configure a new server named "default" createJfrogHomeConfig(t, true) defer cleanTestsHomeEnv() - output := xrayCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+string(utils.SimpleJson), workingDirsFlag) + output := xrayCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+string(format.SimpleJson), workingDirsFlag) verifySimpleJsonScanResults(t, output, 35, 0) verifySimpleJsonJasResults(t, output, 1, 9, 7, 3) } func TestXrayAuditPipJson(t *testing.T) { - output := testXrayAuditPip(t, string(utils.Json), "") + output := testXrayAuditPip(t, string(format.Json), "") verifyJsonScanResults(t, output, 0, 3, 1) } func TestXrayAuditPipSimpleJson(t *testing.T) { - output := testXrayAuditPip(t, string(utils.SimpleJson), "") + output := testXrayAuditPip(t, string(format.SimpleJson), "") verifySimpleJsonScanResults(t, output, 3, 1) } func TestXrayAuditPipJsonWithRequirementsFile(t *testing.T) { - output := testXrayAuditPip(t, string(utils.Json), "requirements.txt") + output := testXrayAuditPip(t, string(format.Json), "requirements.txt") verifyJsonScanResults(t, output, 0, 2, 0) } func TestXrayAuditPipSimpleJsonWithRequirementsFile(t *testing.T) { - output := testXrayAuditPip(t, string(utils.SimpleJson), "requirements.txt") + output := testXrayAuditPip(t, string(format.SimpleJson), "requirements.txt") verifySimpleJsonScanResults(t, output, 2, 0) } @@ -489,12 +492,12 @@ func testXrayAuditPip(t *testing.T, format, requirementsFile string) string { } func TestXrayAuditPipenvJson(t *testing.T) { - output := testXrayAuditPipenv(t, string(utils.Json)) + output := testXrayAuditPipenv(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 3, 1) } func TestXrayAuditPipenvSimpleJson(t *testing.T) { - output := testXrayAuditPipenv(t, string(utils.SimpleJson)) + output := testXrayAuditPipenv(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 3, 1) } @@ -522,7 +525,7 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) { defer setEnvCallBack() // Download - err := artUtils.DownloadAnalyzerManagerIfNeeded() + err := dependencies.DownloadAnalyzerManagerIfNeeded() assert.NoError(t, err) // Validate Analyzer manager app & checksum.sh2 file exist @@ -532,7 +535,7 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) { exists, err := fileutils.IsFileExists(amPath, false) assert.NoError(t, err) assert.True(t, exists) - checksumPath := filepath.Join(path, artUtils.ChecksumFileName) + checksumPath := filepath.Join(path, dependencies.ChecksumFileName) exists, err = fileutils.IsFileExists(checksumPath, false) assert.NoError(t, err) assert.True(t, exists) @@ -543,7 +546,7 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) { // Validate no second download occurred firstFileStat, err := os.Stat(amPath) assert.NoError(t, err) - err = artUtils.DownloadAnalyzerManagerIfNeeded() + err = dependencies.DownloadAnalyzerManagerIfNeeded() assert.NoError(t, err) secondFileStat, err := os.Stat(amPath) assert.NoError(t, err) @@ -551,12 +554,12 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) { } func TestXrayAuditPoetryJson(t *testing.T) { - output := testXrayAuditPoetry(t, string(utils.Json)) + output := testXrayAuditPoetry(t, string(format.Json)) verifyJsonScanResults(t, output, 0, 3, 1) } func TestXrayAuditPoetrySimpleJson(t *testing.T) { - output := testXrayAuditPoetry(t, string(utils.SimpleJson)) + output := testXrayAuditPoetry(t, string(format.SimpleJson)) verifySimpleJsonScanResults(t, output, 3, 1) } @@ -701,7 +704,7 @@ func runDockerScan(t *testing.T, imageName, watchName string, minViolations, min // Pull image from docker repo imageTag := path.Join(*tests.ContainerRegistry, tests.DockerVirtualRepo, imageName) dockerPullCommand := coreContainer.NewPullCommand(container.DockerClient) - dockerPullCommand.SetCmdParams([]string{"pull", imageTag}).SetImageTag(imageTag).SetRepo(tests.DockerVirtualRepo).SetServerDetails(serverDetails).SetBuildConfiguration(new(artUtils.BuildConfiguration)) + dockerPullCommand.SetCmdParams([]string{"pull", imageTag}).SetImageTag(imageTag).SetRepo(tests.DockerVirtualRepo).SetServerDetails(serverDetails).SetBuildConfiguration(new(build.BuildConfiguration)) if assert.NoError(t, dockerPullCommand.Run()) { defer inttestutils.DeleteTestImage(t, imageTag, container.DockerClient) @@ -778,17 +781,17 @@ func TestXrayOfflineDBSyncV3(t *testing.T) { } func TestXrayAuditJasSimpleJson(t *testing.T) { - output := testXrayAuditJas(t, string(utils.SimpleJson), "jas-test") + output := testXrayAuditJas(t, string(format.SimpleJson), "jas-test") verifySimpleJsonJasResults(t, output, 1, 9, 7, 2) } func TestXrayAuditJasSimpleJsonWithConfig(t *testing.T) { - output := testXrayAuditJas(t, string(utils.SimpleJson), "jas-config") + output := testXrayAuditJas(t, string(format.SimpleJson), "jas-config") verifySimpleJsonJasResults(t, output, 0, 0, 1, 2) } func TestXrayAuditJasNoViolationsSimpleJson(t *testing.T) { - output := testXrayAuditJas(t, string(utils.SimpleJson), "npm") + output := testXrayAuditJas(t, string(format.SimpleJson), "npm") verifySimpleJsonScanResults(t, output, 1, 0) verifySimpleJsonJasResults(t, output, 0, 0, 0, 0) } @@ -868,12 +871,12 @@ func TestCurationAudit(t *testing.T) { resolutionRepo := "repo-resolve" deploymentRepo := "repo-deploy" context := createContext(t, resolutionServerId+"="+config.ServerId, resolutionRepo+"=npms", deploymentServerId+"="+config.ServerId, deploymentRepo+"=npm-local", "global=false") - err = artCmdUtils.CreateBuildConfig(context, artUtils.Npm) + err = coreCmd.CreateBuildConfig(context, project.Npm) assert.NoError(t, err) localXrayCli := xrayCli.WithoutCredentials() workingDirsFlag := fmt.Sprintf("--working-dirs=%s", filepath.Join(tempDirPath, "npm")) - output := localXrayCli.RunCliCmdWithOutput(t, "curation-audit", "--format="+string(utils.Json), workingDirsFlag) + output := localXrayCli.RunCliCmdWithOutput(t, "curation-audit", "--format="+string(format.Json), workingDirsFlag) expectedResp := getCurationExpectedResponse(config) var got []coreCuration.PackageStatus bracketIndex := strings.Index(output, "[") @@ -975,61 +978,61 @@ func TestDependencyResolutionFromArtifactory(t *testing.T) { testProjectPath []string resolveRepoName string cacheRepoName string - projectType artUtils.ProjectType + projectType project.ProjectType }{ { testProjectPath: []string{"npm", "npmproject"}, resolveRepoName: tests.NpmRemoteRepo, cacheRepoName: tests.NpmRemoteRepo, - projectType: artUtils.Npm, + projectType: project.Npm, }, { testProjectPath: []string{"nuget", "simple-dotnet"}, resolveRepoName: tests.NugetRemoteRepo, cacheRepoName: tests.NugetRemoteRepo, - projectType: artUtils.Dotnet, + projectType: project.Dotnet, }, { testProjectPath: []string{"yarn", "yarnproject"}, resolveRepoName: tests.YarnRemoteRepo, cacheRepoName: tests.YarnRemoteRepo, - projectType: artUtils.Yarn, + projectType: project.Yarn, }, { testProjectPath: []string{"gradle", "gradleproject"}, resolveRepoName: tests.GradleRemoteRepo, cacheRepoName: tests.GradleRemoteRepo, - projectType: artUtils.Gradle, + projectType: project.Gradle, }, { testProjectPath: []string{"maven", "mavenproject"}, resolveRepoName: tests.MvnRemoteRepo, cacheRepoName: tests.MvnRemoteRepo, - projectType: artUtils.Maven, + projectType: project.Maven, }, { testProjectPath: []string{"go", "simple-project"}, resolveRepoName: tests.GoVirtualRepo, cacheRepoName: tests.GoRemoteRepo, - projectType: artUtils.Go, + projectType: project.Go, }, { testProjectPath: []string{"pipenv", "pipenvproject"}, resolveRepoName: tests.PypiRemoteRepo, cacheRepoName: tests.PypiRemoteRepo, - projectType: artUtils.Pipenv, + projectType: project.Pipenv, }, { testProjectPath: []string{"pip", "setuppyproject"}, resolveRepoName: tests.PypiRemoteRepo, cacheRepoName: tests.PypiRemoteRepo, - projectType: artUtils.Pip, + projectType: project.Pip, }, { testProjectPath: []string{"poetry", "projecttomlproject"}, resolveRepoName: tests.PypiRemoteRepo, cacheRepoName: tests.PypiRemoteRepo, - projectType: artUtils.Poetry, + projectType: project.Poetry, }, } createJfrogHomeConfig(t, true) @@ -1042,7 +1045,7 @@ func TestDependencyResolutionFromArtifactory(t *testing.T) { } } -func testSingleTechDependencyResolution(t *testing.T, testProjectPartialPath []string, resolveRepoName string, cacheRepoName string, projectType artUtils.ProjectType) { +func testSingleTechDependencyResolution(t *testing.T, testProjectPartialPath []string, resolveRepoName string, cacheRepoName string, projectType project.ProjectType) { tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() testProjectPath := filepath.Join(append([]string{filepath.FromSlash(tests.GetTestResourcesPath())}, testProjectPartialPath...)...) @@ -1065,7 +1068,7 @@ func testSingleTechDependencyResolution(t *testing.T, testProjectPartialPath []s assert.NoError(t, configCmd.Run()) context := createContext(t, "repo-resolve="+resolveRepoName, "server-id-resolve="+server.ServerId) - err = artCmdUtils.CreateBuildConfig(context, projectType) + err = coreCmd.CreateBuildConfig(context, projectType) assert.NoError(t, err) artifactoryPathToSearch := cacheRepoName + "-cache/*" @@ -1089,19 +1092,19 @@ func testSingleTechDependencyResolution(t *testing.T, testProjectPartialPath []s } // To guarantee that dependencies are resolved from Artifactory, certain package managers may need their local cache to be cleared. -func clearOrRedirectLocalCacheIfNeeded(t *testing.T, projectType artUtils.ProjectType) (callbackFunc func()) { +func clearOrRedirectLocalCacheIfNeeded(t *testing.T, projectType project.ProjectType) (callbackFunc func()) { switch projectType { - case artUtils.Dotnet: + case project.Dotnet: _, err := exec.Command("dotnet", "nuget", "locals", "all", "--clear").CombinedOutput() assert.NoError(t, err) - case artUtils.Maven: + case project.Maven: mavenCacheTempPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) envVarCallbackFunc := clientTestUtils.SetEnvWithCallbackAndAssert(t, jvmLaunchEnvVar, mavenCacheRedirectionVal+mavenCacheTempPath) callbackFunc = func() { envVarCallbackFunc() createTempDirCallback() } - case artUtils.Go: + case project.Go: goTempCachePath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) envVarCallbackFunc := clientTestUtils.SetEnvWithCallbackAndAssert(t, goCacheEnvVar, goTempCachePath) @@ -1111,7 +1114,7 @@ func clearOrRedirectLocalCacheIfNeeded(t *testing.T, projectType artUtils.Projec assert.NoError(t, coreutils.SetPermissionsRecursively(goTempCachePath, 0755)) createTempDirCallback() } - case artUtils.Pip: + case project.Pip: pipTempCachePath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) envVarCallbackFunc := clientTestUtils.SetEnvWithCallbackAndAssert(t, pipCacheEnvVar, pipTempCachePath) callbackFunc = func() { From 86342fe81fccafcb1287f0150da7d744b09fb420 Mon Sep 17 00:00:00 2001 From: Yahav Itzhak Date: Thu, 4 Jan 2024 12:14:14 +0200 Subject: [PATCH 2/6] Transfer - Use tmp dir under user home (#2394) --- go.mod | 4 ++-- go.sum | 4 ++-- transfer_test.go | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index c195963c1..6d6e02fcc 100644 --- a/go.mod +++ b/go.mod @@ -130,9 +130,9 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231224075754-92c93a2d086e +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5 +// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20231220105505-e62769dde9da // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231220102935-c8776c613ad8 diff --git a/go.sum b/go.sum index 83555e7b3..315f201c1 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,8 @@ github.com/jfrog/gofrog v1.4.0 h1:s7eysVnmIBfVheMs4LPU43MAlxwPa4K8u2N5h7kwzXA= github.com/jfrog/gofrog v1.4.0/go.mod h1:AQo5Fq0G9nDEF6icH7MYQK0iohR4HuEAXl8jaxRuT6Q= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5 h1:/9SiDpqQ3zVsnzmxiQmYKNLyNdn6+y+EWK+lABEce9o= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240103100500-8e451d1cd6d5/go.mod h1:l5y34dJhQ0W16o7OrCUjTQdGikoZPKTRI1NKGneoJ0g= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d h1:sdJ18v0Fk01Wsd3ej0etMBfAIgweZA8YoYj64pZXp/c= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d/go.mod h1:l5y34dJhQ0W16o7OrCUjTQdGikoZPKTRI1NKGneoJ0g= github.com/jfrog/jfrog-client-go v1.35.5 h1:1QlrXdMhGi099Cs3mVKIpeVre2w1DiYhU7WGSEH2gQU= github.com/jfrog/jfrog-client-go v1.35.5/go.mod h1:Leua+MdhCV+M4gl746PcTsHF8dDP7+LLJ/NgHCTl/Fo= github.com/jszwec/csvutil v1.8.0 h1:G7vS2LGdpZZDH1HmHeNbxOaJ/ZnJlpwGFvOkTkJzzNk= diff --git a/transfer_test.go b/transfer_test.go index 90bed37eb..943476aa5 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -298,17 +298,18 @@ func TestUnsupportedRunStatusVersion(t *testing.T) { defer cleanUp() // Create run status file with lower version. - transferDir, err := coreutils.GetJfrogTransferDir() - assert.NoError(t, err) + transferDir, actualError := coreutils.GetJfrogTransferDir() + assert.NoError(t, actualError) assert.NoError(t, os.MkdirAll(transferDir, 0777)) statusFilePath := filepath.Join(transferDir, coreutils.JfrogTransferRunStatusFileName) trs := state.TransferRunStatus{Version: 0} - content, err := json.Marshal(trs) - assert.NoError(t, err) + content, actualError := json.Marshal(trs) + assert.NoError(t, actualError) assert.NoError(t, os.WriteFile(statusFilePath, content, 0600)) - err = artifactoryCli.WithoutCredentials().Exec("transfer-files", inttestutils.SourceServerId, inttestutils.TargetServerId, "--include-repos="+tests.RtRepo1+";"+tests.RtRepo2) - assert.Equal(t, err, state.GetOldTransferDirectoryStructureError()) + expectedError := state.GetOldTransferDirectoryStructureError() + actualError = artifactoryCli.WithoutCredentials().Exec("transfer-files", inttestutils.SourceServerId, inttestutils.TargetServerId, "--include-repos="+tests.RtRepo1+";"+tests.RtRepo2) + assert.ErrorAs(t, expectedError, &actualError) } func TestTransferWithRepoSnapshot(t *testing.T) { From 000913bb9d56da1e6b60f61a8c8184d1325237c1 Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Thu, 4 Jan 2024 16:14:10 +0200 Subject: [PATCH 3/6] Simplify Jenkinsfile (#2393) --- Jenkinsfile | 114 +++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 825895a0d..ad0f079c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,15 +55,13 @@ node("docker") { } stage('synchronize branches') { - if ("$EXECUTION_MODE".toString().equals("Build CLI")) { - masterBranch = 'v2' - devBranch = 'dev' - if (BRANCH?.trim() == 'v1') { - masterBranch = 'v1' - devBranch = 'dev-v1' - } - synchronizeBranches(masterBranch, devBranch) + masterBranch = 'v2' + devBranch = 'dev' + if (BRANCH?.trim() == 'v1') { + masterBranch = 'v1' + devBranch = 'dev-v1' } + synchronizeBranches(masterBranch, devBranch) } stage('install npm') { @@ -104,64 +102,62 @@ def runRelease(architectures) { configRepo21() try { - if ("$EXECUTION_MODE".toString().equals("Publish packages")) { - stage('Docker login') { - dockerLogin() - } - - stage('Build and publish rpm and debian') { - buildRpmAndDeb(version, architectures) - } - - stage('Npm publish') { - publishNpmPackage(jfrogCliRepoDir) - } - - stage('Build and publish docker images') { - buildPublishDockerImages(version, jfrogCliRepoDir) - } - - // Download cert files, to be used for signing the Windows executable, packaged by Chocolatey. - downloadToolsCert() - stage('Build and publish Chocolatey') { - publishChocoPackageWithRetries(version, jfrogCliRepoDir, architectures) - } - } else if ("$EXECUTION_MODE".toString().equals("Build CLI")) { - validateReleaseVersion() - if (identifier != "v2") { - stage("Audit") { - dir("$jfrogCliRepoDir") { - sh """#!/bin/bash - ../$builderPath audit --fail=false - """ - } + validateReleaseVersion() + if (identifier != "v2") { + stage("Audit") { + dir("$jfrogCliRepoDir") { + sh """#!/bin/bash + ../$builderPath audit --fail=false + """ } } + } - downloadToolsCert() - print "Uploading version $version to Repo21" - uploadCli(architectures) - stage("Distribute executables") { - distributeToReleases("ecosystem-jfrog-cli", version, "cli-rbc-spec.json") - } - stage("Publish latest scripts") { - withCredentials([string(credentialsId: 'jfrog-cli-automation', variable: 'JFROG_CLI_AUTOMATION_ACCESS_TOKEN')]) { - options = "--url https://releases.jfrog.io/artifactory --access-token=$JFROG_CLI_AUTOMATION_ACCESS_TOKEN" + downloadToolsCert() + print "Uploading version $version to Repo21" + uploadCli(architectures) + stage("Distribute executables") { + distributeToReleases("ecosystem-jfrog-cli", version, "cli-rbc-spec.json") + } + stage("Publish latest scripts") { + withCredentials([string(credentialsId: 'jfrog-cli-automation', variable: 'JFROG_CLI_AUTOMATION_ACCESS_TOKEN')]) { + options = "--url https://releases.jfrog.io/artifactory --access-token=$JFROG_CLI_AUTOMATION_ACCESS_TOKEN" + sh """#!/bin/bash + $builderPath rt cp jfrog-cli/$identifier/$version/scripts/getCli.sh jfrog-cli/$identifier/scripts/ --flat $options --fail-no-op + $builderPath rt cp jfrog-cli/$identifier/$version/scripts/install-cli.sh jfrog-cli/$identifier/scripts/ --flat $options --fail-no-op + """ + if (identifier == "v2-jf") { sh """#!/bin/bash - $builderPath rt cp jfrog-cli/$identifier/$version/scripts/getCli.sh jfrog-cli/$identifier/scripts/ --flat $options --fail-no-op - $builderPath rt cp jfrog-cli/$identifier/$version/scripts/install-cli.sh jfrog-cli/$identifier/scripts/ --flat $options --fail-no-op + $builderPath rt cp jfrog-cli/$identifier/$version/scripts/setup-cli.sh jfrog-cli/setup/scripts/getCli.sh --flat $options --fail-no-op + $builderPath rt cp "jfrog-cli/$identifier/$version/scripts/gitlab/(*)" "jfrog-cli/gitlab/{1}" $options --fail-no-op """ - if (identifier == "v2-jf") { - sh """#!/bin/bash - $builderPath rt cp jfrog-cli/$identifier/$version/scripts/setup-cli.sh jfrog-cli/setup/scripts/getCli.sh --flat $options --fail-no-op - $builderPath rt cp "jfrog-cli/$identifier/$version/scripts/gitlab/(*)" "jfrog-cli/gitlab/{1}" $options --fail-no-op - """ - } } } - if (identifier == "v2") { - createTag() - } + } + if (identifier == "v2") { + createTag() + } + + stage('Docker login') { + dockerLogin() + } + + stage('Build and publish rpm and debian') { + buildRpmAndDeb(version, architectures) + } + + stage('Npm publish') { + publishNpmPackage(jfrogCliRepoDir) + } + + stage('Build and publish docker images') { + buildPublishDockerImages(version, jfrogCliRepoDir) + } + + // Download cert files, to be used for signing the Windows executable, packaged by Chocolatey. + downloadToolsCert() + stage('Build and publish Chocolatey') { + publishChocoPackageWithRetries(version, jfrogCliRepoDir, architectures) } } finally { cleanupRepo21() From 3f8af3ea0050d59d872b7306cbdaa45a4b0d8b94 Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Sun, 7 Jan 2024 18:01:09 +0200 Subject: [PATCH 4/6] Upgrade depedencies (#2401) --- go.mod | 11 ++++++----- go.sum | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 6d6e02fcc..bdcf6cde4 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ require ( github.com/buger/jsonparser v1.1.1 github.com/go-git/go-git/v5 v5.11.0 github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a - github.com/jfrog/build-info-go v1.9.19 - github.com/jfrog/gofrog v1.4.0 - github.com/jfrog/jfrog-cli-core/v2 v2.47.9 - github.com/jfrog/jfrog-client-go v1.35.5 + github.com/jfrog/build-info-go v1.9.20 + github.com/jfrog/gofrog v1.4.1 + github.com/jfrog/jfrog-cli-core/v2 v2.47.10 + github.com/jfrog/jfrog-client-go v1.35.6 github.com/jszwec/csvutil v1.8.0 github.com/mholt/archiver/v3 v3.5.1 github.com/stretchr/testify v1.8.4 @@ -65,6 +65,7 @@ require ( github.com/gookit/color v1.5.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jfrog/archiver/v3 v3.5.3 // indirect github.com/jfrog/jfrog-apps-config v1.0.1 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/klauspost/compress v1.17.0 // indirect @@ -130,7 +131,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d +// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20231220105505-e62769dde9da diff --git a/go.sum b/go.sum index 315f201c1..fbf201b69 100644 --- a/go.sum +++ b/go.sum @@ -130,16 +130,18 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty/v6 v6.4.0 h1:YlI/2zYDrweA4MThiYMKtGRfT+2qZOO65ulej8GTcVI= github.com/jedib0t/go-pretty/v6 v6.4.0/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI= -github.com/jfrog/build-info-go v1.9.19 h1:tFPR0Je+ETLXcJqa7UrICkSjwc27zeY06AoWaMYPdQI= -github.com/jfrog/build-info-go v1.9.19/go.mod h1:DBxqvz1N/uI9iI/1gkCfjKjOrlcCzQ3hiKXqtKJUrrY= -github.com/jfrog/gofrog v1.4.0 h1:s7eysVnmIBfVheMs4LPU43MAlxwPa4K8u2N5h7kwzXA= -github.com/jfrog/gofrog v1.4.0/go.mod h1:AQo5Fq0G9nDEF6icH7MYQK0iohR4HuEAXl8jaxRuT6Q= +github.com/jfrog/archiver/v3 v3.5.3 h1:Udz6+z/YIhTFmcEp1TeW2DEwNyo7JSAnrGUsrbL2FZI= +github.com/jfrog/archiver/v3 v3.5.3/go.mod h1:/MbmBhPzkliu9PtweAg9lCYHGcKdapwMMZS/QS09T5c= +github.com/jfrog/build-info-go v1.9.20 h1:tQF6EMjt/EEX8syTrgpL/c7FjhlBSjtv848jNvxpMp8= +github.com/jfrog/build-info-go v1.9.20/go.mod h1:Vxv6zmx4e1NWsx40OHaDWCCYDeYAq2yXzpJ4nsDChbE= +github.com/jfrog/gofrog v1.4.1 h1:jz4kXBdsvVCNRDVkGLRiZIQ+uTO6/DSxQ9LjfvmLfoY= +github.com/jfrog/gofrog v1.4.1/go.mod h1:wQqagqq2VpuCWRPlq/65GbH9gsRz+7Bgc1Q+PKD4Y+k= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d h1:sdJ18v0Fk01Wsd3ej0etMBfAIgweZA8YoYj64pZXp/c= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240104095135-8e243b03531d/go.mod h1:l5y34dJhQ0W16o7OrCUjTQdGikoZPKTRI1NKGneoJ0g= -github.com/jfrog/jfrog-client-go v1.35.5 h1:1QlrXdMhGi099Cs3mVKIpeVre2w1DiYhU7WGSEH2gQU= -github.com/jfrog/jfrog-client-go v1.35.5/go.mod h1:Leua+MdhCV+M4gl746PcTsHF8dDP7+LLJ/NgHCTl/Fo= +github.com/jfrog/jfrog-cli-core/v2 v2.47.10 h1:14d6nQBU4zVV2c6ieH7pc/efDKybIgW0RnoXcsaU28A= +github.com/jfrog/jfrog-cli-core/v2 v2.47.10/go.mod h1:ZcyEfF9CuSsLCx1XiVd1xbwUdHlLH6Y6zvuXVipn+SE= +github.com/jfrog/jfrog-client-go v1.35.6 h1:nVS94x6cwSRkhtj8OM3elbUcGgQhqsK8YMPvC/gf5sk= +github.com/jfrog/jfrog-client-go v1.35.6/go.mod h1:V+XKC27k6GA5OcWIAItpnxZAZnCigg8xCkpXKP905Fk= github.com/jszwec/csvutil v1.8.0 h1:G7vS2LGdpZZDH1HmHeNbxOaJ/ZnJlpwGFvOkTkJzzNk= github.com/jszwec/csvutil v1.8.0/go.mod h1:/E4ONrmGkwmWsk9ae9jpXnv9QT8pLHEPcCirMFhxG9I= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= From e9eb8497cdc46222dda84f7cd60774768d84f23d Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Sun, 7 Jan 2024 20:21:27 +0200 Subject: [PATCH 5/6] Enhance JFrog CLI's release process to include automatic version bump (#2403) --- Jenkinsfile | 74 +++++++++++++++++++++++++-------------- build/bump-version.sh | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 26 deletions(-) create mode 100755 build/bump-version.sh diff --git a/Jenkinsfile b/Jenkinsfile index ad0f079c4..6e87fcf55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,6 +23,13 @@ node("docker") { identifier = 'v2-jf' nodeVersion = 'v8.17.0' + masterBranch = 'v2' + devBranch = 'dev' + if (BRANCH?.trim() == 'v1') { + masterBranch = 'v1' + devBranch = 'dev-v1' + } + repo = 'jfrog-cli' sh 'rm -rf temp' sh 'mkdir temp' @@ -54,17 +61,15 @@ node("docker") { """ } - stage('synchronize branches') { - masterBranch = 'v2' - devBranch = 'dev' - if (BRANCH?.trim() == 'v1') { - masterBranch = 'v1' - devBranch = 'dev-v1' - } - synchronizeBranches(masterBranch, devBranch) + stage('Bump version') { + bumpVersion() } - stage('install npm') { + stage('Sync branches') { + synchronizeBranches() + } + + stage('Install npm') { installNpm(nodeVersion) } @@ -80,6 +85,11 @@ node("docker") { } } +def getCliVersion(exePath) { + version = sh(script: "$exePath -v | tr -d 'jfrog version' | tr -d '\n'", returnStdout: true) + return version +} + def runRelease(architectures) { stage('Build JFrog CLI') { sh "echo Running release for executable name: '$cliExecutableName'" @@ -95,8 +105,8 @@ def runRelease(architectures) { } sh "mv $jfrogCliRepoDir/$cliExecutableName $builderDir" - // Extract CLI version - version = sh(script: "$builderPath -v | tr -d 'jfrog version' | tr -d '\n'", returnStdout: true) + + version = getCliVersion(builderPath) print "CLI version: $version" } configRepo21() @@ -164,24 +174,36 @@ def runRelease(architectures) { } } -def synchronizeBranches(masterBranch, devBranch) { +def bumpVersion() { + dir("$cliWorkspace/$repo") { + withCredentials([string(credentialsId: 'ecosystem-github-automation', variable: 'GITHUB_ACCESS_TOKEN')]) { + sh "git checkout $devBranch" + sh "build/build.sh" + fromVersion = getCliVersion("./jf") + sh "build/bump-version.sh $fromVersion $RELEASE_VERSION" + sh "git checkout $masterBranch" + } + } +} + +def synchronizeBranches() { dir("$cliWorkspace/$repo") { releaseTag = "v$RELEASE_VERSION" withCredentials([string(credentialsId: 'ecosystem-github-automation', variable: 'GITHUB_ACCESS_TOKEN')]) { - stage("Merge to $masterBranch") { - sh """#!/bin/bash - git merge origin/$devBranch --no-edit - git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git" - """ - } - stage("Merge to $devBranch") { - sh """#!/bin/bash - git checkout $devBranch - git merge origin/$masterBranch --no-edit - git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git" - git checkout $masterBranch - """ - } + print "Merge to $masterBranch" + sh """#!/bin/bash + git checkout $masterBranch + git merge origin/$devBranch --no-edit + git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git" + """ + + print "Merge to $devBranch" + sh """#!/bin/bash + git checkout $devBranch + git merge origin/$masterBranch --no-edit + git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git" + git checkout $masterBranch + """ } } } diff --git a/build/bump-version.sh b/build/bump-version.sh new file mode 100755 index 000000000..12d0179c7 --- /dev/null +++ b/build/bump-version.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Function to validate arguments +validateArgs() { + # Check if both arguments are provided + if [ $# -ne 2 ]; then + echo "Error: Please provide exactly two arguments - fromVersion and toVersion." + exit 1 + fi + + # Extract arguments + fromVersion=$1 + toVersion=$2 + + # Check if arguments are non-empty + if [ -z "$fromVersion" ] || [ -z "$toVersion" ]; then + echo "Error: Both fromVersion and toVersion must have non-empty values." + exit 1 + fi + + # Check if arguments are not identical + if [ "$fromVersion" = "$toVersion" ]; then + echo "Error: fromVersion and toVersion must have different values." + exit 1 + fi +} + +# Function to replace version in file +replaceVersion() { + local filePath=$1 + local line=$2 + local fromVersion=$3 + local toVersion=$4 + + # Check if the file exists + if [ ! -e "$filePath" ]; then + echo "Error: File '$filePath' not found." + exit 1 + fi + + # Use awk to replace the value if the line is found + awk -v line="$line" -v from="$fromVersion" -v to="$toVersion" ' + index($0, line) { + gsub(from, to); + found=1; + } + { print } + END { + if (found != 1) { + print "Error: The specified line ('" line "') does not exist in the file ('" filePath "')."; + exit 1; + } + } + ' "$filePath" > "$filePath.tmp" && mv "$filePath.tmp" "$filePath" + + # Validate if the file was modified using git + if git diff --exit-code "$filePath" > /dev/null; then + echo "Error: File '$filePath' was not modified." + exit 1 + fi + + git add "$filePath" +} + +# Call the function to validate arguments +validateArgs "$@" + +# Add calls to the function to replace version in file with specified filePath values +replaceVersion "../utils/cliutils/cli_consts.go" "CliVersion = \"$fromVersion\"" "$fromVersion" "$toVersion" +replaceVersion "./npm/v2/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "./npm/v2/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "./npm/v2-jf/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "./npm/v2-jf/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" + +# Print success message if validation and replacement pass +echo "Version bumped successfully." + +git commit -m "Bump version from $fromVersion to $toVersion" +git push +echo "Version bump pushed to git." From d55dad9e47b6163cbc3b436a5239b4d2ccd4bf35 Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Sun, 7 Jan 2024 20:51:14 +0200 Subject: [PATCH 6/6] Fix paths in bump-version.sh (#2404) --- build/bump-version.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build/bump-version.sh b/build/bump-version.sh index 12d0179c7..5b8f8a493 100755 --- a/build/bump-version.sh +++ b/build/bump-version.sh @@ -66,11 +66,11 @@ replaceVersion() { validateArgs "$@" # Add calls to the function to replace version in file with specified filePath values -replaceVersion "../utils/cliutils/cli_consts.go" "CliVersion = \"$fromVersion\"" "$fromVersion" "$toVersion" -replaceVersion "./npm/v2/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" -replaceVersion "./npm/v2/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" -replaceVersion "./npm/v2-jf/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" -replaceVersion "./npm/v2-jf/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "utils/cliutils/cli_consts.go" "CliVersion = \"$fromVersion\"" "$fromVersion" "$toVersion" +replaceVersion "build/npm/v2/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "build/npm/v2/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "build/npm/v2-jf/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" +replaceVersion "build/npm/v2-jf/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion" # Print success message if validation and replacement pass echo "Version bumped successfully."