Skip to content

Commit

Permalink
add goreleaser (#49)
Browse files Browse the repository at this point in the history
* add goreleaser

Add a goreleaser configuration file that builds binaries for Linux,
MacOS and Windows, for 32bit (x86/386) and 64bit (x64/amd64). The
binaries will be archived into a tar.gz/zip file along with the LICENSE
file.

The `dist/` directory will be written to by goreleaser with the binaries
during the build process, so it's also been added to .gitignore.

To build all the binaries and release them to GitHub:
1. Tag the release. e.g. `git tag -a v1.0.0 -m 'First release'`
2. Generate a GitHub Personal Access Token. See https://github.com/settings/tokens.
3. Push the release to GitHub. e.g. `git push origin v1.0.0`
4. Make the release, which will publish binaries to the GitHub "Releases" page. e.g.  `GITHUB_TOKEN=xxxxxxx... make release`

* add -version flag

Run `grpcurl -version` to see the release version. Use `make install` to build a binary that shows the version based on current git hash (which will show a version number if HEAD is a release tag and otherwise uses `git describe` to summarize the version).
  • Loading branch information
leighmcculloch authored and jhump committed Sep 25, 2018
1 parent d4d048f commit 79a550b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
24 changes: 24 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
builds:
- binary: grpcurl
main: ./cmd/grpcurl
goos:
- linux
- darwin
- windows
goarch:
- amd64
- 386
ldflags:
- -s -w -X main.version=v{{.Version}}

archive:
format: tar.gz
format_overrides:
- goos: windows
format: zip
replacements:
amd64: x86_64
386: x86_32
darwin: osx
files:
- LICENSE
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dev_build_version=$(shell git describe --tags --always --dirty)

# TODO: run golint and errcheck, but only to catch *new* violations and
# decide whether to change code or not (e.g. we need to be able to whitelist
# violations already in the code). They can be useful to catch errors, but
Expand All @@ -16,7 +18,12 @@ updatedeps:

.PHONY: install
install:
go install ./...
go install -ldflags '-X "main.version=dev build $(dev_build_version)"' ./...

.PHONY: release
release:
@GO111MODULE=off go get github.com/goreleaser/goreleaser
goreleaser --rm-dist

.PHONY: checkgofmt
checkgofmt:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ As mentioned above, `grpcurl` works seamlessly if the server supports the reflec
service. If not, you can supply the `.proto` source files or you can supply protoset
files (containing compiled descriptors, produced by `protoc`) to `grpcurl`.

## Installation
## Installation (binaries)

Download the binary from the [releases](https://github.com/fullstorydev/grpcurl/releases) page.

## Installation (source)
You can use the `go` tool to install `grpcurl`:
```shell
go get github.com/fullstorydev/grpcurl
Expand Down
8 changes: 8 additions & 0 deletions cmd/grpcurl/grpcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ import (
"github.com/fullstorydev/grpcurl"
)

var version = "dev build <no version set>"

var (
exit = os.Exit

isUnixSocket func() bool // nil when run on non-unix platform

help = flag.Bool("help", false,
`Print usage instructions and exit.`)
printVersion = flag.Bool("version", false,
`Print version.`)
plaintext = flag.Bool("plaintext", false,
`Use plain-text HTTP/2 when connecting to server (no TLS).`)
insecure = flag.Bool("insecure", false,
Expand Down Expand Up @@ -146,6 +150,10 @@ func main() {
usage()
os.Exit(0)
}
if *printVersion {
fmt.Fprintf(os.Stderr, "%s %s\n", os.Args[0], version)
os.Exit(0)
}

// Do extra validation on arguments and figure out what user asked us to do.
if *plaintext && *insecure {
Expand Down

0 comments on commit 79a550b

Please sign in to comment.