Skip to content

Commit

Permalink
Fix release process and minor cleanup (#15)
Browse files Browse the repository at this point in the history
nitisht authored Aug 24, 2023
1 parent c25b627 commit a4dc850
Showing 7 changed files with 64 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ config.toml

# build
pb
bin/

# OS Files
.DS_Store
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go $(VERSION))

GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
GO111MODULE=on

all: build

@@ -14,6 +15,7 @@ checks:
@(env bash $(PWD)/buildscripts/checkdeps.sh)

getdeps:
@GO111MODULE=on
@mkdir -p ${GOPATH}/bin
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
@echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest
@@ -41,6 +43,10 @@ build: checks
@echo "Building pb binary to './pb'"
@GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags "$(LDFLAGS)" -o $(PWD)/pb

# Build pb for all supported platforms.
build-release: verifiers crosscompile
@echo "Built releases for version $(VERSION)"

# Builds pb and installs it to $GOPATH/bin.
install: build
@echo "Installing pb binary to '$(GOPATH)/bin/pb'"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## PB
## pb

PB (short for Parseable) is a command line interface for [Parseable Server](https://github.com/parseablehq/parseable). PB allows you to manage Streams, Users, and Data on Parseable Server. You can use PB to manage multiple Parseable Server instances using Profiles.
pb (short for Parseable) is a command line interface for [Parseable Server](https://github.com/parseablehq/parseable). pb allows you to manage Streams, Users, and Data on Parseable Server. You can use pb to manage multiple Parseable Server instances using Profiles.

### Installation

PB is available as a single, self contained binary for Mac, Linux, and Windows. You can download the latest version from the [releases page](https://github.com/parseablehq/pb/releases/latest).
pb is available as a single, self contained binary for Mac, Linux, and Windows. You can download the latest version from the [releases page](https://github.com/parseablehq/pb/releases/latest).

To install PB, download the binary for your platform and place it in a directory that is in your $PATH. For example, on Mac you can place the binary in `/usr/local/bin`.
To install pb, download the binary for your platform and place it in a directory that is in your $PATH. For example, on Mac you can place the binary in `/usr/local/bin`.

![pb query](https://github.com/parseablehq/.github/blob/main/images/pb.png?raw=true)

27 changes: 14 additions & 13 deletions buildscripts/cross-compile.sh
Original file line number Diff line number Diff line change
@@ -30,26 +30,27 @@ function _init() {
}

function _build() {
local osarch=$1
IFS=/ read -r -a arr <<<"$osarch"
os="${arr[0]}"
arch="${arr[1]}"
package=$(go list -f '{{.ImportPath}}')
printf -- "--> %15s:%s\n" "${osarch}" "${package}"
local ldflags=("$@")

# Go build to build the binary.
export GOOS=$os
export GOARCH=$arch
export GO111MODULE=on
export CGO_ENABLED=0
go build -tags kqueue -o /dev/null

for osarch in ${SUPPORTED_OSARCH}; do
IFS=/ read -r -a arr <<<"$osarch"
os="${arr[0]}"
arch="${arr[1]}"
export GOOS=$os
export GOARCH=$arch
printf -- "Building release binary for --> %s:%s\n" "${os}" "${arch}"
go build -trimpath -tags kqueue --ldflags "${ldflags[@]}" -o "$(PWD)"/bin/pb_"${os}"_"${arch}"
shasum -a 256 "$(PWD)"/bin/pb_"${os}"_"${arch}" >"$(PWD)"/bin/pb_"${os}"_"${arch}".sha256
done
}

function main() {
echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
for each_osarch in ${SUPPORTED_OSARCH}; do
_build "${each_osarch}"
done
ldflags=/ read -r arr <<<"$(go run "$(PWD)"/buildscripts/gen-ldflags.go)"
_build "${arr[@]}"
}

_init && main "$@"
9 changes: 3 additions & 6 deletions buildscripts/gen-ldflags.go
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import (
func genLDFlags(version string) string {
var ldflagsStr string
ldflagsStr = "-s -w -X main.Version=" + version + " "
ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:12]
ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:6]
return ldflagsStr
}

@@ -50,12 +50,9 @@ func commitID() string {
}

func main() {
var version string
if len(os.Args) > 1 {
version = os.Args[1]
} else {
version, ok := os.LookupEnv("VERSION")
if !ok {
version = "v0.0.0/DEVELOPMENT"
}

fmt.Println(genLDFlags(version))
}
40 changes: 29 additions & 11 deletions cmd/stream.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,15 @@ type StreamStatsData struct {
Time time.Time `json:"time"`
}

type StreamListItem struct {
name string
}

func (item *StreamListItem) Render() string {
render := standardStyle.Render(item.name)
return itemOuter.Render(render)
}

// StreamRetentionData is the data structure for stream retention
type StreamRetentionData []struct {
Description string `json:"description"`
@@ -143,7 +152,7 @@ var StatStreamCmd = &cobra.Command{

isRententionSet := len(retention) > 0

fmt.Println(styleBold.Render("Info:"))
fmt.Println(styleBold.Render("\nInfo:"))
fmt.Printf(" Event Count: %d\n", ingestionCount)
fmt.Printf(" Ingestion Size: %s\n", humanize.Bytes(uint64(ingestionSize)))
fmt.Printf(" Storage Size: %s\n", humanize.Bytes(uint64(storageSize)))
@@ -217,7 +226,7 @@ var RemoveStreamCmd = &cobra.Command{
}

if resp.StatusCode == 200 {
fmt.Printf("Removed stream %s", styleBold.Render(name))
fmt.Printf("Removed stream %s\n", styleBold.Render(name))
} else {
bytes, err := io.ReadAll(resp.Body)
if err != nil {
@@ -256,18 +265,27 @@ var ListStreamCmd = &cobra.Command{
return err
}
defer resp.Body.Close()
for _, item := range items {
fmt.Println(item["name"])

if len(items) >= 0 {
fmt.Println()
} else if len(items) == 0 {
fmt.Println("No streams found")
return nil
}
} else {
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return err

for _, item := range items {
item := StreamListItem{item["name"]}
fmt.Println(item.Render())
}
body := string(bytes)
fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body)
fmt.Println()
return nil
}

bytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
body := string(bytes)
fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body)
return nil
},
}
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -54,43 +54,43 @@ func defaultInitialProfile() config.Profile {
// Root command
var cli = &cobra.Command{
Use: "pb",
Short: "\nParseable command line tool",
Long: "\npb is a command line tool for Parseable",
Short: "\nParseable command line interface",
Long: "\npb is a command line interface for Parseable",
RunE: func(command *cobra.Command, args []string) error {
if p, _ := command.Flags().GetBool(versionFlag); p {
cmd.PrintVersion(Version, Commit)
return nil
}

return errors.New("No command or flag supplied\n")
return errors.New("no command or flag supplied")
},
}

var profile = &cobra.Command{
Use: "profile",
Short: "Manage profiles",
Long: "\nprofile command is used to manage multiple instances of Parseable. Each profile can have a different set of credentials and URL",
Long: "\nuse profile command to configure (multiple) Parseable instances. Each profile takes a URL and credentials.",
}

var user = &cobra.Command{
Use: "user",
Short: "Manage users",
Long: "\nuser command is used to manage users. Users can be added, deleted and listed",
Long: "\nuser command is used to manage users.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
}

var stream = &cobra.Command{
Use: "stream",
Short: "Manage streams",
Long: "\nstream command is used to manage streams. Streams can be created, deleted and listed",
Long: "\nstream command is used to manage streams.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
}

var query = &cobra.Command{
Use: "query [stream-name] --duration 10",
Example: " pb query frontend --duration 10",
Short: "Open SQL query prompt",
Long: "\nquery command is used to open a prompt to query a stream. The stream name and duration in minutes are required arguments",
Long: "\nquery command is used to open a prompt to query a stream.",
Args: cobra.ExactArgs(1),
PreRunE: cmd.PreRunDefaultProfile,
RunE: func(command *cobra.Command, args []string) error {

0 comments on commit a4dc850

Please sign in to comment.