Skip to content

Commit

Permalink
pull dev & update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Mar 20, 2024
2 parents be48048 + b631e3d commit 6c156dc
Show file tree
Hide file tree
Showing 40 changed files with 139 additions and 316 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,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: Static Code Analysis
uses: golangci/golangci-lint-action@v3
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
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ 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
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
13 changes: 3 additions & 10 deletions artifactory/commands/npm/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"errors"
"fmt"
ioutils "github.com/jfrog/gofrog/io"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -198,12 +199,7 @@ func (npc *NpmPublishCommand) Run() (err error) {
if err != nil {
return err
}
defer func() {
e := npc.artifactsDetailsReader.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(npc.artifactsDetailsReader, &err)
err = npmModule.AddArtifacts(buildArtifacts...)
if err != nil {
return errorutils.CheckError(err)
Expand Down Expand Up @@ -432,10 +428,7 @@ func (npc *NpmPublishCommand) readPackageInfoFromTarball(packedFilePath string)
return errorutils.CheckError(err)
}
defer func() {
e := tarball.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(tarball.Close()))
}()
gZipReader, err := gzip.NewReader(tarball)
if err != nil {
Expand Down
15 changes: 3 additions & 12 deletions artifactory/commands/python/dependencies/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dependencies
import (
"encoding/json"
buildinfo "github.com/jfrog/build-info-go/entities"
ioutils "github.com/jfrog/gofrog/io"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"io"
Expand Down Expand Up @@ -31,12 +32,7 @@ func GetProjectDependenciesCache(cacheDir string) (cache *DependenciesCache, err
if errorutils.CheckError(err) != nil {
return nil, err
}
defer func() {
e := jsonFile.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(jsonFile, &err)
byteValue, err := io.ReadAll(jsonFile)
if errorutils.CheckError(err) != nil {
return nil, err
Expand Down Expand Up @@ -66,12 +62,7 @@ func UpdateDependenciesCache(updatedMap map[string]buildinfo.Dependency, cacheDi
if err != nil {
return errorutils.CheckError(err)
}
defer func() {
e := cacheFile.Close()
if err == nil {
err = e
}
}()
defer ioutils.Close(cacheFile, &err)
_, err = cacheFile.Write(content)
if err != nil {
return errorutils.CheckError(err)
Expand Down
Loading

0 comments on commit 6c156dc

Please sign in to comment.