-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Add gbm cli tool with checklist rendering command (#146)
* Initial commit for the gbm cli * Add Pull Request support to the cli tool (#118) * Add initial gh tools with failng tests * Add repo package * Add GetPr function * Add error return to getOrg * Add CreatePr function * Add UpdatePr * Add AddLabels function * Refactor AddLabels to suppor removing labels * Add RemoveLabels * Update labels when creating or updateing a PR: * Add comment --------- Co-authored-by: jhnstn <[email protected]> * Add ability to search prs (#119) Co-authored-by: jhnstn <[email protected]> * Add git helpers (#120) Co-authored-by: jhnstn <[email protected]> * CLI Add template renderer (#121) * Add template renderer * Hook root template directory into project main --------- Co-authored-by: jhnstn <[email protected]> * Add render checklist command (#122) * Add some gbm helpers * Add initial command render checklist * Update render package to accept custom functions * Update root render command message Add add empty bin dir --------- Co-authored-by: jhnstn <[email protected]> * Add missing templates * Add ValidateVersion function * Validate the version before running the checklist generator * Fix version in 'Incoming Changes' section * Fix markdown format in quote blocks Also use a group to tighten up the vertical spacing * Add host version flag for patch releases * Update apps infrastructure slack channel name * Add changes from PR #143 * Add check Aztec flow Also reorg the internal library code * Update task partial render helper Also add a checkeck task helper * Hide Aztec steps if Aztec is valid * Move Aztec steps to a seperate file * Add console package for handling cli output and exits * Add standalone aztec steps generator * Don't need the internal packages yet * tidy up go mod * Refactor render to use struct data * Resolve typos with release checklist --------- Co-authored-by: Derek Blank <[email protected]>
- Loading branch information
1 parent
462b34c
commit 4f20f6c
Showing
23 changed files
with
988 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package render | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wordpress-mobile/gbm-cli/pkg/console" | ||
) | ||
|
||
var AztecCmd = &cobra.Command{ | ||
Use: "aztec", | ||
Short: "Render the steps for upgrading Aztec", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
result, err := renderAztecSteps(false) | ||
|
||
console.ExitIfError(err) | ||
|
||
if writeToClipboard { | ||
console.Clipboard(result) | ||
} else { | ||
console.Out(result) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/wordpress-mobile/gbm-cli/pkg/console" | ||
"github.com/wordpress-mobile/gbm-cli/pkg/gbm" | ||
"github.com/wordpress-mobile/gbm-cli/pkg/render" | ||
) | ||
|
||
var version string | ||
var hostVersion string | ||
var message string | ||
var releaseDate string | ||
var checkAztec bool | ||
|
||
type templateData struct { | ||
Version string | ||
Scheduled bool | ||
Date string | ||
Message string | ||
ReleaseUrl string | ||
HostVersion string | ||
IncludeAztec bool | ||
CheckAztec bool | ||
} | ||
|
||
// checklistCmd represents the checklist command | ||
var ChecklistCmd = &cobra.Command{ | ||
Use: "checklist", | ||
Short: "Render the content for the release checklist", | ||
Long: ` | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
vv := gbm.ValidateVersion(version) | ||
if !vv { | ||
console.ExitError(1, "%v is not a valid version. Versions must have a `Major.Minor.Patch` form", version) | ||
} | ||
|
||
// For now let's assume we should include the Aztec steps unless explicitly checking if the versions are valid. | ||
// We'll render the aztec steps with the optional | ||
includeAztec := true | ||
if checkAztec { | ||
includeAztec = !gbm.ValidateAztecVersions() | ||
|
||
if includeAztec { | ||
console.Info("Aztec is not set to a stable version. Including the Update Aztec steps.") | ||
} | ||
} | ||
|
||
scheduled := gbm.IsScheduledRelease(version) | ||
|
||
if releaseDate == "" { | ||
releaseDate = gbm.NextReleaseDate() | ||
} | ||
|
||
releaseUrl := fmt.Sprintf("https://github.com/wordpress-mobile/gutenberg-mobile/releases/new?tag=v%s&target=release/%s&title=Release+%s", version, version, version) | ||
|
||
t := render.Template{ | ||
Path: "templates/checklist/checklist.html", | ||
Funcs: template.FuncMap{"RenderAztecSteps": renderAztecSteps}, | ||
Data: templateData{ | ||
Version: version, | ||
Scheduled: scheduled, | ||
ReleaseUrl: releaseUrl, | ||
Date: releaseDate, | ||
HostVersion: hostVersion, | ||
IncludeAztec: includeAztec, | ||
CheckAztec: checkAztec, | ||
}, | ||
} | ||
|
||
result, err := render.RenderTasks(t) | ||
console.ExitIfError(err) | ||
|
||
if writeToClipboard { | ||
console.Clipboard(result) | ||
} else { | ||
console.Out(result) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
ChecklistCmd.Flags().StringVarP(&version, "version", "v", "", "release version") | ||
ChecklistCmd.MarkFlagRequired("version") | ||
ChecklistCmd.Flags().StringVarP(&message, "message", "m", "", "release message") | ||
ChecklistCmd.Flags().StringVarP(&releaseDate, "date", "d", "", "release date") | ||
ChecklistCmd.Flags().BoolVar(&checkAztec, "a", false, "Check if Aztec config is valid before adding the optional update Aztec section") | ||
ChecklistCmd.Flags().StringVarP(&hostVersion, "host-version", "V", "X.XX", "host app version") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package render | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var writeToClipboard bool | ||
|
||
// rootCmd represents the render command | ||
var RenderCmd = &cobra.Command{ | ||
Use: "render", | ||
Short: "Renders various GBM templates", | ||
Long: `Use this command to render: | ||
- Release checklists | ||
- Steps to update Aztec | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
cmd.Help() | ||
os.Exit(0) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
RenderCmd.AddCommand(ChecklistCmd) | ||
RenderCmd.AddCommand(AztecCmd) | ||
RenderCmd.PersistentFlags().BoolVar(&writeToClipboard, "c", false, "Send output to clipboard") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/wordpress-mobile/gbm-cli/pkg/render" | ||
) | ||
|
||
func renderAztecSteps(conditional bool) (string, error) { | ||
return render.RenderTasks(render.Template{ | ||
Path: "templates/checklist/aztec.html", | ||
Json: fmt.Sprintf(`{"conditional": %v}`, conditional), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wordpress-mobile/gbm-cli/cmd/render" | ||
"github.com/wordpress-mobile/gbm-cli/pkg/console" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "gbm", | ||
Short: "Gutenberg Mobile CLI", | ||
} | ||
|
||
func Execute() { | ||
err := rootCmd.Execute() | ||
console.ExitIfError(err) | ||
} | ||
|
||
func init() { | ||
// Add the render command | ||
rootCmd.AddCommand(render.RenderCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module github.com/wordpress-mobile/gbm-cli | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.7.0 | ||
golang.design/x/clipboard v0.7.0 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect | ||
golang.org/x/image v0.6.0 // indirect | ||
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= | ||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.design/x/clipboard v0.7.0 h1:4Je8M/ys9AJumVnl8m+rZnIvstSnYj1fvzqYrU3TXvo= | ||
golang.design/x/clipboard v0.7.0/go.mod h1:PQIvqYO9GP29yINEfsEn5zSQKAz3UgXmZKzDA6dnq2E= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU= | ||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= | ||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= | ||
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4= | ||
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= | ||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= | ||
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c h1:Gk61ECugwEHL6IiyyNLXNzmu8XslmRP2dS0xjIYhbb4= | ||
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY= | ||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= | ||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
|
||
"github.com/wordpress-mobile/gbm-cli/cmd" | ||
"github.com/wordpress-mobile/gbm-cli/pkg/render" | ||
) | ||
|
||
//go:embed templates/* | ||
var templatesFS embed.FS | ||
|
||
func main() { | ||
render.TemplateFS = templatesFS | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package console | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"golang.design/x/clipboard" | ||
) | ||
|
||
func ExitIfError(err error) { | ||
if err != nil { | ||
ExitError(1, err.Error()+"\n") | ||
} | ||
} | ||
|
||
func ExitError(code int, format string, args ...interface{}) { | ||
fmt.Fprintf(os.Stderr, format+"\n", args...) | ||
os.Exit(1) | ||
} | ||
|
||
func Clipboard(m string) { | ||
clipboard.Write(clipboard.FmtText, []byte(m)) | ||
} | ||
|
||
/* | ||
Use Out for printing resulting messages that should be piped. For status logging use console.Info | ||
*/ | ||
func Out(m string) { | ||
fmt.Fprintln(os.Stdout, m) | ||
} | ||
|
||
/* | ||
Use Info to log messages from the scripts. Output is sent to stderr to not muddle up pipe-able output | ||
*/ | ||
func Info(format string, args ...interface{}) { | ||
fmt.Fprintf(os.Stderr, format+"\n", args...) | ||
} |
Oops, something went wrong.