From c856461b899de0f36ab3f4e0fd450164aa76ecf7 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Thu, 30 Nov 2017 11:07:08 -0500 Subject: [PATCH] releases Signed-off-by: Jess Frazelle --- .gitignore | 4 +- .travis.yml | 51 +++++++++++++++++- Makefile | 126 ++++++++++++++++++++++++++++++++++++++------- README.md | 16 ++++++ VERSION | 1 + main.go | 8 +-- version/version.go | 7 +++ 7 files changed, 185 insertions(+), 28 deletions(-) create mode 100644 VERSION create mode 100644 version/version.go diff --git a/.gitignore b/.gitignore index 664b8ea..6bc3ad4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,6 @@ *.o *.a *.so -*.swo -*.swp # Folders _obj @@ -45,3 +43,5 @@ Icon .Trashes dockfmt +binaries +cross diff --git a/.travis.yml b/.travis.yml index c3c1033..72c9d13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,64 @@ notifications: email: true go: - - 1.6 - - 1.7 + - 1.6.x + - 1.7.x + - 1.8.x + - 1.9.x - tip env: global: - GO15VENDOREXPERIMENT=1 install: - go get github.com/golang/lint/golint + - go get honnef.co/go/tools/cmd/staticcheck script: - go build -v - go vet $(go list ./... | grep -v vendor) + - staticcheck $(go list ./... | grep -v vendor) - test -z "$(golint ./... | grep -v vendor | tee /dev/stderr)" - test -z "$(gofmt -s -l . | grep -v vendor | tee /dev/stderr)" - go test $(go list ./... | grep -v vendor) + - make release + deploy: + provider: releases + api_key: + secure: "bYFfZ9KCvIGLFDEp8xlaE28SLCFIzYWqX63amsGY2iyT2ybMINQTVTAebzRvkFKI8tXHq2rlHRVJ/SNNklelv5Fjt/yhFIV6QM2tKeJ+sh3TWRGC03v/BdyjlVo3yPddYRQiUWpf8uKhZp7IVLfaEPz5xR42mcYAKk1DP+rm7pn/Jwm4ORxcgEtgdmIyzTIApAMlMwAQbJekZVSpDoOOrOdVySqGOvzbCbg253svOA+ulFv+AYxLU7HWlE86wLyZYtsK+xSmwmrg2Gzn7Is92MuZgWBBVF7IvKIkDto06TNHzJiL2eAjCGM+Y2oyUT1xycgtbx1LB4MC4ZrSXLnJ2x6Tw1CxrPgMZJ/ij0DY5yxeU1jo1LtwHXyR1G5gd8WcrZ8hYGLSw1vllFjNUgS83DE5QZIajYmVJIUn7JBjSvFoTffYDDOPPQUJ+1uy5VtQte0rEPR7au2GXle9Vp2tHsPGlQw7I/VXapbu4QMIWHcgnOElFYdWzYLV0jntpDTc9xShux9/RhCBObehaI36JJDqVnur6444ahEVOFWfhViEqTXp1aRuGuHoU0nycOvzlD1KKdyHpinhpmLrayhZdack1jr/Mnj7ot26VBaOHQAZ9yXNGWReBNOQoU9yHuOu8vZW3K3MMa8P4Es4WqZC5glQ3Lf+QeemLexkqLVoc30=" + file: + - cross/dockfmt-linux-amd64.md5 + - cross/dockfmt-windows-386.sha256 + - cross/dockfmt-linux-arm + - cross/dockfmt-darwin-amd64.md5 + - cross/dockfmt-darwin-amd64 + - cross/dockfmt-solaris-amd64.md5 + - cross/dockfmt-linux-arm64.sha256 + - cross/dockfmt-linux-arm.sha256 + - cross/dockfmt-linux-386.sha256 + - cross/dockfmt-darwin-386.md5 + - cross/dockfmt-windows-386.md5 + - cross/dockfmt-freebsd-amd64.md5 + - cross/dockfmt-linux-arm64.md5 + - cross/dockfmt-linux-arm64 + - cross/dockfmt-freebsd-amd64.sha256 + - cross/dockfmt-freebsd-386.md5 + - cross/dockfmt-linux-amd64.sha256 + - cross/dockfmt-linux-386.md5 + - cross/dockfmt-freebsd-386 + - cross/dockfmt-solaris-amd64.sha256 + - cross/dockfmt-windows-amd64 + - cross/dockfmt-windows-amd64.md5 + - cross/dockfmt-windows-amd64.sha256 + - cross/dockfmt-linux-arm.md5 + - cross/dockfmt-darwin-386.sha256 + - cross/dockfmt-darwin-amd64.sha256 + - cross/dockfmt-windows-386 + - cross/dockfmt-solaris-amd64 + - cross/dockfmt-darwin-386 + - cross/dockfmt-linux-386 + - cross/dockfmt-freebsd-amd64 + - cross/dockfmt-freebsd-386.sha256 + - cross/dockfmt-linux-amd64 + skip_cleanup: true + on: + go: tip + tags: true diff --git a/Makefile b/Makefile index efa21ba..d4e3e0c 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,130 @@ # Set an output prefix, which is the local directory if not specified PREFIX?=$(shell pwd) -BUILDTAGS= -.PHONY: clean all fmt vet lint build test install static -.DEFAULT: default +# Setup name variables for the package/tool +NAME := dockfmt +PKG := github.com/jessfraz/$(NAME) -all: clean build fmt lint test vet install +# Set any default go build tags +BUILDTAGS := -build: +# Set the build dir, where built cross-compiled binaries will be output +BUILDDIR := ${PREFIX}/cross + +# Populate version variables +# Add to compile time flags +VERSION := $(shell cat VERSION) +GITCOMMIT := $(shell git rev-parse --short HEAD) +GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no) +ifneq ($(GITUNTRACKEDCHANGES),) + GITCOMMIT := $(GITCOMMIT)-dirty +endif +CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VERSION) +GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)" +GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static" + +# List the GOOS and GOARCH to build +GOOSARCHES = darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 linux/arm linux/arm64 linux/amd64 linux/386 solaris/amd64 windows/amd64 windows/386 + +all: clean build fmt lint test staticcheck vet install ## Runs a clean, build, fmt, lint, test, staticcheck, vet and install + +.PHONY: build +build: $(NAME) ## Builds a dynamic executable or package + +$(NAME): *.go VERSION @echo "+ $@" - @go build -tags "$(BUILDTAGS) cgo" . + go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) . -static: +.PHONY: static +static: ## Builds a static executable @echo "+ $@" - CGO_ENABLED=1 go build -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static" -o dockfmt . + CGO_ENABLED=0 go build \ + -tags "$(BUILDTAGS) static_build" \ + ${GO_LDFLAGS_STATIC} -o $(NAME) . -fmt: +.PHONY: fmt +fmt: ## Verifies all files have men `gofmt`ed @echo "+ $@" - @gofmt -s -l . | grep -v vendor | tee /dev/stderr + @gofmt -s -l . | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr -lint: +.PHONY: lint +lint: ## Verifies `golint` passes @echo "+ $@" - @golint ./... | grep -v vendor | tee /dev/stderr + @golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr -test: fmt lint vet +.PHONY: test +test: ## Runs the go tests @echo "+ $@" @go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor) -vet: +.PHONY: vet +vet: ## Verifies `go vet` passes @echo "+ $@" - @go vet $(shell go list ./... | grep -v vendor) + @go vet $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr -clean: +.PHONY: staticcheck +staticcheck: ## Verifies `staticcheck` passes @echo "+ $@" - @rm -rf dockfmt + @staticcheck $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr -install: +.PHONY: install +install: ## Installs the executable or package @echo "+ $@" @go install . + +define buildpretty +mkdir -p $(BUILDDIR)/$(1)/$(2); +GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \ + -o $(BUILDDIR)/$(1)/$(2)/$(NAME) \ + -a -tags "$(BUILDTAGS) static_build netgo" \ + -installsuffix netgo ${GO_LDFLAGS_STATIC} .; +md5sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).md5; +sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256; +endef + +.PHONY: cross +cross: *.go VERSION ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary) + @echo "+ $@" + $(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) + +define buildrelease +GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \ + -o $(BUILDDIR)/$(NAME)-$(1)-$(2) \ + -a -tags "$(BUILDTAGS) static_build netgo" \ + -installsuffix netgo ${GO_LDFLAGS_STATIC} .; +md5sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).md5; +sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256; +endef + +.PHONY: release +release: *.go VERSION ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH) + @echo "+ $@" + $(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) + +.PHONY: bump-version +BUMP := patch +bump-version: ## Bump the version in the version file. Set KIND to [ patch | major | minor ] + @go get -u github.com/jessfraz/junk/sembump # update sembump tool + $(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION))) + @echo "Bumping VERSION from $(VERSION) to $(NEW_VERSION)" + echo $(NEW_VERSION) > VERSION + @echo "Updating links to download binaries in README.md" + sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md + git add VERSION README.md + git commit -vsam "Bump version to $(NEW_VERSION)" + @echo "Run make tag to create and push the tag for new version $(NEW_VERSION)" + +.PHONY: tag +tag: ## Create a new git tag to prepare to build a release + git tag -sa $(VERSION) -m "$(VERSION)" + @echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build." + +.PHONY: clean +clean: ## Cleanup any build binaries or packages + @echo "+ $@" + $(RM) $(NAME) + $(RM) -r $(BUILDDIR) + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index 8872331..94b4ee6 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,22 @@ Dockerfile format. This is a work in progress so calm yourself if you want to file 80 bajillion issues. +## Installation + +#### Binaries + +- **darwin** [386](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-darwin-386) / [amd64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-darwin-amd64) +- **freebsd** [386](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-freebsd-386) / [amd64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-freebsd-amd64) +- **linux** [386](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-linux-386) / [amd64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-linux-amd64) / [arm](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-linux-arm) / [arm64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-linux-arm64) +- **solaris** [amd64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-solaris-amd64) +- **windows** [386](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-windows-386) / [amd64](https://github.com/jessfraz/dockfmt/releases/download/v0.2.0/dockfmt-windows-amd64) + +#### Via Go + +```bash +$ go get github.com/jessfraz/dockfmt +``` + ## Usage **Help output** diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..1474d00 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.2.0 diff --git a/main.go b/main.go index a666501..cf31633 100644 --- a/main.go +++ b/main.go @@ -8,14 +8,10 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/builder/dockerfile/parser" + "github.com/jessfraz/dockfmt/version" "github.com/urfave/cli" ) -const ( - // VERSION is the binary version. - VERSION = "v0.2.0" -) - // preload initializes any global options and configuration // before the main or sub commands are run. func preload(c *cli.Context) (err error) { @@ -33,7 +29,7 @@ func preload(c *cli.Context) (err error) { func main() { app := cli.NewApp() app.Name = "dockfmt" - app.Version = VERSION + app.Version = version.VERSION app.Author = "@jessfraz" app.Email = "no-reply@butts.com" app.Usage = "Dockerfile format." diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..8088a27 --- /dev/null +++ b/version/version.go @@ -0,0 +1,7 @@ +package version + +// VERSION indicates which version of the binary is running. +var VERSION string + +// GITCOMMIT indicates which git hash the binary was built off of +var GITCOMMIT string