-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
171 lines (129 loc) · 4.52 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
PKG?=github.com/smallstep/step-kms-plugin
BINNAME?=step-kms-plugin
GOLANG_CROSS_VERSION?=v1.22
# Set V to 1 for verbose output from the Makefile
Q=$(if $V,,@)
PREFIX?=
SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOOS_OVERRIDE ?=
OUTPUT_ROOT=output/
RELEASE=./.releases
#########################################
# Default
#########################################
all: lint test build
ci: test build
.PHONY: all ci
#########################################
# Bootstrapping
#########################################
bootstrap:
$Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
$Q go install golang.org/x/vuln/cmd/govulncheck@latest
$Q go install gotest.tools/gotestsum@latest
.PHONY: bootstrap
#################################################
# Determine the type of `push` and `version`
#################################################
# GITHUB Actions
ifdef GITHUB_REF
VERSION ?= $(shell echo $(GITHUB_REF) | sed 's/^refs\/tags\///')
NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
else
VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
endif
VERSION := $(shell echo $(VERSION) | sed 's/^v//')
DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
ifdef V
$(info GITHUB_REF is $(GITHUB_REF))
$(info VERSION is $(VERSION))
$(info DATE is $(DATE))
endif
#########################################
# Build
#########################################
LDFLAGS := -ldflags='-s -w -X "$(PKG)/cmd.Version=$(VERSION)" -X "$(PKG)/cmd.ReleaseDate=$(DATE)"'
build:
$Q go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
@echo "Build Complete!"
build-fips:
$Q GOEXPERIMENT="boringcrypto" go build -v -tags fips,noyubikey -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
@echo "Build Complete!"
.PHONY: build build-fips
#########################################
# Go generate
#########################################
generate: build
$Q go generate ./...
$Q mkdir -p completions
$Q bin/step-kms-plugin completion bash > completions/bash_completion
$Q bin/step-kms-plugin completion fish > completions/fish_completion
$Q bin/step-kms-plugin completion powershell > completions/powershell_completion
$Q bin/step-kms-plugin completion zsh > completions/zsh_completion
.PHONY: generate
#########################################
# Test
#########################################
test:
$Q go test -coverprofile=coverage.out ./...
.PHONY: test
#########################################
# Linting
#########################################
fmt:
$Q goimports --local github.com/smallstep/step-kms-plugin -l -w $(SRC)
lint: golint govulncheck
golint: SHELL:=/bin/bash
golint:
$Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
govulncheck:
$Q govulncheck ./...
.PHONY: fmt lint golint govulncheck
#########################################
# Release
#########################################
release-dev:
$Q @docker run -it --rm --privileged -e CGO_ENABLED=1 \
--entrypoint /bin/bash \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION}
release-dry-run:
$Q @docker run --rm --privileged -e CGO_ENABLED=1 \
--entrypoint /go/src/$(PKG)/docker/build/entrypoint.sh \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
$Q @docker run --rm --privileged -e CGO_ENABLED=1 --env-file .release-env \
--entrypoint /go/src/$(PKG)/docker/build/entrypoint.sh \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean
.PHONY: release-dev release-dry-run release
#########################################
# Install
#########################################
INSTALL_PREFIX?=/usr/
install: $(PREFIX)bin/$(BINNAME)
$Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
uninstall:
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
.PHONY: install uninstall
#########################################
# Clean
#########################################
clean:
ifneq ($(BINNAME),"")
$Q rm -f bin/$(BINNAME)
endif
.PHONY: clean