forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (146 loc) · 5.19 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
.DEFAULT_GOAL = build
extension = $(patsubst windows,.exe,$(filter windows,$(1)))
GO := go
PKG_NAME := gomplate
PREFIX := .
ifeq ("$(CI)","true")
LINT_PROCS ?= 1
else
LINT_PROCS ?= $(shell nproc)
endif
COMMIT ?= `git rev-parse --short HEAD 2>/dev/null`
VERSION ?= `git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null | sed 's/v\(.*\)/\1/'`
COMMIT_FLAG := -X `go list ./version`.GitCommit=$(COMMIT)
VERSION_FLAG := -X `go list ./version`.Version=$(VERSION)
GOOS ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/')
GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/')
platforms := freebsd-amd64 linux-amd64 linux-386 linux-arm linux-arm64 darwin-amd64 solaris-amd64 windows-amd64.exe windows-386.exe
compressed-platforms := linux-amd64-slim linux-arm-slim linux-arm64-slim darwin-amd64-slim windows-amd64-slim.exe
clean:
rm -Rf $(PREFIX)/bin/*
rm -f $(PREFIX)/*.[ci]id
build-x: $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%,$(platforms))
compress-all: $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%,$(compressed-platforms))
$(PREFIX)/bin/$(PKG_NAME)_%-slim: $(PREFIX)/bin/$(PKG_NAME)_%
upx --lzma $< -o $@
$(PREFIX)/bin/$(PKG_NAME)_%-slim.exe: $(PREFIX)/bin/$(PKG_NAME)_%.exe
upx --lzma $< -o $@
$(PREFIX)/bin/$(PKG_NAME)_%_checksum.txt: $(PREFIX)/bin/$(PKG_NAME)_%
@sha256sum $< > $@
$(PREFIX)/bin/checksums.txt: \
$(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%_checksum.txt,$(platforms)) \
$(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%_checksum.txt,$(compressed-platforms))
@cat $^ > $@
$(PREFIX)/%.signed: $(PREFIX)/%
@keybase sign < $< > $@
compress: $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)-slim$(call extension,$(GOOS))
cp $< $(PREFIX)/bin/$(PKG_NAME)-slim$(call extension,$(GOOS))
%.iid: Dockerfile
@docker build \
--build-arg VCS_REF=$(COMMIT) \
--target $(subst .iid,,$@) \
--iidfile $@ \
.
%.cid: %.iid
@docker create $(shell cat $<) > $@
build-release: artifacts.cid
@docker cp $(shell cat $<):/bin/. bin/
docker-images: gomplate.iid gomplate-slim.iid
$(PREFIX)/bin/$(PKG_NAME)_%: $(shell find $(PREFIX) -type f -name "*.go")
GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- | cut -f1 -d.) CGO_ENABLED=0 \
$(GO) build \
-ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" \
-o $@ \
./cmd/gomplate
$(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)$(call extension,$(GOOS))
cp $< $@
build: $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS))
ifeq ($(OS),Windows_NT)
test:
$(GO) test -v -coverprofile=c.out ./...
else
test:
$(GO) test -v -race -coverprofile=c.out ./...
endif
integration: build
$(GO) test -v -tags=integration \
./tests/integration
integration.iid: Dockerfile.integration $(PREFIX)/bin/$(PKG_NAME)_linux-amd64$(call extension,$(GOOS))
docker build -f $< --iidfile $@ .
test-integration-docker: integration.iid
docker run -it --rm $(shell cat $<)
gen-changelog:
docker run -it -v $(shell pwd):/app --workdir /app -e CHANGELOG_GITHUB_TOKEN hairyhenderson/github_changelog_generator \
github_changelog_generator --no-filter-by-milestone --exclude-labels duplicate,question,invalid,wontfix,admin
docs/themes/hugo-material-docs:
git clone https://github.com/digitalcraftsman/hugo-material-docs.git $@
gen-docs: docs/themes/hugo-material-docs
cd docs/; hugo
docs/content/functions/%.md: docs-src/content/functions/%.yml docs-src/content/functions/func_doc.md.tmpl
gomplate -d data=$< -f docs-src/content/functions/func_doc.md.tmpl -o $@
# this target doesn't usually get used - it's mostly here as a reminder to myself
# hint: make sure CLOUDCONVERT_API_KEY is set ;)
gomplate.png: gomplate.svg
cloudconvert -f png -c density=288 $^
lint:
@golangci-lint run --timeout 2m --disable-all \
--enable depguard \
--enable dupl \
--enable goconst \
--enable gocritic \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable golint \
--enable gosec \
--enable gosimple \
--enable govet \
--enable ineffassign \
--enable maligned \
--enable misspell \
--enable nakedret \
--enable prealloc \
--enable staticcheck \
--enable structcheck \
--enable stylecheck \
--enable typecheck \
--enable unconvert \
--enable varcheck
@golangci-lint run --timeout 2m --tests=false --disable-all \
--enable deadcode \
--enable errcheck \
--enable interfacer \
--enable scopelint \
--enable unused
@golangci-lint run --timeout 2m --build-tags integration \
--disable-all \
--enable deadcode \
--enable depguard \
--enable dupl \
--enable gochecknoinits \
--enable gocritic \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable golint \
--enable gosec \
--enable gosimple \
--enable govet \
--enable ineffassign \
--enable maligned \
--enable misspell \
--enable nakedret \
--enable prealloc \
--enable scopelint \
--enable staticcheck \
--enable structcheck \
--enable stylecheck \
--enable typecheck \
--enable unconvert \
--enable unparam \
--enable unused \
--enable varcheck \
./tests/integration
.PHONY: gen-changelog clean test build-x compress-all build-release build test-integration-docker gen-docs lint clean-images clean-containers docker-images
.DELETE_ON_ERROR:
.SECONDARY: