Skip to content

Commit

Permalink
Upload empty archive when all upload files were filtered out (jfrog#2432
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sverdlov93 authored Feb 14, 2024
1 parent 2d641f3 commit 073387d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
go-version: 1.20.x
# Due to a bug in Python 3.12.0 we temporary use version 3.11.5
- name: Setup Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11.5"
- name: Setup Pipenv
Expand Down
31 changes: 30 additions & 1 deletion artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
biutils "github.com/jfrog/build-info-go/utils"

"github.com/buger/jsonparser"
"github.com/jfrog/archiver/v3"
gofrogio "github.com/jfrog/gofrog/io"
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
Expand Down Expand Up @@ -59,7 +60,6 @@ import (
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/jfrog/jfrog-client-go/utils/log"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/mholt/archiver/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -4204,6 +4204,35 @@ func TestUploadZipAndCheckDeploymentViewWithArchive(t *testing.T) {

}

func TestUploadEmptyArchiveWithEmptyArchiveEnv(t *testing.T) {
initArtifactoryTest(t, "")

// Create tmp dir
assert.NoError(t, os.Mkdir(tests.Out, 0755))
wd, err := os.Getwd()
assert.NoError(t, err)
defer cleanArtifactoryTest()
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, tests.Out)
defer chdirCallback()

// Create file and a zip
zipName := "test.zip"

setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, services.JfrogCliUploadEmptyArchiveEnv, "true")
defer setEnvCallBack()

// Upload & download zip file
assert.NoError(t, artifactoryCli.Exec("upload", "*", path.Join(tests.RtRepo1, zipName), "--exclusions", "**", "--archive", "zip"))
assert.NoError(t, artifactoryCli.Exec("download", path.Join(tests.RtRepo1, zipName)))

// Check that the zip file uploaded and it's empty
assert.FileExists(t, zipName)
r, err := zip.OpenReader(zipName)
assert.NoError(t, err)
defer func() { assert.NoError(t, r.Close()) }()
assert.Empty(t, r.File)
}

func TestUploadDetailedSummary(t *testing.T) {
initArtifactoryTest(t, "")
uploadCmd := generic.NewUploadCommand()
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/upload/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/jfrog/jfrog-cli/docs/common"
var Usage = []string{"rt u [command options] <source pattern> <target pattern>",
"rt u --spec=<File Spec path> [command options]"}

var EnvVar = []string{common.JfrogCliMinChecksumDeploySizeKb, common.JfrogCliFailNoOp}
var EnvVar = []string{common.JfrogCliMinChecksumDeploySizeKb, common.JfrogCliFailNoOp, common.JfrogCliUploadEmptyArchive}

func GetDescription() string {
return "Upload files."
Expand Down
6 changes: 6 additions & 0 deletions docs/common/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"github.com/jfrog/jfrog-client-go/artifactory/services"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
Expand Down Expand Up @@ -80,6 +81,10 @@ const (
Set to true if you'd like the command to return exit code 2 in case of no files are affected.
Support by the following commands: copy, delete, delete-props, set-props, download, move, search and upload`

JfrogCliUploadEmptyArchive = ` ` + services.JfrogCliUploadEmptyArchiveEnv + `
[Default: false]
Set to true if you'd like to upload an empty archive when '--archive' is set but all files were excluded by exclusions pattern. `

JfrogCliEncryptionKey = ` JFROG_CLI_ENCRYPTION_KEY
If provided, encrypt the sensitive data stored in the config with the provided key. Must be exactly 32 characters.`

Expand Down Expand Up @@ -119,6 +124,7 @@ func GetGlobalEnvVars() string {
JfrogCliReleasesRepo,
JfrogCliDependenciesDir,
JfrogCliMinChecksumDeploySizeKb,
JfrogCliUploadEmptyArchive,
JfrogCliBuildUrl,
JfrogCliEnvExclude,
JfrogCliFailNoOp,
Expand Down
37 changes: 18 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ require (
github.com/buger/jsonparser v1.1.1
github.com/go-git/go-git/v5 v5.11.0
github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a
github.com/jfrog/archiver/v3 v3.6.0
github.com/jfrog/build-info-go v1.9.21
github.com/jfrog/gofrog v1.5.1
github.com/jfrog/jfrog-cli-core/v2 v2.47.11
github.com/jfrog/jfrog-cli-security v0.0.0-20240122124933-edf9cb4ca3ac
github.com/jfrog/jfrog-client-go v1.36.0
github.com/jszwec/csvutil v1.9.0
github.com/mholt/archiver/v3 v3.5.1
github.com/jfrog/gofrog v1.6.0
github.com/jfrog/jfrog-cli-core/v2 v2.47.12
github.com/jfrog/jfrog-cli-security v1.0.1
github.com/jfrog/jfrog-client-go v1.36.1
github.com/jszwec/csvutil v1.10.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.23.0
github.com/urfave/cli v1.22.14
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
golang.org/x/term v0.16.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/term v0.17.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -59,12 +59,11 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jedib0t/go-pretty/v6 v6.5.3 // indirect
github.com/jfrog/archiver/v3 v3.6.0 // indirect
github.com/jedib0t/go-pretty/v6 v6.5.4 // indirect
github.com/jfrog/jfrog-apps-config v1.0.1 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
Expand Down Expand Up @@ -116,13 +115,13 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand All @@ -131,11 +130,11 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240204105703-557f7a17d7f9
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240214142246-bb1e61c953ac

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240204105421-dd3f7041f3df
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240214141548-6691c4323f52

// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v0.0.0-20240122124933-edf9cb4ca3ac
replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.0.2-0.20240214091334-d8ecf2a2cf76

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231220102935-c8776c613ad8

Expand Down
Loading

0 comments on commit 073387d

Please sign in to comment.