Skip to content

Commit

Permalink
Merge branch 'dev' into add-module-flag-to-bad
Browse files Browse the repository at this point in the history
  • Loading branch information
sarao1310 authored Jul 20, 2023
2 parents 6a51b3e + 7e6b04f commit 4165c9c
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build/npm/v2-jf/package-lock.json

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

2 changes: 1 addition & 1 deletion build/npm/v2-jf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2-jf",
"version": "2.43.1",
"version": "2.44.0",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2/package-lock.json

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

2 changes: 1 addition & 1 deletion build/npm/v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2",
"version": "2.43.1",
"version": "2.44.0",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func GoPublishCmd(c *cli.Context) (err error) {
version := c.Args().Get(0)
printDeploymentView, detailedSummary := log.IsStdErrTerminal(), c.Bool("detailed-summary")
goPublishCmd := golang.NewGoPublishCommand()
goPublishCmd.SetConfigFilePath(configFilePath).SetBuildConfiguration(buildConfiguration).SetVersion(version).SetDetailedSummary(detailedSummary || printDeploymentView)
goPublishCmd.SetConfigFilePath(configFilePath).SetBuildConfiguration(buildConfiguration).SetVersion(version).SetDetailedSummary(detailedSummary || printDeploymentView).SetExcludedPatterns(cliutils.GetStringsArrFlagValue(c, "exclusions"))
err = commands.Exec(goPublishCmd)
result := goPublishCmd.Result()
defer cliutils.CleanupResult(result, &err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ replace github.com/jfrog/jfrog-cli-core/v2 => github.com/sarao1310/jfrog-cli-cor

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

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230705083849-6fd087a5e228
//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230717090738-b2e0c7bcc026
50 changes: 50 additions & 0 deletions go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,56 @@ func TestGoPublishWithDeploymentView(t *testing.T) {
clientTestUtils.ChangeDirAndAssert(t, wd)
}

func TestGoPublishWithExclusions(t *testing.T) {
_, goCleanupFunc := initGoTest(t)
defer goCleanupFunc()
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
searchFilePath, err := tests.CreateSpec(tests.GoPublishRepoExcludes)
assert.NoError(t, err)

var testData = []struct {
exclusions string
expectedExistFilesPaths []string
expectedNotExistFilesPaths []string
}{
{"./dir1/*", tests.GetGoPublishWithExclusionsExpectedFiles1(), tests.GetGoPublishWithExclusionsExcludedFiles1()},
{"./dir1/dir2/*", tests.GetGoPublishWithExclusionsExpectedFiles2(), tests.GetGoPublishWithExclusionsExcludedFiles2()},
{"*.txt", nil, tests.GetGoPublishWithExclusionsExcludedFiles3()},
}
for _, test := range testData {
prepareGoProject("project4", t, true)
jfrogCli := tests.NewJfrogCli(execMain, "jf", "")
err = execGo(jfrogCli, "gp", "v1.1.1", "--exclusions", test.exclusions)
assert.NoError(t, err)

// Verify that go-publish successfully published expected files and directories to Artifactory.
inttestutils.VerifyExistInArtifactory(tests.GetGoPublishWithExclusionsExpectedRepoGo(), searchFilePath, serverDetails, t)
// Creating a temporary directory to download for it the content of the zip file from artifactory.
tmpDir, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
err = os.RemoveAll(tmpDir)
assert.NoError(t, err)
assert.NoError(t, os.Mkdir(tmpDir, 0777))
runRt(t, "download", tests.GoRepo, tmpDir+"/", "--explode")
// Checking whether the expected files exist in the zip file after downloading from artifactory with unzipping it.
for _, path := range test.expectedExistFilesPaths {
result, err := fileutils.IsFileExists(filepath.Join(tmpDir, path), true)
assert.NoError(t, err)
assert.True(t, result, "This file"+path+"does not exist")
}
// Checking whether the excluded files do not exist in the zip file after downloading from Artifactory with unzipping it.
for _, path := range test.expectedNotExistFilesPaths {
result, err := fileutils.IsFileExists(filepath.Join(tmpDir, path), true)
assert.NoError(t, err)
assert.False(t, result)
}
// Delete the temporary dir.
createTempDirCallback()
// Restore workspace.
clientTestUtils.ChangeDirAndAssert(t, wd)
}
}

func TestGoVcsFallback(t *testing.T) {
_, cleanUpFunc := initGoTest(t)
defer cleanUpFunc()
Expand Down
7 changes: 7 additions & 0 deletions testdata/filespecs/go_publish_repo_excludes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files": [
{
"pattern": "${GO_REPO}/*"
}
]
}
9 changes: 9 additions & 0 deletions testdata/go/project3/.jfrog/projects/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
type: go

resolver:
repo: ${GO_VIRTUAL_REPO}
serverID: default
deployer:
repo: ${GO_REPO}
serverID: default
8 changes: 8 additions & 0 deletions testdata/go/project3/createGoProject_go.mod_suffix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/jfrog/dependency

require (
github.com/pkg/errors v0.8.0
rsc.io/quote v1.5.2
)

go 1.13
11 changes: 11 additions & 0 deletions testdata/go/project3/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dependency

import (
"fmt"
"github.com/pkg/errors"
)

func PrintHello() error {
fmt.Println("Hello")
return errors.New("abc")
}
7 changes: 7 additions & 0 deletions testdata/go/project3/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
9 changes: 9 additions & 0 deletions testdata/go/project4/.jfrog/projects/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
type: go

resolver:
repo: ${GO_VIRTUAL_REPO}
serverID: default
deployer:
repo: ${GO_REPO}
serverID: default
8 changes: 8 additions & 0 deletions testdata/go/project4/createGoProject_go.mod_suffix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/jfrog/dependency

require (
github.com/pkg/errors v0.8.0
rsc.io/quote v1.5.2
)

go 1.13
11 changes: 11 additions & 0 deletions testdata/go/project4/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dependency

import (
"fmt"
"github.com/pkg/errors"
)

func PrintHello() error {
fmt.Println("Hello World")
return errors.New("abc")
}
1 change: 1 addition & 0 deletions testdata/go/project4/dir1/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a.txt
1 change: 1 addition & 0 deletions testdata/go/project4/dir1/dir2/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b.txt
1 change: 1 addition & 0 deletions testdata/go/project4/dir1/dir2/dir3/c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c.txt
1 change: 1 addition & 0 deletions testdata/go/project4/dir4/d.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d.txt
7 changes: 7 additions & 0 deletions testdata/go/project4/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
2 changes: 1 addition & 1 deletion utils/cliutils/cli_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

const (
// General CLI constants
CliVersion = "2.43.1"
CliVersion = "2.44.0"
ClientAgent = "jfrog-cli-go"

// CLI base commands constants:
Expand Down
9 changes: 8 additions & 1 deletion utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ const (
propsProps = propertiesPrefix + props
propsExcludeProps = propertiesPrefix + excludeProps

// Unique go publish flags
goPublishExclusions = GoPublish + exclusions

// Unique build-publish flags
buildPublishPrefix = "bp-"
bpDryRun = buildPublishPrefix + dryRun
Expand Down Expand Up @@ -1407,6 +1410,10 @@ var flagsMap = map[string]cli.Flag{
Name: Go,
Usage: "[Default: false] Set to true to request audit for a Go project.` `",
},
goPublishExclusions: cli.StringFlag{
Name: exclusions,
Usage: "[Optional] Semicolon-separated list of exclusions. Exclusions can include the * and the ? wildcards.` `",
},
rescan: cli.BoolFlag{
Name: rescan,
Usage: "[Default: false] Set to true when scanning an already successfully scanned build, for example after adding an ignore rule.` `",
Expand Down Expand Up @@ -1768,7 +1775,7 @@ var commandFlags = map[string][]string{
global, serverIdResolve, serverIdDeploy, repoResolve, repoDeploy,
},
GoPublish: {
url, user, password, accessToken, buildName, buildNumber, module, project, detailedSummary,
url, user, password, accessToken, buildName, buildNumber, module, project, detailedSummary, goPublishExclusions,
},
Go: {
buildName, buildNumber, module, project, noFallback,
Expand Down
71 changes: 71 additions & 0 deletions utils/tests/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
SearchAllProdRepo = "search_all_prod_repo.json"
SearchDistRepoByInSuffix = "search_dist_repo_by_in_suffix.json"
SearchRepo1ByInSuffix = "search_repo1_by_in_suffix.json"
GoPublishRepoExcludes = "go_publish_repo_excludes.json"
SearchRepo1IncludeDirs = "search_repo1_include_dirs.json"
SearchRepo1NonExistFile = "search_repo1_ant_test_file.json"
SearchRepo1NonExistFileAntExclusions = "search_repo1_ant_and_exclusions_test_file.json"
Expand Down Expand Up @@ -215,6 +216,7 @@ var (
LcRbName1 = "cli-lc-rb1"
LcRbName2 = "cli-lc-rb2"
LcRbName3 = "cli-lc-rb3"
GoPublishWithExclusionPath = "github.com/jfrog/dependency/@v/github.com/jfrog/[email protected]/"

// Users
UserName1 = "alice"
Expand Down Expand Up @@ -262,6 +264,16 @@ func GetExpectedExcludeUploadPart2() []string {
RtRepo1 + "/",
}
}
func GetExpectedExcludeUpload2() []string {
return []string{
RtRepo1 + "/b3.in",
RtRepo1 + "/a2.in",
RtRepo1 + "/a3.in",
RtRepo1 + "/a1.in",
RtRepo1 + "/c",
RtRepo1 + "/",
}
}
func GetExpectedExcludeUploadIncludeDir() []string {
return []string{
RtRepo1 + "/a2.in",
Expand All @@ -272,6 +284,14 @@ func GetExpectedExcludeUploadIncludeDir() []string {
}
}

func GetUploadLegacyPropsExpected() []string {
return []string{
RtRepo1 + "/data/a1.in",
RtRepo1 + "/data/a2.in",
RtRepo1 + "/data/a3.in",
}
}

func GetSearchAppendedBuildNoPatternExpected() []string {
return []string{
RtRepo1 + "/data/a1.in",
Expand Down Expand Up @@ -2078,3 +2098,54 @@ func GetExpectedLifecycleArtifacts() []string {
RtProdRepo + "/c3.in",
}
}

func GetGoPublishWithExclusionsExpectedRepoGo() []string {
var expected = []string{
GoRepo + "/github.com/jfrog/dependency/@v/v1.1.1.info",
GoRepo + "/github.com/jfrog/dependency/@v/v1.1.1.mod",
GoRepo + "/github.com/jfrog/dependency/@v/v1.1.1.zip",
}
return expected
}

func GetGoPublishWithExclusionsExpectedFiles1() []string {
var expected = []string{
GoPublishWithExclusionPath + "dir4/d.txt",
}
return expected
}

func GetGoPublishWithExclusionsExcludedFiles1() []string {
var excluded = []string{
GoPublishWithExclusionPath + "dir1/a.txt",
GoPublishWithExclusionPath + "dir1/dir2/b.txt",
GoPublishWithExclusionPath + "dir1/dir2/dir3/c.txt",
}
return excluded
}

func GetGoPublishWithExclusionsExpectedFiles2() []string {
var expected = []string{
GoPublishWithExclusionPath + "dir4/d.txt",
GoPublishWithExclusionPath + "dir1/a.txt",
}
return expected
}

func GetGoPublishWithExclusionsExcludedFiles2() []string {
var excluded = []string{
GoPublishWithExclusionPath + "dir1/dir2/b.txt",
GoPublishWithExclusionPath + "dir1/dir2/dir3/c.txt",
}
return excluded
}

func GetGoPublishWithExclusionsExcludedFiles3() []string {
var excluded = []string{
GoPublishWithExclusionPath + "dir1/a.txt",
GoPublishWithExclusionPath + "dir1/dir2/b.txt",
GoPublishWithExclusionPath + "dir1/dir2/dir3/c.txt",
GoPublishWithExclusionPath + "dir4/d.txt",
}
return excluded
}
2 changes: 1 addition & 1 deletion xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestXrayAuditNoTech(t *testing.T) {
defer clientTestUtils.ChangeDirAndAssert(t, prevWd)
// Run audit on empty folder, expect an error
err := xrayCli.Exec("audit")
assert.EqualError(t, err, "could not determine the package manager / build tool used by this project.")
assert.NoError(t, err)
}

func TestXrayAuditDetectTech(t *testing.T) {
Expand Down

0 comments on commit 4165c9c

Please sign in to comment.