-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jess Frazelle <[email protected]>
- Loading branch information
Showing
7 changed files
with
185 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "[email protected]" | ||
app.Usage = "Dockerfile format." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |