Skip to content

Commit

Permalink
New --operation flag for release bundle promote command (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshratZairi authored Feb 21, 2025
1 parent 97b96b6 commit 8d5750c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
8 changes: 2 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ require (

replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.1.13-0.20250219071539-9bcf054e67db

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.20250221065317-8f044fe71fea

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250219065446-e17342f27e44

// 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-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250221062042-87cb5136765e
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ 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.20250219071539-9bcf054e67db h1:I9ywkE/lXJ/1S/0h2jjEWiqIKzWiJszE0VrjoGsorLk=
github.com/jfrog/jfrog-cli-artifactory v0.1.13-0.20250219071539-9bcf054e67db/go.mod h1:EzlrSRtRoEipL+8axXHfgoUgXEoHZMVA6cElS2xK1w8=
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-core/v2 v2.31.1-0.20250221065317-8f044fe71fea h1:ahP9eFJOw5K3AehHytj1H9nPGpswYfb3paTTwcBtwHg=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250221065317-8f044fe71fea/go.mod h1:VAVY5umw94aXf+yGzKCoEqijeUjIUNv+ikJUeQkd9tw=
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.28.1-0.20250219065446-e17342f27e44 h1:Q2S65q8vk4Yb0B95XGCkcJJCUmJoKsDO5w/A1l6guJ8=
github.com/jfrog/jfrog-client-go v1.28.1-0.20250219065446-e17342f27e44/go.mod h1:hDoUcW6LZme83YNFbdSRImV+di1x0GP+Nlw7fctkwtE=
github.com/jfrog/jfrog-client-go v1.28.1-0.20250221062042-87cb5136765e h1:SGKkXdFJtc5Rb32jh5E55SCLrHXtOTvc9YKy6QwWbzY=
github.com/jfrog/jfrog-client-go v1.28.1-0.20250221062042-87cb5136765e/go.mod h1:hDoUcW6LZme83YNFbdSRImV+di1x0GP+Nlw7fctkwtE=
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
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
38 changes: 31 additions & 7 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,8 +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())
// Assert no artifacts were promoted to prod repo 2.
Expand Down Expand Up @@ -181,6 +181,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, "")

promoteRb(t, lcManager, tests.LcRbName1, number1, tests.RtProdRepo1, "move")
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 +301,24 @@ 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 promoteRb(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 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 @@ -582,6 +582,7 @@ const (
lcIncludeRepos = lifecyclePrefix + IncludeRepos
lcExcludeRepos = lifecyclePrefix + ExcludeRepos
setupRepo = repo
PromotionType = "promotion-type"
)

var flagsMap = map[string]cli.Flag{
Expand Down Expand Up @@ -1726,6 +1727,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 @@ -2006,7 +2011,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 8d5750c

Please sign in to comment.