Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into si…
Browse files Browse the repository at this point in the history
…mple-defer
  • Loading branch information
sverdlov93 committed Mar 19, 2024
2 parents 0514c84 + bc5cbba commit 6d5a595
Show file tree
Hide file tree
Showing 395 changed files with 9,499 additions and 19,163 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
Expand All @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
Expand All @@ -39,6 +39,7 @@ jobs:
cache: false

- name: Run Gosec Security Scanner
uses: securego/gosec@master
# Temporarily set version 2.18.0 to workaround https://github.com/securego/gosec/issues/1046
uses: securego/[email protected]
with:
args: -exclude G204,G301,G302,G304,G306 -tests -exclude-dir \.*test\.* ./...
2 changes: 1 addition & 1 deletion .github/workflows/embedded-jar-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
GOPROXY: direct
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download JARs
run: buildscripts/download-jars.sh
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
GRADLE_OPTS: -Dorg.gradle.daemon=false
JFROG_CLI_LOG_LEVEL: "DEBUG"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"

Expand All @@ -40,20 +40,17 @@ jobs:
nuget-version: 6.x

- name: Install dotnet
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.x'

- name: Go Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Lint
run: go vet ./...

- name: Tests
run: go test -v github.com/jfrog/jfrog-cli-core/v2/tests -timeout 0 -race
11 changes: 6 additions & 5 deletions artifactory/commands/buildinfo/adddependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
buildinfo "github.com/jfrog/build-info-go/entities"
commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
"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/spec"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-client-go/artifactory"
Expand All @@ -22,7 +23,7 @@ import (
)

type BuildAddDependenciesCommand struct {
buildConfiguration *utils.BuildConfiguration
buildConfiguration *build.BuildConfiguration
dependenciesSpec *spec.SpecFiles
dryRun bool
result *commandsutils.Result
Expand Down Expand Up @@ -62,7 +63,7 @@ func (badc *BuildAddDependenciesCommand) Run() error {
if err != nil {
return err
}
if err = utils.SaveBuildGeneralDetails(buildName, buildNumber, badc.buildConfiguration.GetProject()); err != nil {
if err = build.SaveBuildGeneralDetails(buildName, buildNumber, badc.buildConfiguration.GetProject()); err != nil {
return err
}
}
Expand Down Expand Up @@ -93,7 +94,7 @@ func (badc *BuildAddDependenciesCommand) SetServerDetails(serverDetails *config.
return badc
}

func (badc *BuildAddDependenciesCommand) SetBuildConfiguration(buildConfiguration *utils.BuildConfiguration) *BuildAddDependenciesCommand {
func (badc *BuildAddDependenciesCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildAddDependenciesCommand {
badc.buildConfiguration = buildConfiguration
return badc
}
Expand Down Expand Up @@ -262,7 +263,7 @@ func collectPatternMatchingFiles(addDepsParams *specutils.CommonParams, rootPath
return nil, err
}

paths, err := fspatterns.ListFiles(rootPath, addDepsParams.IsRecursive(), addDepsParams.IsIncludeDirs(), true, excludePathPattern)
paths, err := fspatterns.ListFiles(rootPath, addDepsParams.IsRecursive(), addDepsParams.IsIncludeDirs(), false, true, excludePathPattern)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -296,7 +297,7 @@ func (badc *BuildAddDependenciesCommand) savePartialBuildInfo(dependencies []bui
if err != nil {
return err
}
return utils.SavePartialBuildInfo(buildName, buildNumber, badc.buildConfiguration.GetProject(), populateFunc)
return build.SavePartialBuildInfo(buildName, buildNumber, badc.buildConfiguration.GetProject(), populateFunc)
}

func convertFileInfoToDependencies(files map[string]*fileutils.FileDetails) []buildinfo.Dependency {
Expand Down
43 changes: 20 additions & 23 deletions artifactory/commands/buildinfo/addgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
buildinfo "github.com/jfrog/build-info-go/entities"
gofrogcmd "github.com/jfrog/gofrog/io"
"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/project"
utilsconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-client-go/artifactory/services"
artclientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
Expand All @@ -30,7 +32,7 @@ const (
)

type BuildAddGitCommand struct {
buildConfiguration *utils.BuildConfiguration
buildConfiguration *build.BuildConfiguration
dotGitPath string
configFilePath string
serverId string
Expand All @@ -56,7 +58,7 @@ func (config *BuildAddGitCommand) SetDotGitPath(dotGitPath string) *BuildAddGitC
return config
}

func (config *BuildAddGitCommand) SetBuildConfiguration(buildConfiguration *utils.BuildConfiguration) *BuildAddGitCommand {
func (config *BuildAddGitCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildAddGitCommand {
config.buildConfiguration = buildConfiguration
return config
}
Expand All @@ -76,7 +78,7 @@ func (config *BuildAddGitCommand) Run() error {
if err != nil {
return err
}
err = utils.SaveBuildGeneralDetails(buildName, buildNumber, config.buildConfiguration.GetProject())
err = build.SaveBuildGeneralDetails(buildName, buildNumber, config.buildConfiguration.GetProject())
if err != nil {
return err
}
Expand Down Expand Up @@ -127,7 +129,7 @@ func (config *BuildAddGitCommand) Run() error {
}
}
}
err = utils.SavePartialBuildInfo(buildName, buildNumber, config.buildConfiguration.GetProject(), populateFunc)
err = build.SavePartialBuildInfo(buildName, buildNumber, config.buildConfiguration.GetProject(), populateFunc)
if err != nil {
return err
}
Expand All @@ -148,7 +150,7 @@ func (config *BuildAddGitCommand) ServerDetails() (*utilsconfig.ServerDetails, e
} else if config.configFilePath != "" {
// Get the server ID from the conf file.
var vConfig *viper.Viper
vConfig, err := utils.ReadConfigFile(config.configFilePath, utils.YAML)
vConfig, err := project.ReadConfigFile(config.configFilePath, project.YAML)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -189,16 +191,15 @@ func (config *BuildAddGitCommand) collectBuildIssues(vcsUrl string) ([]buildinfo
return config.DoCollect(config.issuesConfig, lastVcsRevision)
}

func (config *BuildAddGitCommand) DoCollect(issuesConfig *IssuesConfiguration, lastVcsRevision string) ([]buildinfo.AffectedIssue, error) {
var foundIssues []buildinfo.AffectedIssue
func (config *BuildAddGitCommand) DoCollect(issuesConfig *IssuesConfiguration, lastVcsRevision string) (foundIssues []buildinfo.AffectedIssue, err error) {
logRegExp, err := createLogRegExpHandler(issuesConfig, &foundIssues)
if err != nil {
return nil, err
return
}

errRegExp, err := createErrRegExpHandler(lastVcsRevision)
if err != nil {
return nil, err
return
}

// Get log with limit, starting from the latest commit.
Expand All @@ -207,36 +208,32 @@ func (config *BuildAddGitCommand) DoCollect(issuesConfig *IssuesConfiguration, l
// Change working dir to where .git is.
wd, err := os.Getwd()
if errorutils.CheckError(err) != nil {
return nil, err
return
}
defer func() {
e := os.Chdir(wd)
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(os.Chdir(wd)))
}()
err = os.Chdir(config.dotGitPath)
if errorutils.CheckError(err) != nil {
return nil, err
return
}

// Run git command.
_, _, exitOk, err := gofrogcmd.RunCmdWithOutputParser(logCmd, false, logRegExp, errRegExp)
if err != nil {
if _, ok := err.(RevisionRangeError); ok {
if errorutils.CheckError(err) != nil {
var revisionRangeError RevisionRangeError
if errors.As(err, &revisionRangeError) {
// Revision not found in range. Ignore and don't collect new issues.
log.Info(err.Error())
return []buildinfo.AffectedIssue{}, nil
}
return nil, errorutils.CheckError(err)
return
}
if !exitOk {
// May happen when trying to run git log for non-existing revision.
return nil, errorutils.CheckErrorf("failed executing git log command")
err = errorutils.CheckErrorf("failed executing git log command")
}

// Return found issues.
return foundIssues, nil
return
}

// Creates a regexp handler to parse and fetch issues from the output of the git log command.
Expand Down Expand Up @@ -372,7 +369,7 @@ func (config *BuildAddGitCommand) getLatestBuildInfo(issuesConfig *IssuesConfigu

func (ic *IssuesConfiguration) populateIssuesConfigsFromSpec(configFilePath string) (err error) {
var vConfig *viper.Viper
vConfig, err = utils.ReadConfigFile(configFilePath, utils.YAML)
vConfig, err = project.ReadConfigFile(configFilePath, project.YAML)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions artifactory/commands/buildinfo/addgit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"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/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/utils/log"
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
Expand Down Expand Up @@ -134,7 +134,7 @@ func cleanUp(t *testing.T, buildDir, dotGitPath, originalDir string) {
}

func getBuildInfoPartials(t *testing.T, buildName, buildNumber, projectKey string) buildinfo.Partials {
partials, err := utils.ReadPartialBuildInfoFiles(buildName, buildNumber, projectKey)
partials, err := build.ReadPartialBuildInfoFiles(buildName, buildNumber, projectKey)
if err != nil {
assert.NoError(t, err)
return nil
Expand All @@ -144,7 +144,7 @@ func getBuildInfoPartials(t *testing.T, buildName, buildNumber, projectKey strin

// Run BAG command. If setDotGit==true, provide baseDir to the command. Else, change wd to baseDir and make the command find .git manually.
func runBuildAddGit(t *testing.T, buildName, buildNumber string, baseDir string, setDotGit bool) error {
buildAddGitConfiguration := new(BuildAddGitCommand).SetBuildConfiguration(utils.NewBuildConfiguration(buildName, buildNumber, "", ""))
buildAddGitConfiguration := new(BuildAddGitCommand).SetBuildConfiguration(build.NewBuildConfiguration(buildName, buildNumber, "", ""))
if setDotGit {
buildAddGitConfiguration.SetDotGitPath(baseDir)
} else {
Expand All @@ -167,7 +167,7 @@ func runBuildAddGit(t *testing.T, buildName, buildNumber string, baseDir string,
}

func getBuildDir(t *testing.T) string {
buildDir, err := utils.GetBuildDir(buildName, "1", "")
buildDir, err := build.GetBuildDir(buildName, "1", "")
if err != nil {
t.Error("Cannot create temp dir due to: " + err.Error())
return ""
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestAddGitDoCollect(t *testing.T) {
Regexp: `(.+-[0-9]+)\s-\s(.+)`,
TrackerName: "test",
},
buildConfiguration: utils.NewBuildConfiguration("cli-tests-rt-build1", "1", "", ""),
buildConfiguration: build.NewBuildConfiguration("cli-tests-rt-build1", "1", "", ""),
configFilePath: "",
dotGitPath: dotGitPath,
}
Expand Down
Loading

0 comments on commit 6d5a595

Please sign in to comment.