Skip to content

Commit 60e75c0

Browse files
authored
Re-implement CLI in Go, automate release process (#62)
1 parent 3e36c50 commit 60e75c0

29 files changed

+1016
-1479
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
node_modules/
1+
# Generated files that should never be checked into git
2+
install.sh
3+
linux-amd64/DEBIAN/control
4+
kitura.rb

.npmignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
language: node_js
2-
sudo: required
1+
language: go
2+
go:
3+
- 1.12.x
4+
35
branches:
46
only:
5-
- master
6-
- "/^issue.*$/"
7-
- /^greenkeeper/.*$/
8-
node_js:
9-
- '8'
10-
- '10'
7+
- master
8+
- "/^issue.*$/"
9+
- /^\d+.\d+.\d+$/
10+
1111
os:
12-
- linux
13-
- osx
14-
osx_image: xcode10.2
12+
- linux
13+
- osx
14+
osx_image: xcode11
15+
dist: xenial
16+
sudo: required
17+
18+
script:
19+
- "./build.sh ${TRAVIS_TAG:-0.0.1}"
20+
21+
deploy:
22+
provider: releases
23+
api_key:
24+
secure: Eag3dXonpciJXsxoG7PPF7lvp8v/VVZa9ggWb7mcbdVS1lgS6C6eN2t5B9ziTyZ7G5M8ScN8nVSeTIDBf8mNVgjRQghAhuIf9inblS1OxzbqPOPlAVPLYawCUUnKygpReVQY96UR9+2mWFXJUzt1GvwqVlHcGJE2wMBTR3Feg7Py1Gpmb8DVgMhG+r5UCF9l0m4r2z54NOxfyNlbjXYjIbAqI8IkDtWgYCPsO4qBA7COBkeULXNB2rvK2Vc9UVW0mdV76PbxXTWAEYniFQR3LriUF6lWRu9YP9Swhm3aKQOo1xwUz5inX3VFIfdEf1W/ef3oSQyoGC3e7cAnJl3Ycm2VgcDxaKDhQ5x796fKrPS9YHscBUZ56cy+1VDuMpa++iz4W1/ZroHnYdSHgakSlyAKvfEixUsWqJx62Ylm6JqnAD7VFb4a331oQuB6Rl3rwIfOQQuJFVdvSMwxeeyX97BEfVobusB7AOMkH+ZdOQs0A903BJgfdw598Pbjsni+jSJmGfd3PdQaGNDxXHNY4gRdLloQP9+U7+D/K2bNAl1l4xYfSsnsxEk7iV4sITWtxygB3ttmqOJ9aMfPEnpjErBDChPvgF+seYCbqqvH/ndTWtMTXwRre9Tu+HLjATfxxjkYCIpEnAPHWnxt6OT701g7X0WW9jfAx62vlJFr23I=
25+
file:
26+
- kitura-cli_${TRAVIS_TAG}_amd64.deb
27+
- kitura-cli_${TRAVIS_TAG}_darwin.tar.gz
28+
- install.sh
29+
- kitura.rb
30+
skip_cleanup: true
31+
on:
32+
tags: true
33+
repo: IBM-Swift/kitura-cli

Makefile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
GOCMD=go
2+
GOBUILD=$(GOCMD) build
3+
GOGET=$(GOCMD) get
4+
GOCLEAN=$(GOCMD) clean
5+
GOTEST=$(GOCMD) test
6+
7+
BINARY_NAME=kitura
8+
PACKAGE_NAME=kitura-cli
9+
LINUX_DIR=linux-amd64
10+
LINUX_PATH=/usr/local/bin
11+
LINUX_BINARY=$(LINUX_DIR)$(LINUX_PATH)/$(BINARY_NAME)
12+
MACOS_DIR=darwin-amd64
13+
MACOS_PATH=/
14+
MACOS_BINARY=$(MACOS_DIR)$(MACOS_PATH)/$(BINARY_NAME)
15+
16+
GOPATH=$(HOME)/kitura-cli-$(RELEASE)
17+
KITURA_SRC=$(GOPATH)/src/kitura
18+
19+
# Handle additional param for sed -i on Darwin
20+
SED_FLAGS=
21+
UNAME_S := $(shell uname -s)
22+
ifeq ($(UNAME_S),Darwin)
23+
SED_FLAGS := ""
24+
endif
25+
26+
all: build package
27+
build: build-linux build-darwin
28+
package: package-linux package-darwin
29+
clean:
30+
$(GOCLEAN)
31+
rm -f install.sh
32+
rm -f $(LINUX_DIR)/DEBIAN/control
33+
rm -rf $(LINUX_DIR)/usr
34+
rm -rf $(MACOS_DIR)
35+
36+
setup:
37+
# Check RELEASE is set
38+
ifndef RELEASE
39+
$(error RELEASE is not set)
40+
endif
41+
42+
# Copy kitura/cmd module into GOPATH
43+
mkdir -p $(KITURA_SRC)
44+
cp -R -p cmd $(KITURA_SRC)
45+
# Replace release placeholders in sources
46+
cp install.sh.ver install.sh
47+
cp kitura.rb.ver kitura.rb
48+
cp $(LINUX_DIR)/DEBIAN/control.ver $(LINUX_DIR)/DEBIAN/control
49+
sed -i $(SED_FLAGS) -e"s#@@RELEASE@@#$(RELEASE)#g" install.sh $(LINUX_DIR)/DEBIAN/control $(KITURA_SRC)/cmd/root.go kitura.rb
50+
deps:
51+
# Install dependencies
52+
$(GOGET) github.com/spf13/cobra/cobra
53+
$(GOGET) gopkg.in/src-d/go-git.v4/...
54+
55+
build-linux: setup deps
56+
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(LINUX_BINARY) -v
57+
58+
build-darwin: setup deps
59+
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(MACOS_BINARY) -v
60+
61+
test:
62+
cd $(KITURA_SRC)
63+
$(GOTEST) kitura/cmd
64+
65+
package-linux: build-linux
66+
cp -R -p $(LINUX_DIR) $(PACKAGE_NAME)_$(RELEASE)
67+
chmod -R 755 $(LINUX_DIR)$(LINUX_PATH)
68+
dpkg-deb --build $(PACKAGE_NAME)_$(RELEASE)
69+
mv $(PACKAGE_NAME)_$(RELEASE).deb $(PACKAGE_NAME)_$(RELEASE)_amd64.deb
70+
rm -r $(PACKAGE_NAME)_$(RELEASE)
71+
72+
package-darwin-tar: build-darwin
73+
tar -czf $(PACKAGE_NAME)_$(RELEASE)_darwin.tar.gz $(MACOS_DIR)
74+
75+
package-darwin: package-darwin-tar
76+
# This syntax defines SHA_VALUE at rule execution time.
77+
# Note: separate rule to delay evaluation until tar.gz has been written
78+
$(eval SHA_VALUE := $(shell shasum -a 256 $(PACKAGE_NAME)_$(RELEASE)_darwin.tar.gz | cut -d' ' -f1))
79+
sed -i $(SED_FLAGS) -e"s#@@SHA256@@#$(SHA_VALUE)#" kitura.rb

README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,56 @@
11
# Kitura command-line interface
22

3-
This Node.js package provides a `kitura` command-line interface, to simplify the process of creating [Kitura](https://github.com/IBM-Swift/Kitura) applications.
3+
This Go package provides a `kitura` command-line interface, to simplify the process of creating [Kitura](https://github.com/IBM-Swift/Kitura) applications.
44

5-
## Installation via Homebrew
5+
## Installation on macOS (via Homebrew)
66

7+
Kitura's CLI may be installed using [Homebrew](https://brew.sh):
78
```
89
$ brew tap ibm-swift/kitura
910
$ brew install kitura
1011
```
1112

12-
Installing via Homebrew will also install the latest version of Node.js on your system.
13-
14-
## Installation via NPM
13+
## Installation (simple)
1514

15+
You can install (either on Mac or Linux) with this one-liner:
1616
```
17-
$ npm install -g kitura-cli
17+
$ curl -fsSL https://github.com/IBM-Swift/kitura-cli/releases/latest/download/install.sh | sudo bash
1818
```
19+
The `kitura` binary will be placed in your `/usr/local/bin` directory.
1920

20-
> If you encounter permissions errors such as `ENOENT` you may need to make changes to your NPM configuration. See [here](https://docs.npmjs.com/getting-started/fixing-npm-permissions) for further details.
21+
## Installation (manual)
2122

22-
## Usage
23+
If you'd prefer not to use a script, the binary can be installed manually by downloading the release binary from GitHub. In the following commands, substitute `<release>` for the version of the CLI you are installing.
2324

25+
On Mac:
26+
```
27+
$ curl -LO https://github.com/IBM-Swift/kitura-cli/releases/download/<release>/kitura-cli_<release>_darwin.tar.gz
28+
$ tar -xzf kitura-cli_<release>_darwin.tar.gz
29+
$ sudo mv darwin-amd64/kitura /usr/local/bin/
2430
```
25-
$ kitura
26-
27-
Usage: kitura [options] [command]
28-
29-
Kitura command-line interface
30-
31-
32-
Options:
33-
34-
-V, --version output the version number
35-
-h, --help output usage information
3631

32+
On Linux:
33+
```
34+
curl -LO https://github.com/IBM-Swift/kitura-cli/releases/download/<release>/kitura-cli_<release>_amd64.deb
35+
sudo dpkg -i kitura-cli_<release>_amd64.deb
36+
```
3737

38-
Commands:
38+
## Usage
3939

40-
build build the project in a local container
41-
create interactively create a Kitura project
42-
idt install IBM Cloud Developer Tools
43-
init scaffold a bare-bones Kitura project
44-
kit print Cocoapods boilerplate for KituraKit
45-
run run the project in a local container
46-
help [cmd] display help for [cmd]
40+
```
41+
Usage:
42+
kitura [command]
43+
44+
Available Commands:
45+
build Build the project in a local container
46+
help Help about any command
47+
idt Install IBM Cloud Developer Tools
48+
init Initialize a Kitura project
49+
run Run the project in a local container.
50+
51+
Flags:
52+
-h, --help help for kitura
53+
-v, --version Prints the kitura-cli version number.
4754
```
4855

4956
## Release process

Release-Process.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
## kitura-cli Release Process
22

3-
The following instructions are for releasing a new version of kitura-cli on both npm and homebrew:
3+
The following instructions are for releasing a new version of kitura-cli:
44

5+
- Tag the release using the format `0.0.17`, which will trigger a build.
6+
- Travis will then execute `build.sh <TAG>`, building and packaging the binary.
7+
- Travis will attach the `kitura-cli_0.0.17_amd64.deb`, `kitura-cli_0.0.17_darwin.tar.gz`, `install.sh` and `kitura.rb` files to the release.
58

6-
**Make sure you run `npm test` on your changes before creating a PR.**
7-
8-
Once your PR has been merged:
9-
10-
### npm
11-
12-
- Run `npm version patch` (or replace 'patch' with 'major'/'minor' based on your changes).
13-
- Check that the right version has been created by running `git tag` and making sure the new version is listed.
14-
- Run `git status` and `git diff <commit hash of previous commit>` to check that the version has been updated by npm in the project. You can find the previous commit hash by using `git log`.
15-
- If everything looks ok, switch to a new branch by running `git checkout -b update-version` and run `git push` to push the update version changes.
16-
- Run `git push --tags`.
17-
- Raise and merge the PR with your tag changes.
18-
- `git checkout master && git pull` to make sure you have the updated code.
19-
- Run `npm publish`. You'll need to log in using `npm adduser` and make sure you are a collaborator on https://www.npmjs.com/package/kitura-cli/).
20-
- Check to make sure the [npm package](https://www.npmjs.com/package/kitura-cli/) has been updated.
21-
22-
### homebrew
9+
### Updating homebrew
2310

2411
- Clone https://github.com/IBM-Swift/homebrew-kitura and create a new branch.
25-
- In `kitura.rb` change the strings specified by `url` and `version` to match the new version you've just uploaded to npm.
26-
- Download the new .tgz file specified by `url` and run `shasum -a 256 <name of .tgz file>`. Change then string specified by `sha256` to the the hash that came out of running this command.
12+
- Replace the `kitura.rb` file with the one that is attached to the release.
2713
- Push your changes, then raise and merge the PR.
2814
- Update your version of the cli by running `brew upgrade kitura` and do a final check to make sure your updates are running as expected.

build.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
if [ -z "$1" ]; then
5+
echo "Usage: build.sh <release>"
6+
echo " - where <release> is a SemVer version in the format x.y.z"
7+
exit 1
8+
fi
9+
10+
export RELEASE=$1
11+
12+
function failCmdFound() {
13+
echo "Error - 'kitura' command already exists"
14+
echo "Existing kitura --version: `kitura --version`"
15+
exit 1
16+
}
17+
18+
function test_Darwin() {
19+
# Todo: Test brew installation
20+
# Check that command does not already exist
21+
kitura && failCmdFound || echo "Command 'kitura' not found - OK"
22+
# Check reported CLI version matches our release
23+
cliVersion=`./darwin-amd64/kitura --version`
24+
if [ "$cliVersion" == $RELEASE ]; then
25+
echo "kitura --version reports $cliVersion - OK"
26+
else
27+
echo "Error - kitura --version reports $cliVersion, expected $RELEASE"
28+
exit 1
29+
fi
30+
# Check that kitura init successfully produces a project
31+
./darwin-amd64/kitura init --dir TestProj
32+
rm -rf TestProj
33+
}
34+
35+
function test_Linux() {
36+
# Check that command does not already exist
37+
kitura && failCmdFound || echo "Command 'kitura' not found - OK"
38+
sudo dpkg -i kitura-cli_${RELEASE}_amd64.deb
39+
# Check reported CLI version matches our release
40+
cliVersion=`kitura --version`
41+
if [ "$cliVersion" == $RELEASE ]; then
42+
echo "kitura --version reports $cliVersion - OK"
43+
else
44+
echo "Error - kitura --version reports $cliVersion, expected $RELEASE"
45+
exit 1
46+
fi
47+
# Check that kitura init successfully produces a project
48+
kitura init --dir TestProj
49+
rm -rf TestProj
50+
}
51+
52+
case `uname` in
53+
Darwin)
54+
make build-darwin package-darwin
55+
test_Darwin
56+
;;
57+
Linux)
58+
make
59+
test_Linux
60+
;;
61+
*)
62+
echo "Unsupported OS: `uname`"
63+
exit 1
64+
esac

cmd/build.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"bufio"
19+
"fmt"
20+
"os/exec"
21+
22+
"github.com/spf13/cobra"
23+
)
24+
25+
// buildCmd represents the build command
26+
var buildCmd = &cobra.Command{
27+
Use: "build",
28+
Short: "Build the project in a local container",
29+
Long: `Builds your project in a local container. You must have the IBM Developer Tools installed to run this command.
30+
If you do not have the IBM Developer Tools installed you can run 'kitura idt' to install them.`,
31+
Run: func(cmd *cobra.Command, args []string) {
32+
33+
devBuild := exec.Command("ibmcloud", "dev", "build")
34+
35+
stdOut, _ := devBuild.StdoutPipe()
36+
devBuild.Start()
37+
38+
scanner := bufio.NewScanner(stdOut)
39+
40+
for scanner.Scan() {
41+
m := scanner.Text()
42+
fmt.Println(m)
43+
}
44+
45+
err := devBuild.Wait()
46+
if err != nil {
47+
println("Error: failed to run IBM Cloud Developer Tools")
48+
println("Run 'kitura idt' to install")
49+
}
50+
51+
},
52+
}
53+
54+
func init() {
55+
rootCmd.AddCommand(buildCmd)
56+
57+
// Here you will define your flags and configuration settings.
58+
59+
// Cobra supports Persistent Flags which will work for this command
60+
// and all subcommands, e.g.:
61+
// buildCmd.PersistentFlags().String("foo", "", "A help for foo")
62+
63+
// Cobra supports local flags which will only run when this command
64+
// is called directly, e.g.:
65+
// buildCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
66+
}

0 commit comments

Comments
 (0)