/
Makefile
84 lines (67 loc) · 2.28 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.DEFAULT_GOAL := help
# Determine this makefile's path.
# Be sure to place this BEFORE `include` directives, if any.
DEFAULT_BRANCH := main
THIS_FILE := $(lastword $(MAKEFILE_LIST))
PKG := github.com/natemarks/iam-disable
COMMIT := $(shell git rev-parse HEAD)
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/)
CDIR = $(shell pwd)
EXECUTABLES := iam-disable
GOOS := linux darwin
GOARCH := amd64
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
DEFAULT_BRANCH := main
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
${EXECUTABLES}:
@for o in $(GOOS); do \
for a in $(GOARCH); do \
echo "$(COMMIT)/$${o}/$${a}" ; \
mkdir -p build/$(COMMIT)/$${o}/$${a} ; \
echo "COMMIT: $(COMMIT)" >> build/$(COMMIT)/$${o}/$${a}/version.txt ; \
env GOOS=$${o} GOARCH=$${a} \
go build -v -o build/$(COMMIT)/$${o}/$${a}/$@ \
-ldflags="-X github.com/natemarks/iam-disable/version.Version=${COMMIT}" ${PKG}/cmd/$@; \
done \
done ; \
build: git-status ${EXECUTABLES}
rm -f build/current
ln -s $(CDIR)/build/$(COMMIT) $(CDIR)/build/current
release: git-status build
mkdir -p release/$(COMMIT)
@for o in $(GOOS); do \
for a in $(GOARCH); do \
tar -C ./build/$(COMMIT)/$${o}/$${a} -czvf release/$(COMMIT)/iam-disable_$(COMMIT)_$${o}_$${a}.tar.gz . ; \
done \
done ; \
test:
@go test -v ${PKG_LIST}
# @go test -short ${PKG_LIST}
vet:
@go vet ${PKG_LIST}
goimports: ## check imports
go install golang.org/x/tools/cmd/goimports@latest
goimports -w .
lint: ## run golint
go install golang.org/x/lint/golint@latest
@for file in ${GO_FILES} ; do \
golint $$file ; \
done
fmt: ## run gofmt
@go fmt ${PKG_LIST}
gocyclo: # run cyclomatic complexity check
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
gocyclo -over 25 .
static: goimports fmt vet lint gocyclo test
clean:
-@rm ${OUT} ${OUT}-v*
git-status: ## require status is clean so we can use undo_edits to put things back
@status=$$(git status --porcelain); \
if [ ! -z "$${status}" ]; \
then \
echo "Error - working directory is dirty. Commit those changes!"; \
exit 1; \
fi
.PHONY: build release static upload vet lint fmt gocyclo goimports test