Skip to content

Commit

Permalink
Adding 'operation' flag for release bundle promote command
Browse files Browse the repository at this point in the history
  • Loading branch information
oshratZairi committed Feb 16, 2025
1 parent 34354c4 commit c6ea9d8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,16 @@ require (

replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.1.13-0.20250212084027-746cc7ae6a63

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250212021126-e5223ab616af
//replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250212021126-e5223ab616af

//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250205140905-08198f526976

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241220065541-91828d43d8b9

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev

//replace github.com/jfrog/jfrog-cli-core/v2 => ../jfrog-cli-core

replace github.com/jfrog/jfrog-client-go => github.com/oshratZairi/jfrog-client-go v0.0.0-20250216115008-a06b0a541670

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/oshratZairi/jfrog-cli-core/v2 v2.31.1-0.20250216122737-f1b83d2faf90
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,10 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-artifactory v0.1.13-0.20250212084027-746cc7ae6a63 h1:OaDd/sz00/89jzrrTnCePnjFj0qzPUy5INXSEyR/3Zg=
github.com/jfrog/jfrog-cli-artifactory v0.1.13-0.20250212084027-746cc7ae6a63/go.mod h1:llrtIDDeRoO0MmyT9shlBA74rTlaU0aJYS9JXj72F2Q=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250212021126-e5223ab616af h1:XnyhhyARP1YCzYGdhk8ovpyZV+hSchiTGVTuejrZXsI=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250212021126-e5223ab616af/go.mod h1:Hx2houXADsNv0eRh4w5XCS2uSsPNPn1OmiSDdwGFB7g=
github.com/jfrog/jfrog-cli-platform-services v1.7.0 h1:u0AOyG4JX3VT7xhEeA9gDpBgW8tYILONpQURtzR3FkI=
github.com/jfrog/jfrog-cli-platform-services v1.7.0/go.mod h1:u3lMRG7XC8MeUy/OPkHkZnsgCMIi0br4sjk2/W1Pm8I=
github.com/jfrog/jfrog-cli-security v1.15.0 h1:TYNIID231X/AivYtptDCF25JyH8qTQht6ISHRfwejL8=
github.com/jfrog/jfrog-cli-security v1.15.0/go.mod h1:WyXj2D0zBfF6gbdufgt/DWGTA0Qr2dyRMwIqr21t0bc=
github.com/jfrog/jfrog-client-go v1.50.0 h1:t7v/zpLkPomHR6ZjVbPQ1WPQJd9IFKESK9Tt6phZz3k=
github.com/jfrog/jfrog-client-go v1.50.0/go.mod h1:xHxwKBjPSUBd/FyCWgusfHmSWKUZTkfOZkTmntC2F5Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI=
Expand Down Expand Up @@ -285,6 +281,10 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/oshratZairi/jfrog-cli-core/v2 v2.31.1-0.20250216122737-f1b83d2faf90 h1:52tu4x3m860GMBHNzJ4ykT1Uywx5tmo2CQTudjoEIlE=
github.com/oshratZairi/jfrog-cli-core/v2 v2.31.1-0.20250216122737-f1b83d2faf90/go.mod h1:XNsth0jdk/uewfTp8OCWSqBkm0480aVDTzrRI1UhOBs=
github.com/oshratZairi/jfrog-client-go v0.0.0-20250216115008-a06b0a541670 h1:3BOq28ewTiOtXoY949NOsBL0HyjEImfmKrwiwh6n7UQ=
github.com/oshratZairi/jfrog-client-go v0.0.0-20250216115008-a06b0a541670/go.mod h1:xHxwKBjPSUBd/FyCWgusfHmSWKUZTkfOZkTmntC2F5Y=
github.com/owenrumney/go-sarif v1.1.1/go.mod h1:dNDiPlF04ESR/6fHlPyq7gHKmrM0sHUvAGjsoh8ZH0U=
github.com/owenrumney/go-sarif/v2 v2.3.0 h1:wP5yEpI53zr0v5cBmagXzLbHZp9Oylyo3AJDpfLBITs=
github.com/owenrumney/go-sarif/v2 v2.3.0/go.mod h1:MSqMMx9WqlBSY7pXoOZWgEsVB4FDNfhcaXDA1j6Sr+w=
Expand Down
3 changes: 2 additions & 1 deletion lifecycle/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ func promote(c *cli.Context) error {
promoteCmd := lifecycle.NewReleaseBundlePromoteCommand().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)).
SetReleaseBundleVersion(c.Args().Get(1)).SetEnvironment(c.Args().Get(2)).SetSigningKeyName(c.String(cliutils.SigningKey)).
SetSync(c.Bool(cliutils.Sync)).SetReleaseBundleProject(cliutils.GetProject(c)).
SetIncludeReposPatterns(splitRepos(c, cliutils.IncludeRepos)).SetExcludeReposPatterns(splitRepos(c, cliutils.ExcludeRepos))
SetIncludeReposPatterns(splitRepos(c, cliutils.IncludeRepos)).SetExcludeReposPatterns(splitRepos(c, cliutils.ExcludeRepos)).
SetPromotionType(c.String(cliutils.PromotionType))
return commands.Exec(promoteCmd)
}

Expand Down
45 changes: 39 additions & 6 deletions lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
const (
artifactoryLifecycleMinVersion = "7.68.3"
signingKeyOptionalArtifactoryMinVersion = "7.104.1"
promotionTypeFlagArtifactoryMinVersion = "7.106.1"
gpgKeyPairName = "lc-tests-key-pair"
lcTestdataPath = "lifecycle"
releaseBundlesSpec = "release-bundles-spec.json"
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestLifecycleFullFlow(t *testing.T) {
defer deleteReleaseBundle(t, lcManager, tests.LcRbName3, number3)

// Promote the last release bundle to prod repo 1.
promoteRb(t, lcManager, number3)
promoteRb(t, lcManager, tests.LcRbName3, number3, tests.RtProdRepo1)

// Assert the artifacts of both the initial release bundles made it to prod repo 1.
assertExpectedArtifacts(t, tests.SearchAllProdRepo1, tests.GetExpectedLifecycleArtifacts())
Expand Down Expand Up @@ -181,6 +182,22 @@ func TestImportReleaseBundle(t *testing.T) {
assert.Error(t, err)
}

func TestPromoteReleaseBundleWithPromotionTypeFlag(t *testing.T) {
cleanCallback := initLifecycleTest(t, promotionTypeFlagArtifactoryMinVersion)
defer cleanCallback()
lcManager := getLcServiceManager(t)

deleteBuilds := uploadBuilds(t)
defer deleteBuilds()

createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true, false)
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)
assertStatusCompleted(t, lcManager, tests.LcRbName1, number1, "")

promoteRbWithPromotionTypeFlag(t, lcManager, tests.LcRbName1, number1, tests.RtProdRepo1)
assertStatusCompleted(t, lcManager, tests.LcRbName1, number1, "")
}

func deleteExportedReleaseBundle(t *testing.T, rbName string) {
assert.NoError(t, os.RemoveAll(rbName))
}
Expand Down Expand Up @@ -285,16 +302,32 @@ func getOption(option, value string) string {
return fmt.Sprintf("--%s=%s", option, value)
}

func promoteRb(t *testing.T, lcManager *lifecycle.LifecycleServicesManager, rbVersion string) {
output := lcCli.RunCliCmdWithOutput(t, "rbp", tests.LcRbName3, rbVersion, prodEnvironment,
func promoteRbCommon(t *testing.T, lcManager *lifecycle.LifecycleServicesManager, rbName, rbVersion, promoteRepo, promotionType string) {
cmdArgs := []string{"rbp", rbName, rbVersion, prodEnvironment,
getOption(cliutils.SigningKey, gpgKeyPairName),
getOption(cliutils.IncludeRepos, tests.RtProdRepo1),
"--project=default")
getOption(cliutils.IncludeRepos, promoteRepo),
"--project=default"}

// Include promotion type if specified
if promotionType != "" {
cmdArgs = append(cmdArgs, getOption(cliutils.PromotionType, promotionType))
}

output := lcCli.RunCliCmdWithOutput(t, cmdArgs...)

var promotionResp services.RbPromotionResp
if !assert.NoError(t, json.Unmarshal([]byte(output), &promotionResp)) {
return
}
assertStatusCompleted(t, lcManager, tests.LcRbName3, rbVersion, promotionResp.CreatedMillis.String())
assertStatusCompleted(t, lcManager, rbName, rbVersion, promotionResp.CreatedMillis.String())
}

func promoteRb(t *testing.T, lcManager *lifecycle.LifecycleServicesManager, rbName, rbVersion, promoteTo string) {
promoteRbCommon(t, lcManager, rbName, rbVersion, promoteTo, "")
}

func promoteRbWithPromotionTypeFlag(t *testing.T, lcManager *lifecycle.LifecycleServicesManager, rbName, rbVersion, promoteTo string) {
promoteRbCommon(t, lcManager, rbName, rbVersion, promoteTo, "move")
}

func getSpecFile(fileName string) (string, error) {
Expand Down
7 changes: 6 additions & 1 deletion utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ const (
lcIncludeRepos = lifecyclePrefix + IncludeRepos
lcExcludeRepos = lifecyclePrefix + ExcludeRepos
setupRepo = repo
PromotionType = "promotion-type"
)

var flagsMap = map[string]cli.Flag{
Expand Down Expand Up @@ -1721,6 +1722,10 @@ var flagsMap = map[string]cli.Flag{
Name: repo,
Usage: "[Optional] Specifies the Artifactory repository name for the selected package manager, replacing the interactive repository selection.` `",
},
PromotionType: cli.StringFlag{
Name: PromotionType,
Usage: "[Default: copy] Specifies promotion type. [Valid values: move / copy]` `",
},
}

var commandFlags = map[string][]string{
Expand Down Expand Up @@ -2001,7 +2006,7 @@ var commandFlags = map[string][]string{
specFlag, specVars, BuildName, BuildNumber,
},
ReleaseBundlePromote: {
platformUrl, user, password, accessToken, serverId, lcSigningKey, lcSync, lcProject, lcIncludeRepos, lcExcludeRepos,
platformUrl, user, password, accessToken, serverId, lcSigningKey, lcSync, lcProject, lcIncludeRepos, lcExcludeRepos, PromotionType,
},
ReleaseBundleDistribute: {
platformUrl, user, password, accessToken, serverId, lcProject, DistRules, site, city, countryCodes,
Expand Down

0 comments on commit c6ea9d8

Please sign in to comment.