Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
sverdlov93 committed Mar 28, 2024
2 parents def18c5 + d3d3560 commit a063de8
Show file tree
Hide file tree
Showing 54 changed files with 309 additions and 1,669 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
cache: false

- name: Static Code Analysis
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
args: |
--timeout 5m --out-${NO_FUTURE}format colored-line-number --enable errcheck,gosimple,govet,ineffassign,staticcheck,typecheck,unused,gocritic,asasalint,asciicheck,errchkjson,exportloopref,forcetypeassert,makezero,nilerr,unparam,unconvert,wastedassign,usestdlibvars
Expand All @@ -31,10 +32,11 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
cache: false

- name: Run Gosec Security Scanner
# Temporarily set version 2.18.0 to workaround https://github.com/securego/gosec/issues/1046
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/embedded-jar-test.yml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ jobs:
- name: Install pipenv & poetry
run: python -m pip install pipenv poetry

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
cache: false

- name: Install NuGet
uses: nuget/setup-nuget@v1
uses: nuget/setup-nuget@v2
with:
nuget-version: 6.x

Expand Down
8 changes: 3 additions & 5 deletions artifactory/commands/buildinfo/adddependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package buildinfo

import (
"errors"
ioutils "github.com/jfrog/gofrog/io"
regxp "regexp"
"strconv"

Expand Down Expand Up @@ -316,15 +317,12 @@ func convertFileInfoToDependencies(files map[string]*fileutils.FileDetails) []bu
func searchItems(spec *spec.SpecFiles, servicesManager artifactory.ArtifactoryServicesManager) (resultReader *content.ContentReader, err error) {
temp := []*content.ContentReader{}
var searchParams services.SearchParams
var reader *content.ContentReader
defer func() {
for _, reader := range temp {
e := reader.Close()
if err == nil {
err = e
}
ioutils.Close(reader, &err)
}
}()
var reader *content.ContentReader
for i := 0; i < len(spec.Files); i++ {
searchParams, err = utils.GetSearchParams(spec.Get(i))
if err != nil {
Expand Down
12 changes: 2 additions & 10 deletions artifactory/commands/dotnet/dotnetcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ func (dc *DotnetCommand) Exec() (err error) {
return err
}
defer func() {
if callbackFunc != nil {
e := callbackFunc()
if err == nil {
err = e
}
}
err = errors.Join(err, callbackFunc())
}()
if err = buildInfoModule.CalcDependencies(); err != nil {
if dc.isDotnetTestCommand() {
Expand Down Expand Up @@ -272,10 +267,7 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
}
log.Debug("Nuget config file created at:", configFile.Name())
defer func() {
e := configFile.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(configFile.Close()))
}()

// We would prefer to write the NuGet configuration using the `nuget add source` command,
Expand Down
20 changes: 4 additions & 16 deletions artifactory/commands/generic/delete.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generic

import (
ioutils "github.com/jfrog/gofrog/io"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
"github.com/jfrog/jfrog-client-go/artifactory/services"
Expand Down Expand Up @@ -36,12 +37,7 @@ func (dc *DeleteCommand) Run() (err error) {
if err != nil {
return
}
defer func() {
e := reader.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(reader, &err)
allowDelete := true
if !dc.quiet {
allowDelete, err = utils.ConfirmDelete(reader)
Expand Down Expand Up @@ -72,10 +68,7 @@ func (dc *DeleteCommand) GetPathsToDelete() (contentReader *content.ContentReade
var temp []*content.ContentReader
defer func() {
for _, reader := range temp {
e := reader.Close()
if err == nil {
err = e
}
ioutils.Close(reader, &err)
}
}()
for i := 0; i < len(dc.Spec().Files); i++ {
Expand All @@ -95,12 +88,7 @@ func (dc *DeleteCommand) GetPathsToDelete() (contentReader *content.ContentReade
if err != nil {
return nil, err
}
defer func() {
e := tempMergedReader.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(tempMergedReader, &err)
// After merge, remove top chain dirs as we may encounter duplicates and collisions between files and directories to delete.
// For example:
// Reader1: {"a"}
Expand Down
19 changes: 3 additions & 16 deletions artifactory/commands/generic/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,13 @@ func (dc *DownloadCommand) download() (err error) {
log.Error(err)
}
if summary != nil {
defer func() {
e := summary.ArtifactsDetailsReader.Close()
if err == nil {
err = e
}
}()
defer gofrog.Close(summary.ArtifactsDetailsReader, &err)
// If 'detailed summary' was requested, then the reader should not be closed here.
// It will be closed after it will be used to generate the summary.
if dc.DetailedSummary() {
dc.result.SetReader(summary.TransferDetailsReader)
} else {
defer func() {
e := summary.TransferDetailsReader.Close()
if err == nil {
err = e
}
}()
defer gofrog.Close(summary.TransferDetailsReader, &err)
}
totalDownloaded = summary.TotalSucceeded
totalFailed = summary.TotalFailed
Expand Down Expand Up @@ -168,10 +158,7 @@ func (dc *DownloadCommand) download() (err error) {
var tmpRoot string
tmpRoot, err = createDownloadResultEmptyTmpReflection(summary.TransferDetailsReader)
defer func() {
e := fileutils.RemoveTempDir(tmpRoot)
if err == nil {
err = e
}
err = errors.Join(err, fileutils.RemoveTempDir(tmpRoot))
}()
if err != nil {
return err
Expand Down
20 changes: 5 additions & 15 deletions artifactory/commands/generic/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

buildInfo "github.com/jfrog/build-info-go/entities"

"strconv"
"time"

ioutils "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/spec"
Expand All @@ -18,6 +16,8 @@ import (
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
"github.com/jfrog/jfrog-client-go/utils/io/content"
"github.com/jfrog/jfrog-client-go/utils/log"
"strconv"
"time"
)

type UploadCommand struct {
Expand Down Expand Up @@ -139,12 +139,7 @@ func (uc *UploadCommand) upload() (err error) {
}
if summary != nil {
artifactsDetailsReader = summary.ArtifactsDetailsReader
defer func() {
e := artifactsDetailsReader.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(artifactsDetailsReader, &err)
// If 'detailed summary' was requested, then the reader should not be closed here.
// It will be closed after it will be used to generate the summary.
if uc.DetailedSummary() {
Expand Down Expand Up @@ -263,12 +258,7 @@ func (uc *UploadCommand) handleSyncDeletes(syncDeletesProp string) (err error) {
if err != nil {
return err
}
defer func() {
e := resultItems.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(resultItems, &err)
_, err = servicesManager.DeleteFiles(resultItems)
return err
}
Expand Down
36 changes: 12 additions & 24 deletions artifactory/commands/golang/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"encoding/json"
"errors"
"fmt"
buildinfo "github.com/jfrog/build-info-go/entities"
biutils "github.com/jfrog/build-info-go/utils"
Expand Down Expand Up @@ -57,10 +58,7 @@ func publishPackage(packageVersion, targetRepo, buildName, buildNumber, projectK
return nil, nil, err
}
defer func() {
e := fileutils.RemoveTempDir(tempDirPath)
if err == nil {
err = e
}
err = errors.Join(err, fileutils.RemoveTempDir(tempDirPath))
}()

var zipArtifact *buildinfo.Artifact
Expand All @@ -87,18 +85,17 @@ func publishPackage(packageVersion, targetRepo, buildName, buildNumber, projectK
version := version.NewVersion(artifactoryVersion)
if version.AtLeast(_go.ArtifactoryMinSupportedVersion) {
log.Debug("Creating info file", projectPath)
pathToInfo, err := createInfoFile(packageVersion)
var pathToInfo string
pathToInfo, err = createInfoFile(packageVersion)
if err != nil {
return nil, nil, err
}
defer func() {
e := os.Remove(pathToInfo)
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(os.Remove(pathToInfo)))
}()
if collectBuildInfo {
infoArtifact, err := createInfoFileArtifact(pathToInfo, packageVersion)
var infoArtifact *buildinfo.Artifact
infoArtifact, err = createInfoFileArtifact(pathToInfo, packageVersion)
if err != nil {
return nil, nil, err
}
Expand All @@ -125,10 +122,7 @@ func createInfoFile(packageVersion string) (path string, err error) {
return "", errorutils.CheckError(err)
}
defer func() {
e := file.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(file.Close()))
}()
_, err = file.Write(content)
if err != nil {
Expand All @@ -155,10 +149,7 @@ func readModFile(version, projectPath string, createArtifact bool) ([]byte, *bui
return nil, nil, err
}
defer func() {
e := modFile.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(modFile.Close()))
}()
content, err := io.ReadAll(modFile)
if err != nil {
Expand Down Expand Up @@ -191,10 +182,7 @@ func archive(moduleName, version, projectPath, tempDir string, excludedPatterns
openedFile = true
defer func() {
if openedFile {
e := tempFile.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(tempFile.Close()))
}
}()
if err = archiveProject(tempFile, projectPath, moduleName, version, excludedPatterns); err != nil {
Expand All @@ -216,10 +204,10 @@ func archive(moduleName, version, projectPath, tempDir string, excludedPatterns
}
}
// Sync the file before renaming it
if err := tempFile.Sync(); err != nil {
if err = tempFile.Sync(); err != nil {
return "", nil, err
}
if err := tempFile.Close(); err != nil {
if err = tempFile.Close(); err != nil {
return "", nil, err
}
openedFile = false
Expand Down
Loading

0 comments on commit a063de8

Please sign in to comment.