-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (78 loc) · 2.91 KB
/
Copy pathMakefile
File metadata and controls
106 lines (78 loc) · 2.91 KB
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
ifeq ($(shell go env GOOS),windows)
EXE=.exe
else
EXE=
endif
DIST=dist
BINDIR=.
BASENAME=$(notdir $(shell pwd))
PROGRAM=$(BINDIR)/$(BASENAME)$(EXE)
LAST_RELEASE=
REPO=$(shell go list | head -n 1)
APP_PACKAGE=$(REPO)/cmd
IMAGE=$(BASENAME)
VERSION ?= $(shell git describe --tags --always --dirty)
COMMIT ?= $(shell git rev-parse --short HEAD)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
DOCKER=docker
PACKAGE=$(DIST)/$(basename $(notdir $(PROGRAM)))-$(shell go env GOOS)-$(shell go env GOARCH).zip
LDFLAGS=-X '$(APP_PACKAGE).version=$(VERSION)' -X '$(APP_PACKAGE).commit=$(COMMIT)' -X '$(APP_PACKAGE).date=$(DATE)'
.PHONY: $(PROGRAM) all compile install image test test-integration vet release-snapshot docs man
all: $(PROGRAM)
compile: $(PROGRAM)
$(PROGRAM): $(BINDIR)
mkdir -p $(dir $@)
go build -ldflags="$(LDFLAGS)" -o $(PROGRAM)
package: $(PACKAGE)
$(PACKAGE): $(PROGRAM)
# These next 2 recipes know how to make .zip and .tar files, which are used implicitly in making the package
%.zip:
mkdir $(dir $@)
zip -j $@ $?
%.tar.gz %.tgz:
mkdir $(dir $@)
tar -czf $@ -C $(dir $<) $(notdir $<)
install:
go install -ldflags="$(LDFLAGS)"
image:
$(DOCKER) build -f Dockerfile --build-arg PROGRAM=$(BASENAME) --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --build-arg DATE=$(DATE) --build-arg BASENAME=$(BASENAME) -t $(IMAGE) .
test:
go test ./...
test-integration:
go test -tags=integration -v ./test/...
vet:
go vet ./...
# Regenerate the CLI reference under docs/sm/docs/cli from the live command
# tree, so it can never drift from the code. Depends on compile (not
# $(PROGRAM)) so this always rebuilds the binary before generating docs.
docs: compile
rm -f docs/sm/docs/cli/*.md
./$(PROGRAM) docs --dir docs/sm/docs/cli --format markdown
# Generate man pages into dist/man (dist/ is gitignored, these are build
# artifacts, not committed).
man: compile
mkdir -p $(DIST)/man
./$(PROGRAM) docs --dir $(DIST)/man --format man
# Build every release target locally without publishing anything, using the
# same .goreleaser.yml the release workflow runs on tag push. Requires
# goreleaser (https://goreleaser.com/install/) on PATH.
release-snapshot:
@command -v goreleaser >/dev/null 2>&1 || { echo "goreleaser not found on PATH; install it: https://goreleaser.com/install/"; exit 1; }
goreleaser release --snapshot --clean --skip=publish
changelog: CHANGELOG.md
CHANGELOG.md: .chglog/config.yml
git chglog $(LAST_RELEASE) >$@
.chglog/config.yml: go.mod
sed -i.bak -e "s|repository_url:.*|repository_url: https://$(REPO)|" $@
hooks: .git/hooks/pre-commit
.git/hooks/pre-commit: .pre-commit-config.yaml
pre-commit install
pre-commit install --hook-type commit-msg
info::
@echo BASENAME=$(BASENAME)
@echo PROGRAM=$(PROGRAM)
@echo IMAGE=$(IMAGE)
tools:
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/go-critic/go-critic/cmd/gocritic@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest