Skip to content

Commit

Permalink
New --module option added to the build-add-dependencies command (#…
Browse files Browse the repository at this point in the history
…2081)

* add --module flag to jf rt bad
Fixes #2034
  • Loading branch information
sarao1310 committed Jul 31, 2023
1 parent fe0b3d8 commit 16730c5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
43 changes: 26 additions & 17 deletions buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestBuildAddDependenciesFromHomeDir(t *testing.T) {
fileName := "cliTestFile.txt"
testFileRelPath, testFileAbs := createFileInHomeDir(t, fileName)

test := buildAddDepsBuildInfoTestParams{description: "'rt bad' from home dir", commandArgs: []string{testFileRelPath, "--recursive=false"}, expectedDependencies: []string{fileName}, buildName: tests.RtBuildName1, buildNumber: "1"}
test := buildAddDepsBuildInfoTestParams{description: "'rt bad' from home dir", commandArgs: []string{testFileRelPath, "--recursive=false"}, expectedDependencies: []string{fileName}, buildName: tests.RtBuildName1, buildNumber: "1", expectedModule: tests.RtBuildName1}
collectDepsAndPublishBuild(test, false, t)
validateBuildAddDepsBuildInfo(t, test)

Expand Down Expand Up @@ -436,29 +436,33 @@ func TestBuildAddDependencies(t *testing.T) {
allFiles := []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}
var badTests = []buildAddDepsBuildInfoTestParams{
// Collect the dependencies from the local file system (the --from-rt option is not used).
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*"}, expectedDependencies: allFiles},
{description: "'rt bad' single file", commandArgs: []string{"testdata/a/a1.in"}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
{description: "'rt bad' special chars recursive", commandArgs: []string{getSpecialCharFilePath()}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' exclude command line wildcards", commandArgs: []string{"testdata/a/*", "--exclusions=*a2*;*a3.in"}, expectedDependencies: []string{"a1.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}},
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsSpec)}, expectedDependencies: allFiles},
{description: "'rt bad' two specFiles", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsDoubleSpec)}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in"}},
{description: "'rt bad' exclude command line regexp", commandArgs: []string{"testdata/a/a(.*)", "--exclusions=(.*)a2.*;.*a3.in", "--regexp=true"}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*", "--module=" + ModuleNameJFrogTest}, expectedDependencies: allFiles, expectedModule: ModuleNameJFrogTest},
{description: "'rt bad' single file", commandArgs: []string{"testdata/a/a1.in"}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false", "--module=" + ModuleNameJFrogTest}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}, expectedModule: ModuleNameJFrogTest},
{description: "'rt bad' special chars recursive", commandArgs: []string{getSpecialCharFilePath()}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' exclude command line wildcards", commandArgs: []string{"testdata/a/*", "--exclusions=*a2*;*a3.in"}, expectedDependencies: []string{"a1.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsSpec)}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
{description: "'rt bad' two specFiles", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsDoubleSpec)}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' exclude command line regexp", commandArgs: []string{"testdata/a/a(.*)", "--exclusions=(.*)a2.*;.*a3.in", "--regexp=true", "--module=" + ModuleNameJFrogTest}, expectedDependencies: []string{"a1.in"}, expectedModule: ModuleNameJFrogTest},

// Collect the dependencies from Artifactory using the --from-rt option.
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt"}, expectedDependencies: allFiles},
{description: "'rt bad' single file", commandArgs: []string{tests.RtRepo1 + "/testdata/a/a1.in", "--from-rt"}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' none recursive", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--recursive=false", "--from-rt"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
{description: "'rt bad' exclude command line wildcards", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--exclusions=*a2*;*a3.in", "--from-rt"}, expectedDependencies: []string{"a1.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}},
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + buildAddDepsRemoteSpec, "--from-rt"}, expectedDependencies: allFiles},
{description: "'rt bad' two specFiles", commandArgs: []string{"--spec=" + buildAddDepsDoubleRemoteSpec, "--from-rt"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in"}},
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt", "--module=" + ModuleNameJFrogTest}, expectedDependencies: allFiles, expectedModule: ModuleNameJFrogTest},
{description: "'rt bad' single file", commandArgs: []string{tests.RtRepo1 + "/testdata/a/a1.in", "--from-rt"}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' none recursive", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--recursive=false", "--from-rt"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' exclude command line wildcards", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--exclusions=*a2*;*a3.in", "--from-rt", "--module=" + ModuleNameJFrogTest}, expectedDependencies: []string{"a1.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}, expectedModule: ModuleNameJFrogTest},
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + buildAddDepsRemoteSpec, "--from-rt"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
{description: "'rt bad' two specFiles", commandArgs: []string{"--spec=" + buildAddDepsDoubleRemoteSpec, "--from-rt"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in"}, expectedModule: tests.RtBuildName1},
}

// Tests compatibility to file paths with windows separators.
if coreutils.IsWindows() {
var compatibilityTests = []buildAddDepsBuildInfoTestParams{
{description: "'rt bad' win compatibility by arguments", commandArgs: []string{"testdata\\\\a\\\\a1.in"}, expectedDependencies: []string{"a1.in"}},
{description: "'rt bad' win compatibility by spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.WinBuildAddDepsSpec)}, expectedDependencies: allFiles},
{description: "'rt bad' win compatibility by arguments", commandArgs: []string{"testdata\\\\a\\\\a1.in"}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
{description: "'rt bad' win compatibility by arguments", commandArgs: []string{"testdata\\\\a\\\\a1.in", "--module=" + ModuleNameJFrogTest}, expectedDependencies: []string{"a1.in"}, expectedModule: ModuleNameJFrogTest},
{description: "'rt bad' win compatibility by spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.WinBuildAddDepsSpec)}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
}
badTests = append(badTests, compatibilityTests...)
}
Expand Down Expand Up @@ -881,6 +885,10 @@ func validateBuildAddDepsBuildInfo(t *testing.T, buildInfoTestParams buildAddDep
"%s test with the command: \nrt bad %s \nexpected to have the following dependencies: \n%s \nbut has: \n%s",
buildInfoTestParams.description, buildInfoTestParams.commandArgs, buildInfoTestParams.expectedDependencies, dependenciesToPrintableArray(buildInfo.Modules[0].Dependencies))

assert.Equalf(t, buildInfoTestParams.expectedModule, buildInfo.Modules[0].Id,
"%s test with the command: \nrt bad %s \nexpected to have the following Module ID: \n%s \nbut has: \n%s",
buildInfoTestParams.description, buildInfoTestParams.commandArgs, buildInfoTestParams.expectedModule, buildInfo.Modules[0].Id)

for _, expectedDependency := range buildInfoTestParams.expectedDependencies {
found := false
for _, actualDependency := range buildInfo.Modules[0].Dependencies {
Expand Down Expand Up @@ -909,4 +917,5 @@ type buildAddDepsBuildInfoTestParams struct {
expectedDependencies []string
buildName string
buildNumber string
expectedModule string
}
9 changes: 9 additions & 0 deletions documentation/CLI-for-JFrog-Artifactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ By default, the command collects the files from the local file system. If you'd
| --recursive | \[Default: true\]<br><br>When false, artifacts inside sub-folders in Artifactory will not be affected. |
| --regexp | \[Optional: false\]<br><br>\[Default: false\] Set to true to use a regular expression instead of wildcards expression to collect files to be added to the build info.This option is not supported when --from-rt is set to true. |
| --dry-run | \[Default: false\]<br><br>Set to true to only get a summery of the dependencies that will be added to the build info. |
| --module | \[Optional\]<br><br>Optional module name in the build-info for adding the dependency. |
| --exclusions | A list of Semicolon-separated exclude patterns. Allows using wildcards or a regular expression according to the value of the 'regexp' option. |
| Command arguments | The command takes three arguments. |
| Build name | The build name to add the dependencies to |
Expand All @@ -916,6 +917,14 @@ Add all files located in the **m-local-repo** Artifactory repository, under the
jf rt bad my-build-name 7 "my-local-repo/dependencies/" --from-rt
```


**Example 3**

Add all files located under the **path/to/build/dependencies/dir** directory as dependencies of a build. The build name is **my-build-name**, the build number is **7** and module is m1. The build-info is only updated locally. To publish the build-info to Artifactory use the **jf rt build-publish** command.
```
jf rt bad my-build-name 7 "path/to/build/dependencies/dir/" --module m1
```

### Publishing Build-Info

This command is used to publish build info to Artifactory. To publish the accumulated build-info for a build to Artifactory, use the **build-publish** command. For example, the following command publishes all the build-info collected for build **my-build-name** with build number 18:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ require (

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230731092001-fd76fc416e5b

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.6-0.20230418122323-2bf299dd6d27

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ github.com/jfrog/build-info-go v1.9.6 h1:lCJ2j5uXAlJsSwDe5J8WD7Co1f/hUlZvMfwfb5A
github.com/jfrog/build-info-go v1.9.6/go.mod h1:GbuFS+viHCKZYx9nWHYu7ab1DgQkFdtVN3BJPUNb2D4=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/jfrog/jfrog-cli-core/v2 v2.39.3 h1:GtBwEAchuvI4c8ZwaJ6CKN/KavMlEu5+DwNX9OesYMI=
github.com/jfrog/jfrog-cli-core/v2 v2.39.3/go.mod h1:/HJ9mO3AZsACtQWxkwMj7REWPdXT3yHKjJXjPHlmB34=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230731092001-fd76fc416e5b h1:EgoAukY5Z4su5qVm1DUOIL8Jp+/Q93gws2rbXGWyoNE=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230731092001-fd76fc416e5b/go.mod h1:r282g5RihB+f8vZywtu7zjhh85vGIG9XqpIIe424dK4=
github.com/jfrog/jfrog-client-go v1.28.1-0.20230730114019-1d6985b1f8bd h1:UZxgBwOplrYdKgM3Uj8h3lRkjnHqK/gea1TV2E3yjU8=
github.com/jfrog/jfrog-client-go v1.28.1-0.20230730114019-1d6985b1f8bd/go.mod h1:qEJxoe68sUtqHJ1YhXv/7pKYP/9p1D5tJrruzJKYeoI=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down
7 changes: 6 additions & 1 deletion utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ const (
badRecursive = badPrefix + recursive
badRegexp = badPrefix + regexpFlag
badFromRt = badPrefix + fromRt
badModule = badPrefix + module

// Unique build-add-git flags
configFlag = "config"
Expand Down Expand Up @@ -922,6 +923,10 @@ var flagsMap = map[string]cli.Flag{
Name: recursive,
Usage: "[Default: true] Set to false if you do not wish to collect artifacts in sub-folders to be added to the build info.` `",
},
badModule: cli.StringFlag{
Name: module,
Usage: "[Optional] Optional module name in the build-info for adding the dependency.` `",
},
badRegexp: cli.BoolFlag{
Name: regexpFlag,
Usage: "[Default: false] Set to true to use a regular expression instead of wildcards expression to collect files to be added to the build info.` `",
Expand Down Expand Up @@ -1676,7 +1681,7 @@ var commandFlags = map[string][]string{
envInclude, envExclude, InsecureTls, project,
},
BuildAddDependencies: {
specFlag, specVars, uploadExclusions, badRecursive, badRegexp, badDryRun, project, badFromRt, serverId,
specFlag, specVars, uploadExclusions, badRecursive, badRegexp, badDryRun, project, badFromRt, serverId, badModule,
},
BuildAddGit: {
configFlag, serverId, project,
Expand Down
2 changes: 1 addition & 1 deletion utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func CreateBuildConfiguration(c *cli.Context) *artifactoryUtils.BuildConfigurati
buildNameArg = ""
buildNumberArg = ""
}
buildConfiguration.SetBuildName(buildNameArg).SetBuildNumber(buildNumberArg).SetProject(c.String("project"))
buildConfiguration.SetBuildName(buildNameArg).SetBuildNumber(buildNumberArg).SetProject(c.String("project")).SetModule(c.String("module"))
return buildConfiguration
}

Expand Down

0 comments on commit 16730c5

Please sign in to comment.