Overhaul the Makefile
- Fix updatedeps reverting to master, which causes Travis CI to produce invalid results for pull-request builds. The makefile attempts to detect this change and checkout the correct branch if it happens. - Clean up the code style and failure messaging. - Add / update proxy targets for common workflows: default, deps, ci, release
This commit is contained in:
parent
b610e8005c
commit
938f2178d7
13
.travis.yml
13
.travis.yml
|
@ -4,25 +4,16 @@ language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.4
|
- 1.4
|
||||||
|
- 1.5
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
install: make updatedeps
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- GOMAXPROCS=2 make test
|
- GOMAXPROCS=2 make ci
|
||||||
#- go test -race ./...
|
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
notifications:
|
|
||||||
irc:
|
|
||||||
channels:
|
|
||||||
- "irc.freenode.org#packer-tool"
|
|
||||||
skip_join: true
|
|
||||||
use_notice: true
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
|
76
Makefile
76
Makefile
|
@ -1,12 +1,31 @@
|
||||||
TEST?=./...
|
TEST?=./...
|
||||||
|
# Get the current full sha from git
|
||||||
|
GITSHA:=$(shell git rev-parse HEAD)
|
||||||
|
# Get the current local branch name from git (if we can, this may be blank)
|
||||||
|
GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
|
||||||
|
|
||||||
default: test vet dev
|
default: test dev
|
||||||
|
|
||||||
bin:
|
ci: deps test testrace
|
||||||
|
|
||||||
|
release: updatedeps test bin
|
||||||
|
|
||||||
|
bin: deps
|
||||||
|
@grep 'const VersionPrerelease = ""' version.go > /dev/null ; if [ $$? -ne 0 ]; then \
|
||||||
|
echo "ERROR: You must remove prerelease tags from version.go prior to release."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
@sh -c "$(CURDIR)/scripts/build.sh"
|
@sh -c "$(CURDIR)/scripts/build.sh"
|
||||||
|
|
||||||
dev:
|
deps:
|
||||||
@TF_DEV=1 sh -c "$(CURDIR)/scripts/build.sh"
|
go get -v -d ./...
|
||||||
|
|
||||||
|
dev: deps
|
||||||
|
@grep 'const VersionPrerelease = ""' version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
||||||
|
echo "ERROR: You must add prerelease tags to version.go prior to making a dev build."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@PACKER_DEV=1 sh -c "$(CURDIR)/scripts/build.sh"
|
||||||
|
|
||||||
# generate runs `go generate` to build the dynamically generated
|
# generate runs `go generate` to build the dynamically generated
|
||||||
# source files.
|
# source files.
|
||||||
|
@ -14,23 +33,33 @@ generate:
|
||||||
go generate ./...
|
go generate ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@echo "Running tests on:"; git symbolic-ref HEAD; git rev-parse HEAD
|
go test $(TEST) $(TESTARGS) -timeout=15s
|
||||||
go test $(TEST) $(TESTARGS) -timeout=10s
|
@go vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
|
||||||
@$(MAKE) vet
|
go get golang.org/x/tools/cmd/vet; \
|
||||||
|
fi
|
||||||
|
@go vet $(TEST) ; if [ $$? -eq 1 ]; then \
|
||||||
|
echo "ERROR: Vet found problems in the code."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
# testacc runs acceptance tests
|
# testacc runs acceptance tests
|
||||||
testacc: generate
|
testacc: generate
|
||||||
@if [ "$(TEST)" = "./..." ]; then \
|
@echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel."
|
||||||
echo "ERROR: Set TEST to a specific package"; \
|
PACKER_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout=45m
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
PACKER_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 45m
|
|
||||||
|
|
||||||
testrace:
|
testrace:
|
||||||
go test -race $(TEST) $(TESTARGS)
|
go test -race $(TEST) $(TESTARGS) -timeout=15s
|
||||||
|
|
||||||
|
# `go get -u` causes git to revert packer to the master branch. This causes all
|
||||||
|
# kinds of headaches. We record the git sha when make starts try to correct it
|
||||||
|
# if we detect dift. DO NOT use `git checkout -f` for this because it will wipe
|
||||||
|
# out your changes without asking.
|
||||||
updatedeps:
|
updatedeps:
|
||||||
@echo "Updating deps on:"; git symbolic-ref HEAD; git rev-parse HEAD
|
@echo "INFO: Currently on $(GITBRANCH) ($(GITSHA))"
|
||||||
|
@git diff-index --quiet HEAD ; if [ $$? -ne 0 ]; then \
|
||||||
|
echo "ERROR: Your git working tree has uncommitted changes. updatedeps will fail. Please stash or commit your changes first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
go get -u github.com/mitchellh/gox
|
go get -u github.com/mitchellh/gox
|
||||||
go get -u golang.org/x/tools/cmd/stringer
|
go get -u golang.org/x/tools/cmd/stringer
|
||||||
go list ./... \
|
go list ./... \
|
||||||
|
@ -38,19 +67,14 @@ updatedeps:
|
||||||
| grep -v github.com/mitchellh/packer \
|
| grep -v github.com/mitchellh/packer \
|
||||||
| grep -v '/internal/' \
|
| grep -v '/internal/' \
|
||||||
| sort -u \
|
| sort -u \
|
||||||
| xargs go get -f -u -v
|
| xargs go get -f -u -v -d ; if [ $$? -eq 0 ]; then \
|
||||||
@echo "Finished updating deps, now on:"; git symbolic-ref HEAD; git rev-parse HEAD
|
echo "ERROR: go get failed. Your git branch may have changed; you were on $(GITBRANCH) ($(GITSHA))."; \
|
||||||
|
|
||||||
vet:
|
|
||||||
@echo "Running go vet on:"; git symbolic-ref HEAD; git rev-parse HEAD
|
|
||||||
@go vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
|
|
||||||
go get golang.org/x/tools/cmd/vet; \
|
|
||||||
fi
|
fi
|
||||||
@go vet ./... ; if [ $$? -eq 1 ]; then \
|
@if [ "$(GITBRANCH)" != "" ]; then git checkout -q $(GITBRANCH); else git checkout -q $(GITSHA); fi
|
||||||
echo ""; \
|
@if [ `git rev-parse HEAD` != "$(GITSHA)" ]; then \
|
||||||
echo "Vet found suspicious constructs. Please check the reported constructs"; \
|
echo "ERROR: git checkout has drifted and we weren't able to correct it. Was $(GITBRANCH) ($(GITSHA))"; \
|
||||||
echo "and fix them if necessary before submitting the code for reviewal."; \
|
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
@echo "INFO: Currently on $(GITBRANCH) ($(GITSHA))"
|
||||||
|
|
||||||
.PHONY: bin default generate test testacc updatedeps vet
|
.PHONY: bin checkversion ci default deps generate test testacc testrace updatedeps
|
||||||
|
|
|
@ -16,7 +16,7 @@ GIT_COMMIT=$(git rev-parse HEAD)
|
||||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||||
|
|
||||||
# If its dev mode, only build for ourself
|
# If its dev mode, only build for ourself
|
||||||
if [ "${TF_DEV}x" != "x" ]; then
|
if [ "${PACKER_DEV}x" != "x" ]; then
|
||||||
XC_OS=${XC_OS:-$(go env GOOS)}
|
XC_OS=${XC_OS:-$(go env GOOS)}
|
||||||
XC_ARCH=${XC_ARCH:-$(go env GOARCH)}
|
XC_ARCH=${XC_ARCH:-$(go env GOARCH)}
|
||||||
fi
|
fi
|
||||||
|
@ -27,7 +27,7 @@ XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
echo "==> Getting dependencies..."
|
echo "==> Getting dependencies..."
|
||||||
go get ./...
|
go get -d ./...
|
||||||
|
|
||||||
# Delete the old dir
|
# Delete the old dir
|
||||||
echo "==> Removing old directory..."
|
echo "==> Removing old directory..."
|
||||||
|
|
Loading…
Reference in New Issue