Skip to content

Commit

Permalink
[CLI] Update docs and add cli versioning (#218)
Browse files Browse the repository at this point in the history
* Add version to the cli

* Add version check to the root command

* Add more cli tool info to the releasing doc

* remove bin directory from git

* move releasing doc to top level

* Update readme's

* add more info about installing and creating cli releases
  • Loading branch information
jhnstn authored Nov 8, 2023
1 parent c4126c4 commit d000c32
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 460 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

gbm-cli/bin
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
# release-toolkit-gutenberg-mobile
Automation Scripts for Releasing Gutenberg-Mobile Updates to the WordPress Mobile Apps.

## Prerequisites
## GBM-CLI

To be able to run the automation script make sure you have installed:
The preferred automation flow now uses the `gbm-cli` tool. See the tool [README](./gbm-cli/README.md) for more information. Follow the [Installing](./gbm-cli/README.md#installing) section to get started.

### Prerequisites

There are no prerequisites to using the `gbm-cli` tool beyond what is used to develop on Gutenberg Mobile.

It does use the same Github authentication as `gh` so it is recommended to run `gh auth` before using the tool. See [Authentication](./gbm-cli/README.md#authentication) for alternatives.

#### NVM

`nvm` is the recommended node manager for running the `gbm-cli` release commands.

When preparing Gutenberg for a release it is possible to set the global node version to the current version required by Gutenberg.

At the moment this is not possible when preparing a Gutenberg Mobile PR locally since there are multiple node versions during the preparation.

## Legacy Automation Script

### Prerequisites

To be able to run the legacy automation script make sure you have installed:

- [Github CLI](https://github.com/cli/cli)
```sh
Expand All @@ -14,15 +34,15 @@ brew install gh
brew install jq
```

## Usage
### Usage

Run the script: `./release_automation.sh`

## Testing
### Testing

You can test the scripts on forked repos. Please follow the instructions on top of the [release_automation.sh](./release_automation.sh) file.

## Troubleshooting
### Troubleshooting

Occasionally, the script may encounter an error while running. Because the project makes use of a `node_modules` directory within the Gutenberg submodule, it may be useful in some cases to manually install npm dependencies there. By default, running `npm install` (or `npm i`) from within the `gutenberg-mobile` directory will trigger `npm ci` to run within the `gutenberg` directory, but sometimes it may also be helpful to try:

Expand Down
327 changes: 10 additions & 317 deletions Releasing.md

Large diffs are not rendered by default.

52 changes: 44 additions & 8 deletions gbm-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,63 @@ The current features include:
- Command to generate the release checklist
- Commands to wrangle Gutenberg Mobile releases

## Installing
Check the latest release in this repository for the binary builds. Currently we only build for MacOS arm64 (apple silicon). The script has only been tested on apple silicon but build of other platforms should work as expected. See the official [go build](https://go.dev/ref/mod#go-install) documentation for alternative builds.

If using apple silicon, download the `gbm-cli` binary from the [latest release(https://github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/releases)
Place the executable in your PATH and reload your shell. Try

```
$ gbm-cli --version
```

To verify installation.

If `go` (above version `1.21`) is installed you can also use:

```
go install github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli@latest
```

This will build and install the executable in the `GOPATH` on your machine.
Note: Verify that `GOPATH` is set before using this method. If it's not set run `export GOPATH=$HOME/go` before calling `go install`

## Authentication

The tool uses the same Github authentication as [`gh`](https://cli.github.com/). If `gh` is installed and authorized there is no need to do anything else.

Otherwise follow these steps:

1. Create a [personal access token](https://github.blog/2013-05-16-personal-api-tokens/)
2. Export the token under the environment variable `GH_TOKEN`

## Development Environment
1. Download and install the [Go package](https://go.dev/doc/install).
2. While not required, it is higly recommended to develop with [VSCode](https://code.visualstudio.com/) and install the [Go VSCode](https://marketplace.visualstudio.com/items?itemName=golang.go) extension.
1. Download and install the [Go package](https://go.dev/doc/install). Check `go.mod` for the current version of go required (Note: anything below `v1.21` will not work)
2. While not required, it is highly recommended to develop with [VSCode](https://code.visualstudio.com/) and install the [Go VSCode](https://marketplace.visualstudio.com/items?itemName=golang.go) extension.

## Releasing
For detailed instructions on running a release, visit [Releasing.md](https://github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/blob/cli/update-checklist/cli/Releasing.md).

Check the [Releasing](../Releasing.md) doc for more information on creating Gutenberg Mobile releases. Use the following for creating new releases of the CLI tool

When ready to push updates to a new `gbm-cli` version make sure to:
- Increment the version in `./cmd/root.go`
- Merge the PR with the version bump
- Create a new Github Release with the updated version.
- Locally checkout the release tag
- Create a `./bin` directory if you don't have one already
- Run `go build -o ./bin/gbm-cli`
- Add `./bin/gbm-cli` as an artifact to the Github release.

## Testing
For detailed instructions on testing and configuring your development environment, visit [Testing.md](https://github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/blob/cli/update-checklist/cli/Testing.md).



## Structure
The project is setup wth the following directories:

### bin
The `bin` directory is where the executable files generated by the Go build tools are placed.

### cmd
The `cmd` directory defines the various cli commands that make up the CLI took. Under the hood `gbm` uses [go-cobra](https://github.com/spf13/cobra/tree/main).
The `cmd` directory defines the various cli commands that make up the CLI took. Under the hood `gbm` uses [go-cobra](https://github.com/spf13/cobra/tree/main).

### pkg
The packages in `pkg` are intended as the "public" interface for the tool. The are primarily used by the `cmd` packages but could be used by other go projects.
Expand All @@ -39,4 +76,3 @@ For example using the render package:
// this can be called anywhere in the project
checklist := render.Render("template/checklist/checklist.html", data, funcs)
```

128 changes: 0 additions & 128 deletions gbm-cli/Releasing.md

This file was deleted.

Empty file removed gbm-cli/bin/.gitkeep
Empty file.
18 changes: 16 additions & 2 deletions gbm-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@ import (
"github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/cmd/release"
"github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/cmd/render"
"github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/console"
"github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/gh"
)

const Version = "v1.2.0"

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gbm",
Short: "Gutenberg Mobile CLI",
Use: "gbm-cli",
Short: "Gutenberg Mobile CLI",
Version: Version,
}

func Execute() {
err := rootCmd.Execute()
console.ExitIfError(err)

}

func init() {
// Add the render command
rootCmd.AddCommand(render.RenderCmd)
rootCmd.AddCommand(release.ReleaseCmd)

// Check to see if the user is running the latest version
// of the CLI. If not, let them know.
latestRelease, err := gh.GetLatestRelease("release-toolkit-gutenberg-mobile")
console.ExitIfError(err)

if latestRelease.TagName != Version {
console.Warn("You are running an older version of the CLI. Please update to %s", latestRelease.TagName)
}
}
11 changes: 11 additions & 0 deletions gbm-cli/pkg/gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ func GetReleaseByTag(rpo, tag string) (Release, error) {
return release, nil
}

func GetLatestRelease(rpo string) (Release, error) {
org := repo.GetOrg(rpo)
client := getClient()
endpoint := fmt.Sprintf("repos/%s/%s/releases/latest", org, rpo)
release := Release{}
if err := client.Get(endpoint, &release); err != nil {
return Release{}, err
}
return release, nil
}

func GetPrOrg(org, repo string, id int) (*PullRequest, error) {
client := getClient()

Expand Down
3 changes: 3 additions & 0 deletions gbm-cli/pkg/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
const WordPressAndroidRepo = "WordPress-Android"
const WordPressIosRepo = "WordPress-iOS"
const GutenbergMobileRepo = "gutenberg-mobile"
const ReleaseToolkitGutenbergMobileRepo = "release-toolkit-gutenberg-mobile"
const GutenbergRepo = "gutenberg"
const JetpackRepo = "jetpack"

Expand Down Expand Up @@ -51,6 +52,8 @@ func GetOrg(repo string) string {
fallthrough
case WordPressAndroidRepo:
fallthrough
case ReleaseToolkitGutenbergMobileRepo:
fallthrough
case WordPressIosRepo:
return WpMobileOrg
default:
Expand Down

0 comments on commit d000c32

Please sign in to comment.