Skip to content

Commit 16730c5

Browse files
authored
New --module option added to the build-add-dependencies command (#2081)
* add --module flag to jf rt bad Fixes #2034
1 parent fe0b3d8 commit 16730c5

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

Diff for: buildinfo_test.go

+26-17
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestBuildAddDependenciesFromHomeDir(t *testing.T) {
4141
fileName := "cliTestFile.txt"
4242
testFileRelPath, testFileAbs := createFileInHomeDir(t, fileName)
4343

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

@@ -436,29 +436,33 @@ func TestBuildAddDependencies(t *testing.T) {
436436
allFiles := []string{"a1.in", "a2.in", "a3.in", "b1.in", "b2.in", "b3.in", "c1.in", "c2.in", "c3.in"}
437437
var badTests = []buildAddDepsBuildInfoTestParams{
438438
// Collect the dependencies from the local file system (the --from-rt option is not used).
439-
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*"}, expectedDependencies: allFiles},
440-
{description: "'rt bad' single file", commandArgs: []string{"testdata/a/a1.in"}, expectedDependencies: []string{"a1.in"}},
441-
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
442-
{description: "'rt bad' special chars recursive", commandArgs: []string{getSpecialCharFilePath()}, expectedDependencies: []string{"a1.in"}},
443-
{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"}},
444-
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsSpec)}, expectedDependencies: allFiles},
445-
{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"}},
446-
{description: "'rt bad' exclude command line regexp", commandArgs: []string{"testdata/a/a(.*)", "--exclusions=(.*)a2.*;.*a3.in", "--regexp=true"}, expectedDependencies: []string{"a1.in"}},
439+
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
440+
{description: "'rt bad' simple cli", commandArgs: []string{"testdata/a/*", "--module=" + ModuleNameJFrogTest}, expectedDependencies: allFiles, expectedModule: ModuleNameJFrogTest},
441+
{description: "'rt bad' single file", commandArgs: []string{"testdata/a/a1.in"}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
442+
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}, expectedModule: tests.RtBuildName1},
443+
{description: "'rt bad' none recursive", commandArgs: []string{"testdata/a/*", "--recursive=false", "--module=" + ModuleNameJFrogTest}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}, expectedModule: ModuleNameJFrogTest},
444+
{description: "'rt bad' special chars recursive", commandArgs: []string{getSpecialCharFilePath()}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
445+
{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},
446+
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + tests.GetFilePathForArtifactory(tests.BuildAddDepsSpec)}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
447+
{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},
448+
{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},
447449

448450
// Collect the dependencies from Artifactory using the --from-rt option.
449-
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt"}, expectedDependencies: allFiles},
450-
{description: "'rt bad' single file", commandArgs: []string{tests.RtRepo1 + "/testdata/a/a1.in", "--from-rt"}, expectedDependencies: []string{"a1.in"}},
451-
{description: "'rt bad' none recursive", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--recursive=false", "--from-rt"}, expectedDependencies: []string{"a1.in", "a2.in", "a3.in"}},
452-
{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"}},
453-
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + buildAddDepsRemoteSpec, "--from-rt"}, expectedDependencies: allFiles},
454-
{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"}},
451+
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
452+
{description: "'rt bad' simple cli", commandArgs: []string{tests.RtRepo1 + "/testdata/a/*", "--from-rt", "--module=" + ModuleNameJFrogTest}, expectedDependencies: allFiles, expectedModule: ModuleNameJFrogTest},
453+
{description: "'rt bad' single file", commandArgs: []string{tests.RtRepo1 + "/testdata/a/a1.in", "--from-rt"}, expectedDependencies: []string{"a1.in"}, expectedModule: tests.RtBuildName1},
454+
{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},
455+
{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},
456+
{description: "'rt bad' spec", commandArgs: []string{"--spec=" + buildAddDepsRemoteSpec, "--from-rt"}, expectedDependencies: allFiles, expectedModule: tests.RtBuildName1},
457+
{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},
455458
}
456459

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

888+
assert.Equalf(t, buildInfoTestParams.expectedModule, buildInfo.Modules[0].Id,
889+
"%s test with the command: \nrt bad %s \nexpected to have the following Module ID: \n%s \nbut has: \n%s",
890+
buildInfoTestParams.description, buildInfoTestParams.commandArgs, buildInfoTestParams.expectedModule, buildInfo.Modules[0].Id)
891+
884892
for _, expectedDependency := range buildInfoTestParams.expectedDependencies {
885893
found := false
886894
for _, actualDependency := range buildInfo.Modules[0].Dependencies {
@@ -909,4 +917,5 @@ type buildAddDepsBuildInfoTestParams struct {
909917
expectedDependencies []string
910918
buildName string
911919
buildNumber string
920+
expectedModule string
912921
}

Diff for: documentation/CLI-for-JFrog-Artifactory.md

+9
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ By default, the command collects the files from the local file system. If you'd
893893
| --recursive | \[Default: true\]<br><br>When false, artifacts inside sub-folders in Artifactory will not be affected. |
894894
| --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. |
895895
| --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. |
896+
| --module | \[Optional\]<br><br>Optional module name in the build-info for adding the dependency. |
896897
| --exclusions | A list of Semicolon-separated exclude patterns. Allows using wildcards or a regular expression according to the value of the 'regexp' option. |
897898
| Command arguments | The command takes three arguments. |
898899
| Build name | The build name to add the dependencies to |
@@ -916,6 +917,14 @@ Add all files located in the **m-local-repo** Artifactory repository, under the
916917
jf rt bad my-build-name 7 "my-local-repo/dependencies/" --from-rt
917918
```
918919

920+
921+
**Example 3**
922+
923+
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.
924+
```
925+
jf rt bad my-build-name 7 "path/to/build/dependencies/dir/" --module m1
926+
```
927+
919928
### Publishing Build-Info
920929

921930
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:

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ require (
123123

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

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

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

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ github.com/jfrog/build-info-go v1.9.6 h1:lCJ2j5uXAlJsSwDe5J8WD7Co1f/hUlZvMfwfb5A
238238
github.com/jfrog/build-info-go v1.9.6/go.mod h1:GbuFS+viHCKZYx9nWHYu7ab1DgQkFdtVN3BJPUNb2D4=
239239
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
240240
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
241-
github.com/jfrog/jfrog-cli-core/v2 v2.39.3 h1:GtBwEAchuvI4c8ZwaJ6CKN/KavMlEu5+DwNX9OesYMI=
242-
github.com/jfrog/jfrog-cli-core/v2 v2.39.3/go.mod h1:/HJ9mO3AZsACtQWxkwMj7REWPdXT3yHKjJXjPHlmB34=
241+
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230731092001-fd76fc416e5b h1:EgoAukY5Z4su5qVm1DUOIL8Jp+/Q93gws2rbXGWyoNE=
242+
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230731092001-fd76fc416e5b/go.mod h1:r282g5RihB+f8vZywtu7zjhh85vGIG9XqpIIe424dK4=
243243
github.com/jfrog/jfrog-client-go v1.28.1-0.20230730114019-1d6985b1f8bd h1:UZxgBwOplrYdKgM3Uj8h3lRkjnHqK/gea1TV2E3yjU8=
244244
github.com/jfrog/jfrog-client-go v1.28.1-0.20230730114019-1d6985b1f8bd/go.mod h1:qEJxoe68sUtqHJ1YhXv/7pKYP/9p1D5tJrruzJKYeoI=
245245
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=

Diff for: utils/cliutils/commandsflags.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ const (
288288
badRecursive = badPrefix + recursive
289289
badRegexp = badPrefix + regexpFlag
290290
badFromRt = badPrefix + fromRt
291+
badModule = badPrefix + module
291292

292293
// Unique build-add-git flags
293294
configFlag = "config"
@@ -922,6 +923,10 @@ var flagsMap = map[string]cli.Flag{
922923
Name: recursive,
923924
Usage: "[Default: true] Set to false if you do not wish to collect artifacts in sub-folders to be added to the build info.` `",
924925
},
926+
badModule: cli.StringFlag{
927+
Name: module,
928+
Usage: "[Optional] Optional module name in the build-info for adding the dependency.` `",
929+
},
925930
badRegexp: cli.BoolFlag{
926931
Name: regexpFlag,
927932
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.` `",
@@ -1676,7 +1681,7 @@ var commandFlags = map[string][]string{
16761681
envInclude, envExclude, InsecureTls, project,
16771682
},
16781683
BuildAddDependencies: {
1679-
specFlag, specVars, uploadExclusions, badRecursive, badRegexp, badDryRun, project, badFromRt, serverId,
1684+
specFlag, specVars, uploadExclusions, badRecursive, badRegexp, badDryRun, project, badFromRt, serverId, badModule,
16801685
},
16811686
BuildAddGit: {
16821687
configFlag, serverId, project,

Diff for: utils/cliutils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ func CreateBuildConfiguration(c *cli.Context) *artifactoryUtils.BuildConfigurati
734734
buildNameArg = ""
735735
buildNumberArg = ""
736736
}
737-
buildConfiguration.SetBuildName(buildNameArg).SetBuildNumber(buildNumberArg).SetProject(c.String("project"))
737+
buildConfiguration.SetBuildName(buildNameArg).SetBuildNumber(buildNumberArg).SetProject(c.String("project")).SetModule(c.String("module"))
738738
return buildConfiguration
739739
}
740740

0 commit comments

Comments
 (0)