@@ -20,35 +20,86 @@ import (
2020 "context"
2121 "fmt"
2222 "log"
23+ "sort"
2324 "text/tabwriter"
2425
2526 "cloud.google.com/go/storage"
2627 "github.com/spf13/cobra"
2728 flag "github.com/spf13/pflag"
29+ "golang.org/x/mod/semver"
2830
2931 "github.com/cert-manager/release/pkg/release"
3032)
3133
3234const (
33- stagedCommand = "staged"
34- stagedDescription = "Staged release tarballs to a GCS release bucket"
35- stagedLongDescription = `The staged command will build and staged a cert-manager release to a
36- Google Cloud Storage bucket. It will create a Google Cloud Build job
37- which will run a full cross-build and publish the artifacts to the
38- staging release bucket.
39- `
35+ stagedCommand = "staged"
36+ stagedDescription = "List existing staged releases in the GCS bucket, sorted by version."
4037)
4138
4239var (
43- stagedExample = fmt .Sprintf (`
44- To staged a release of the 'master' branch to the default staging bucket, run:
40+ stagedExample = fmt .Sprint (`
41+ Imagine that you just ran 'cmrel stage', and you now want to run 'cmrel publish',
42+ which requires you to know the "release name" (--release-name).
4543
46- %s %s --git-ref=master
44+ v1.0.0-alpha.1-ae6a747fd4495a24db00ce4c1522c6eac72bc5a4
4745
48- To staged a release of the ' release-0.14' branch to the default staging bucket,
49- overriding the release version as 'v0.14.0' , run:
46+ The " staged" command will help you find this release name. To list the existing
47+ staged releases , run:
5048
51- %s %s --git-ref=release-0.14 --release-version=v0.14.0` , rootCommand , stagedCommand , rootCommand , stagedCommand )
49+ cmrel staged
50+
51+ The output is sorted lexicographically using the version string:
52+
53+ NAME VERSION
54+ v1.0.2-219b7934ac499c7818526597cf635a922bddd22e v1.0.2
55+ v1.0.3-cbd52ed6e9c296012bab87d3877d31e1f1295fa5 v1.0.3
56+ v1.0.4-4d870e49b43960fad974487a262395e65da1373e v1.0.4
57+ v1.1.0-7fbdd6487646e812fe74c0c05503805b5d9d4751 v1.1.0
58+ v1.1.0-alpha.0-09f043d2c96da68ed8d4f2c71a868fe0846d3669 v1.1.0-alpha.0
59+ v1.1.0-alpha.1-fda1c091e3f37046c378bbf832e603284b6db531 v1.1.0-alpha.1
60+ v1.1.1-3ac7418070e22c87fae4b22603a6b952f797ae96 v1.1.1
61+ v1.2.0-969b678f330c68a6429b7a71b271761c59651a85 v1.2.0
62+ v1.2.0-alpha.0-7cef4582ec8e33ff2f3b8dcf15b3f293f6ef82cc v1.2.0-alpha.0
63+ v1.2.0-alpha.1-33f18811909bdd08d39fd8aa3f016734d1393d18 v1.2.0-alpha.1
64+ v1.2.0-alpha.2-35febb171706826f27d71af466c624c25733c135 v1.2.0-alpha.2
65+ v1.3.0-9c42eeebfd3978531b517277a21e28e3cf90b876 v1.3.0
66+ v1.3.0-alpha.0-77b045d159bd20ce0ec454cd79a5edce9187bdd9 v1.3.0-alpha.0
67+ v1.3.0-alpha.1-c2c0fdd78131493707050ffa4a7454885d041b08 v1.3.0-alpha.1
68+ v1.3.0-beta.0-9f612f0c2eee8390fb730b1aafa592b88d768d15 v1.3.0-beta.0
69+ v1.3.1-614438aed00e1060870b273f2238794ef69b60ab v1.3.1
70+ v1.4.0-alpha.1-0ff2b8778c51e6cebe140a6b196e7a9a28cbee87 v1.4.0-alpha.1
71+ v1.4.0-alpha.0-8d794c6bcf3bb02b9961bbd40f5b821f5636cceb v1.4.0-wallrj.1
72+ v1.4.0-wallrj.2-0ff2b8778c51e6cebe140a6b196e7a9a28cbee87 v1.4.0-wallrj.2
73+
74+ If you already know the release version (and since you have run 'cmrel stage',
75+ you probably do), you can select just these versions:
76+
77+ cmrel staged --release-version=v1.3.1
78+
79+ which will only show the releases that you are interested in:
80+
81+ NAME VERSION
82+ v1.3.1-614438aed00e1060870b273f2238794ef69b60ab v1.3.1
83+
84+ The "release name" that you need to pass as --release-name to 'cmrel publish'
85+ is the string:
86+
87+ v1.3.1-614438aed00e1060870b273f2238794ef69b60ab
88+
89+ Note that by default, the command will only show the "release" type, not the
90+ "devel" ones. To see the "devel" staged releases, you need to run:
91+
92+ cmrel staged --release-type=devel
93+
94+ This time, no version will be shown, just the git commit hash:
95+
96+ NAME VERSION
97+ 29406bfaa25c33661ff31b4d60a74f7b04ab6f2d
98+ 3c43140e9e7a6fc04e0e7ba0d50faeaa6aea97df
99+ b95836421f7f3d2bbbebaa4fa3cca7128e3a97ad
100+ dfafd10391b00d65315624dbbdc840d21735b240
101+ ece63038d00e62711443a5abbc0e87b15a1367c1
102+ ` )
52103)
53104
54105type stagedOptions struct {
@@ -72,7 +123,7 @@ func (o *stagedOptions) AddFlags(fs *flag.FlagSet, markRequired func(string)) {
72123 fs .StringVar (& o .Bucket , "bucket" , release .DefaultBucketName , "The name of the GCS bucket containing the staged releases." )
73124 fs .StringVar (& o .GitRef , "git-ref" , "" , "Optional specific git reference to list staged releases for - if specified, --release-version must also be specified." )
74125 fs .StringVar (& o .ReleaseVersion , "release-version" , "" , "Optional release version override used to force the version strings used during the release to a specific value." )
75- fs .StringVar (& o .ReleaseType , "release-type" , "release" , "The type of release to list - usually one of 'release' or 'devel'" )
126+ fs .StringVar (& o .ReleaseType , "release-type" , "release" , "The type of release to list, usually one of 'release' or 'devel'" )
76127}
77128
78129func (o * stagedOptions ) print () {
@@ -88,10 +139,9 @@ func stagedCmd(rootOpts *rootOptions) *cobra.Command {
88139 cmd := & cobra.Command {
89140 Use : stagedCommand ,
90141 Short : stagedDescription ,
91- Long : stagedLongDescription ,
92142 Example : stagedExample ,
93143 SilenceUsage : true ,
94- PreRun : func (cmd * cobra.Command , args []string ) {
144+ PreRun : func (_ * cobra.Command , _ []string ) {
95145 o .print ()
96146 log .Printf ("---" )
97147 },
@@ -103,7 +153,7 @@ func stagedCmd(rootOpts *rootOptions) *cobra.Command {
103153 return cmd
104154}
105155
106- func runStaged (rootOpts * rootOptions , o * stagedOptions ) error {
156+ func runStaged (_ * rootOptions , o * stagedOptions ) error {
107157 if o .ReleaseVersion == "" && o .GitRef != "" {
108158 return fmt .Errorf ("cannot specify --git-ref without --release-version" )
109159 }
@@ -119,10 +169,11 @@ func runStaged(rootOpts *rootOptions, o *stagedOptions) error {
119169 return fmt .Errorf ("failed listing staged releases: %w" , err )
120170 }
121171
122- lines := []string {"NAME\t VERSION\t DATE" }
172+ lines := []string {"NAME\t VERSION" }
173+ sort .Sort (ByVersion (stagedReleases ))
123174 for _ , rel := range stagedReleases {
124175 vers := rel .Metadata ().ReleaseVersion
125- lines = append (lines , fmt .Sprintf ("%s\t %s\t UNKNOWN " , rel .Name (), vers ))
176+ lines = append (lines , fmt .Sprintf ("%s\t %s" , rel .Name (), vers ))
126177 }
127178
128179 logTable (lines ... )
@@ -139,3 +190,11 @@ func logTable(lines ...string) {
139190 }
140191 w .Flush ()
141192}
193+
194+ type ByVersion []release.Staged
195+
196+ func (a ByVersion ) Len () int { return len (a ) }
197+ func (a ByVersion ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
198+ func (a ByVersion ) Less (i , j int ) bool {
199+ return semver .Compare (a [i ].Metadata ().ReleaseVersion , a [j ].Metadata ().ReleaseVersion ) < 0
200+ }
0 commit comments