Skip to content

Commit 1a0eec4

Browse files
authored
Add a tree view to artifacts deployment (#1564)
1 parent 2ac0f50 commit 1a0eec4

20 files changed

+443
-139
lines changed

Diff for: artifactory/cli.go

+35-30
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package artifactory
33
import (
44
"errors"
55
"fmt"
6-
"github.com/jfrog/build-info-go/utils/pythonutils"
7-
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python"
86
"io/ioutil"
97
"os"
108
"strconv"
119
"strings"
1210

11+
"github.com/jfrog/build-info-go/utils/pythonutils"
12+
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python"
13+
1314
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/buildinfo"
1415
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/container"
1516
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/curl"
@@ -1040,41 +1041,40 @@ func dockerPromoteCmd(c *cli.Context) error {
10401041
return commands.Exec(dockerPromoteCommand)
10411042
}
10421043

1043-
func containerPushCmd(c *cli.Context, containerManagerType containerutils.ContainerManagerType) error {
1044+
func containerPushCmd(c *cli.Context, containerManagerType containerutils.ContainerManagerType) (err error) {
10441045
if c.NArg() != 2 {
10451046
return cliutils.WrongNumberOfArgumentsHandler(c)
10461047
}
10471048
artDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c)
10481049
if err != nil {
1049-
return err
1050+
return
10501051
}
10511052
imageTag := c.Args().Get(0)
10521053
targetRepo := c.Args().Get(1)
10531054
skipLogin := c.Bool("skip-login")
10541055

10551056
buildConfiguration, err := buildtools.CreateBuildConfigurationWithModule(c)
10561057
if err != nil {
1057-
return err
1058+
return
10581059
}
10591060
dockerPushCommand := container.NewPushCommand(containerManagerType)
10601061
threads, err := cliutils.GetThreadsCount(c)
10611062
if err != nil {
1062-
return err
1063+
return
10631064
}
1064-
dockerPushCommand.SetThreads(threads).SetDetailedSummary(c.Bool("detailed-summary")).SetCmdParams([]string{"push", imageTag}).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetRepo(targetRepo).SetServerDetails(artDetails).SetImageTag(imageTag)
1065+
printDeploymentView, detailedSummary := log.IsTerminal(), c.Bool("detailed-summary")
1066+
dockerPushCommand.SetThreads(threads).SetDetailedSummary(detailedSummary || printDeploymentView).SetCmdParams([]string{"push", imageTag}).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetRepo(targetRepo).SetServerDetails(artDetails).SetImageTag(imageTag)
10651067
err = cliutils.ShowDockerDeprecationMessageIfNeeded(containerManagerType, dockerPushCommand.IsGetRepoSupported)
10661068
if err != nil {
1067-
return err
1069+
return
10681070
}
10691071
err = commands.Exec(dockerPushCommand)
1070-
if err != nil {
1071-
return err
1072-
}
1073-
if dockerPushCommand.IsDetailedSummary() {
1074-
result := dockerPushCommand.Result()
1075-
return cliutils.PrintDetailedSummaryReport(result.SuccessCount(), result.FailCount(), result.Reader(), true, false, err)
1076-
}
1077-
return nil
1072+
result := dockerPushCommand.Result()
1073+
1074+
// Cleanup.
1075+
defer cliutils.CleanupResult(result, &err)
1076+
err = cliutils.PrintCommandSummary(dockerPushCommand.Result(), detailedSummary, printDeploymentView, false, err)
1077+
return
10781078
}
10791079

10801080
func containerPullCmd(c *cli.Context, containerManagerType containerutils.ContainerManagerType) error {
@@ -1263,11 +1263,16 @@ func downloadCmd(c *cli.Context) error {
12631263
// This error is being checked latter on because we need to generate summary report before return.
12641264
err = progressbar.ExecWithProgress(downloadCommand, false)
12651265
result := downloadCommand.Result()
1266-
err = cliutils.PrintDetailedSummaryReport(result.SuccessCount(), result.FailCount(), result.Reader(), false, cliutils.IsFailNoOp(c), err)
1266+
defer cliutils.CleanupResult(result, &err)
1267+
basicSummary, err := cliutils.CreateSummaryReportString(result.SuccessCount(), result.FailCount(), cliutils.IsFailNoOp(c), err)
1268+
if err != nil {
1269+
return err
1270+
}
1271+
err = cliutils.PrintDetailedSummaryReport(basicSummary, result.Reader(), false, err)
12671272
return cliutils.GetCliError(err, result.SuccessCount(), result.FailCount(), cliutils.IsFailNoOp(c))
12681273
}
12691274

1270-
func uploadCmd(c *cli.Context) error {
1275+
func uploadCmd(c *cli.Context) (err error) {
12711276
if c.NArg() > 0 && c.IsSet("spec") {
12721277
return cliutils.PrintHelpAndReturnError("No arguments should be sent when the spec option is used.", c)
12731278
}
@@ -1276,42 +1281,42 @@ func uploadCmd(c *cli.Context) error {
12761281
}
12771282

12781283
var uploadSpec *spec.SpecFiles
1279-
var err error
12801284
if c.IsSet("spec") {
12811285
uploadSpec, err = cliutils.GetFileSystemSpec(c)
12821286
} else {
12831287
uploadSpec, err = createDefaultUploadSpec(c)
12841288
}
12851289
if err != nil {
1286-
return err
1290+
return
12871291
}
12881292
err = spec.ValidateSpec(uploadSpec.Files, true, false)
12891293
if err != nil {
1290-
return err
1294+
return
12911295
}
12921296
cliutils.FixWinPathsForFileSystemSourcedCmds(uploadSpec, c)
12931297
configuration, err := createUploadConfiguration(c)
12941298
if err != nil {
1295-
return err
1299+
return
12961300
}
12971301
buildConfiguration, err := buildtools.CreateBuildConfigurationWithModule(c)
12981302
if err != nil {
1299-
return err
1303+
return
13001304
}
13011305
retries, err := getRetries(c)
13021306
if err != nil {
1303-
return err
1307+
return
13041308
}
13051309
retryWaitTime, err := getRetryWaitTime(c)
13061310
if err != nil {
1307-
return err
1311+
return
13081312
}
13091313
uploadCmd := generic.NewUploadCommand()
13101314
rtDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c)
13111315
if err != nil {
1312-
return err
1316+
return
13131317
}
1314-
uploadCmd.SetUploadConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(uploadSpec).SetServerDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(c.Bool("detailed-summary")).SetRetries(retries).SetRetryWaitMilliSecs(retryWaitTime)
1318+
printDeploymentView, detailedSummary := log.IsTerminal(), c.Bool("detailed-summary")
1319+
uploadCmd.SetUploadConfiguration(configuration).SetBuildConfiguration(buildConfiguration).SetSpec(uploadSpec).SetServerDetails(rtDetails).SetDryRun(c.Bool("dry-run")).SetSyncDeletesPath(c.String("sync-deletes")).SetQuiet(cliutils.GetQuietValue(c)).SetDetailedSummary(detailedSummary || printDeploymentView).SetRetries(retries).SetRetryWaitMilliSecs(retryWaitTime)
13151320

13161321
if uploadCmd.ShouldPrompt() && !coreutils.AskYesNo("Sync-deletes may delete some artifacts in Artifactory. Are you sure you want to continue?\n"+
13171322
"You can avoid this confirmation message by adding --quiet to the command.", false) {
@@ -1320,9 +1325,9 @@ func uploadCmd(c *cli.Context) error {
13201325
// This error is being checked latter on because we need to generate summary report before return.
13211326
err = progressbar.ExecWithProgress(uploadCmd, false)
13221327
result := uploadCmd.Result()
1323-
err = cliutils.PrintDetailedSummaryReport(result.SuccessCount(), result.FailCount(), result.Reader(), true, cliutils.IsFailNoOp(c), err)
1324-
1325-
return cliutils.GetCliError(err, result.SuccessCount(), result.FailCount(), cliutils.IsFailNoOp(c))
1328+
defer cliutils.CleanupResult(result, &err)
1329+
err = cliutils.PrintCommandSummary(uploadCmd.Result(), detailedSummary, printDeploymentView, cliutils.IsFailNoOp(c), err)
1330+
return
13261331
}
13271332

13281333
func prepareCopyMoveCommand(c *cli.Context) (*spec.SpecFiles, error) {

Diff for: artifactory_test.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -3961,7 +3961,7 @@ func testFailNoOpSummaryReport(t *testing.T, failNoOp bool) {
39613961
}
39623962

39633963
func testSummaryReport(t *testing.T, argsMap map[string][]string, expected summaryExpected) {
3964-
buffer, previousLog := tests.RedirectLogOutputToBuffer()
3964+
buffer, _, previousLog := tests.RedirectLogOutputToBuffer()
39653965
// Restore previous logger when the function returns
39663966
defer log.SetLogger(previousLog)
39673967

@@ -3973,6 +3973,18 @@ func testSummaryReport(t *testing.T, argsMap map[string][]string, expected summa
39733973
cleanArtifactoryTest()
39743974
}
39753975

3976+
func TestUploadDeploymentView(t *testing.T) {
3977+
initArtifactoryTest(t, "")
3978+
assertPrintedDeploymentViewFunc, cleanupFunc := initDeploymentViewTest(t)
3979+
defer cleanupFunc()
3980+
uploadCmd := generic.NewUploadCommand()
3981+
fileSpec := spec.NewBuilder().Pattern(filepath.Join("testdata", "a", "a*.in")).Target(tests.RtRepo1).BuildSpec()
3982+
uploadCmd.SetUploadConfiguration(createUploadConfiguration()).SetSpec(fileSpec).SetServerDetails(serverDetails)
3983+
assert.NoError(t, artifactoryCli.Exec("upload", filepath.Join("testdata", "a", "a*.in"), tests.RtRepo1))
3984+
assertPrintedDeploymentViewFunc()
3985+
cleanArtifactoryTest()
3986+
}
3987+
39763988
func TestUploadDetailedSummary(t *testing.T) {
39773989
initArtifactoryTest(t, "")
39783990
uploadCmd := generic.NewUploadCommand()
@@ -4894,7 +4906,7 @@ func TestArtifactoryReplicationCreate(t *testing.T) {
48944906
func TestAccessTokenCreate(t *testing.T) {
48954907
initArtifactoryTest(t, "")
48964908

4897-
buffer, previousLog := tests.RedirectLogOutputToBuffer()
4909+
buffer, _, previousLog := tests.RedirectLogOutputToBuffer()
48984910
// Restore previous logger when the function returns
48994911
defer log.SetLogger(previousLog)
49004912

Diff for: buildinfo_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"github.com/jfrog/jfrog-cli-core/v2/artifactory/formats"
8-
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
97
"io/ioutil"
108
"os"
119
"path/filepath"
1210
"strconv"
1311
"strings"
1412
"testing"
1513

14+
"github.com/jfrog/jfrog-cli-core/v2/artifactory/formats"
15+
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
16+
1617
buildinfo "github.com/jfrog/build-info-go/entities"
1718
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
1819
"github.com/jfrog/jfrog-client-go/utils/log"
@@ -201,7 +202,7 @@ func TestBuildPublishDetailedSummary(t *testing.T) {
201202
// Verify build dir is not empty
202203
assert.NotEmpty(t, getFilesFromBuildDir(t, tests.RtBuildName1, buildNumber, ""))
203204

204-
buffer, previousLog := tests.RedirectLogOutputToBuffer()
205+
buffer, _, previousLog := tests.RedirectLogOutputToBuffer()
205206
// Restore previous logger when the function returns
206207
defer log.SetLogger(previousLog)
207208
// Execute the bp command with --detailed-summary.
@@ -226,7 +227,7 @@ func TestBuildPublishDryRun(t *testing.T) {
226227
// Verify build dir is not empty
227228
assert.NotEmpty(t, getFilesFromBuildDir(t, tests.RtBuildName1, buildNumber, ""))
228229

229-
buffer, previousLog := tests.RedirectLogOutputToBuffer()
230+
buffer, _, previousLog := tests.RedirectLogOutputToBuffer()
230231
// Restore previous logger when the function returns
231232
defer log.SetLogger(previousLog)
232233

0 commit comments

Comments
 (0)