Skip to content

Commit

Permalink
Add Support for Release Bundles Create and Promote (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Jun 29, 2023
1 parent 33339ad commit 7091558
Show file tree
Hide file tree
Showing 36 changed files with 1,074 additions and 170 deletions.
19 changes: 5 additions & 14 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,7 @@ func createDefaultCopyMoveSpec(c *cli.Context) (*spec.SpecFiles, error) {
Props(c.String("props")).
ExcludeProps(c.String("exclude-props")).
Build(c.String("build")).
Project(getProject(c)).
Project(cliutils.GetProject(c)).
ExcludeArtifacts(c.Bool("exclude-artifacts")).
IncludeDeps(c.Bool("include-deps")).
Bundle(c.String("bundle")).
Expand All @@ -2439,7 +2439,7 @@ func createDefaultDeleteSpec(c *cli.Context) (*spec.SpecFiles, error) {
Props(c.String("props")).
ExcludeProps(c.String("exclude-props")).
Build(c.String("build")).
Project(getProject(c)).
Project(cliutils.GetProject(c)).
ExcludeArtifacts(c.Bool("exclude-artifacts")).
IncludeDeps(c.Bool("include-deps")).
Bundle(c.String("bundle")).
Expand All @@ -2463,7 +2463,7 @@ func createDefaultSearchSpec(c *cli.Context) (*spec.SpecFiles, error) {
Props(c.String("props")).
ExcludeProps(c.String("exclude-props")).
Build(c.String("build")).
Project(getProject(c)).
Project(cliutils.GetProject(c)).
ExcludeArtifacts(c.Bool("exclude-artifacts")).
IncludeDeps(c.Bool("include-deps")).
Bundle(c.String("bundle")).
Expand All @@ -2490,7 +2490,7 @@ func createDefaultPropertiesSpec(c *cli.Context) (*spec.SpecFiles, error) {
Props(c.String("props")).
ExcludeProps(c.String("exclude-props")).
Build(c.String("build")).
Project(getProject(c)).
Project(cliutils.GetProject(c)).
ExcludeArtifacts(c.Bool("exclude-artifacts")).
IncludeDeps(c.Bool("include-deps")).
Bundle(c.String("bundle")).
Expand Down Expand Up @@ -2586,7 +2586,7 @@ func createDefaultDownloadSpec(c *cli.Context) (*spec.SpecFiles, error) {
Props(c.String("props")).
ExcludeProps(c.String("exclude-props")).
Build(c.String("build")).
Project(getProject(c)).
Project(cliutils.GetProject(c)).
ExcludeArtifacts(c.Bool("exclude-artifacts")).
IncludeDeps(c.Bool("include-deps")).
Bundle(c.String("bundle")).
Expand Down Expand Up @@ -2722,12 +2722,3 @@ func getOffsetAndLimitValues(c *cli.Context) (offset, limit int, err error) {

return
}

// Get project key from flag or environment variable
func getProject(c *cli.Context) string {
project := c.String("project")
if project == "" {
project = os.Getenv(coreutils.Project)
}
return project
}
34 changes: 5 additions & 29 deletions artifactory/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package artifactory

import (
"bytes"
"flag"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
"path/filepath"
"strings"
"testing"

"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
"path/filepath"
"testing"
)

func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {
Expand All @@ -34,7 +31,7 @@ func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(t, test.flags, test.args)
context, buffer := tests.CreateContext(t, test.flags, test.args)
funcArray := []func(c *cli.Context) (*spec.SpecFiles, error){
prepareSearchCommand, prepareDownloadCommand, prepareDeleteCommand,
}
Expand Down Expand Up @@ -67,7 +64,7 @@ func TestPrepareCopyMoveCommand(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(t, test.flags, test.args)
context, buffer := tests.CreateContext(t, test.flags, test.args)
specFiles, err := prepareCopyMoveCommand(context)
assertGenericCommand(t, err, buffer, test.expectError, test.expectedPattern, test.expectedBuild, test.expectedBundle, specFiles)
})
Expand Down Expand Up @@ -96,7 +93,7 @@ func TestPreparePropsCmd(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(t, test.flags, test.args)
context, buffer := tests.CreateContext(t, test.flags, test.args)
propsCommand, err := preparePropsCmd(context)
var actualSpec *spec.SpecFiles
if propsCommand != nil {
Expand All @@ -119,27 +116,6 @@ func assertGenericCommand(t *testing.T, err error, buffer *bytes.Buffer, expectE
}
}

func createContext(t *testing.T, testFlags, testArgs []string) (*cli.Context, *bytes.Buffer) {
flagSet := createFlagSet(t, testFlags, testArgs)
app := cli.NewApp()
app.Writer = &bytes.Buffer{}
return cli.NewContext(app, flagSet, nil), &bytes.Buffer{}
}

func getSpecPath(spec string) string {
return filepath.Join("..", "testdata", "filespecs", spec)
}

// Create flag set with input flags and arguments.
func createFlagSet(t *testing.T, flags []string, args []string) *flag.FlagSet {
flagSet := flag.NewFlagSet("TestFlagSet", flag.ContinueOnError)
flags = append(flags, "url=http://127.0.0.1:8081/artifactory")
var cmdFlags []string
for _, curFlag := range flags {
flagSet.String(strings.Split(curFlag, "=")[0], "", "")
cmdFlags = append(cmdFlags, "--"+curFlag)
}
cmdFlags = append(cmdFlags, args...)
assert.NoError(t, flagSet.Parse(cmdFlags))
return flagSet
}
2 changes: 1 addition & 1 deletion artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4549,7 +4549,7 @@ func validateArtifactoryVersion(t *testing.T, minVersion string) {
return
}
if !rtVersion.AtLeast(minVersion) {
t.Skip("Skipping artifactory project test. Artifactory version not supported.")
t.Skip("Skipping test. Artifactory version not supported.")
}
}

Expand Down
12 changes: 6 additions & 6 deletions distribution/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func GetCommands() []cli.Command {
return cliutils.GetSortedCommands(cli.CommandsByName{
{
Name: "release-bundle-create",
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleCreate),
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleV1Create),
Aliases: []string{"rbc"},
Usage: releasebundlecreate.GetDescription(),
HelpName: coreCommonDocs.CreateUsage("ds rbc", releasebundlecreate.GetDescription(), releasebundlecreate.Usage),
Expand All @@ -39,7 +39,7 @@ func GetCommands() []cli.Command {
},
{
Name: "release-bundle-update",
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleUpdate),
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleV1Update),
Aliases: []string{"rbu"},
Usage: releasebundleupdate.GetDescription(),
HelpName: coreCommonDocs.CreateUsage("ds rbu", releasebundleupdate.GetDescription(), releasebundleupdate.Usage),
Expand All @@ -50,7 +50,7 @@ func GetCommands() []cli.Command {
},
{
Name: "release-bundle-sign",
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleSign),
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleV1Sign),
Aliases: []string{"rbs"},
Usage: releasebundlesign.GetDescription(),
HelpName: coreCommonDocs.CreateUsage("ds rbs", releasebundlesign.GetDescription(), releasebundlesign.Usage),
Expand All @@ -61,7 +61,7 @@ func GetCommands() []cli.Command {
},
{
Name: "release-bundle-distribute",
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDistribute),
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleV1Distribute),
Aliases: []string{"rbd"},
Usage: releasebundledistribute.GetDescription(),
HelpName: coreCommonDocs.CreateUsage("ds rbd", releasebundledistribute.GetDescription(), releasebundledistribute.Usage),
Expand All @@ -72,7 +72,7 @@ func GetCommands() []cli.Command {
},
{
Name: "release-bundle-delete",
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDelete),
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleV1Delete),
Aliases: []string{"rbdel"},
Usage: releasebundledelete.GetDescription(),
HelpName: coreCommonDocs.CreateUsage("ds rbdel", releasebundledelete.GetDescription(), releasebundledelete.Usage),
Expand Down Expand Up @@ -328,7 +328,7 @@ func populateReleaseNotesSyntax(c *cli.Context) (distributionServicesUtils.Relea
return distributionServicesUtils.PlainText, errorutils.CheckErrorf("--release-notes-syntax must be one of: markdown, asciidoc or plain_text.")
}
}
// If the file extension is ".md" or ".markdown", use the markdown syntax
// If the file extension is ".md" or ".markdown", use the Markdown syntax
extension := strings.ToLower(filepath.Ext(c.String("release-notes-path")))
if extension == ".md" || extension == ".markdown" {
return distributionServicesUtils.Markdown, nil
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/releasebundlecreate/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Usage = []string{"ds rbc [command options] <release bundle name> <release bu
"ds rbc --spec=<File Spec path> [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Create a release bundle."
return "Create a release bundle v1."
}

func GetArguments() string {
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/releasebundledelete/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package releasebundledelete
var Usage = []string{"ds rbdel [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Delete a release bundle."
return "Delete a release bundle v1."
}

func GetArguments() string {
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/releasebundledistribute/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package releasebundledistribute
var Usage = []string{"ds rbd [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Distribute a release bundle."
return "Distribute a release bundle v1."
}

func GetArguments() string {
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/releasebundlesign/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package releasebundlesign
var Usage = []string{"ds rbs [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Sign a release bundle."
return "Sign a release bundle v1."
}

func GetArguments() string {
Expand Down
2 changes: 1 addition & 1 deletion docs/artifactory/releasebundleupdate/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Usage = []string{"ds rbu [command options] <release bundle name> <release bu
"ds rbu --spec=<File Spec path> [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Updates an existing unsigned release bundle version."
return "Updates an existing unsigned release bundle v1 version."
}

func GetArguments() string {
Expand Down
15 changes: 15 additions & 0 deletions docs/lifecycle/create/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package create

var Usage = []string{"rbc [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Create a release bundle from builds or from existing release bundles"
}

func GetArguments() string {
return ` release bundle name
Name of the newly created Release Bundle.
release bundle version
Version of the newly created Release Bundle.`
}
18 changes: 18 additions & 0 deletions docs/lifecycle/promote/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package promote

var Usage = []string{"rbp [command options] <release bundle name> <release bundle version> <environment>"}

func GetDescription() string {
return "Promote a release bundle"
}

func GetArguments() string {
return ` release bundle name
Name of the Release Bundle to promote.
release bundle version
Version of the Release Bundle to promote.
environment
Name of the target environment for the promotion.`
}
Loading

0 comments on commit 7091558

Please sign in to comment.