-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
275 lines (209 loc) · 10.2 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
PROJECT_VERSION := 2.0.0-beta5
DOCKER_REPO := synfinatic
PROJECT_NAME := aws-sso
DOCKER_PROJECT_NAME := aws-sso-cli-ecs-server
DIST_DIR ?= dist/
GOOS ?= $(shell uname -s | tr "[:upper:]" "[:lower:]")
ARCH ?= $(shell uname -m)
ifeq ($(ARCH),x86_64)
GOARCH := amd64
else
GOARCH := $(ARCH) # no idea if this works for other platforms....
endif
PROJECT_TAG := $(shell git describe --tags 2>/dev/null $(git rev-list --tags --max-count=1))
PROJECT_COMMIT := $(shell git rev-parse HEAD || echo "")
PROJECT_DELTA := $(shell DELTA_LINES=$$(git diff | wc -l); if [ $${DELTA_LINES} -ne 0 ]; then echo $${DELTA_LINES} ; else echo "''" ; fi)
BUILDINFOSDET ?=
PROGRAM_ARGS ?=
ifeq ($(PROJECT_TAG),)
PROJECT_TAG := NO-TAG
endif
ifeq ($(PROJECT_COMMIT),)
PROJECT_COMMIT := NO-CommitID
endif
ifeq ($(PROJECT_DELTA),)
PROJECT_DELTA :=
endif
VERSION_PKG := $(shell echo $(PROJECT_VERSION) | sed 's/^v//g')
LICENSE := GPLv3
URL := https://github.com/$(DOCKER_REPO)/$(PROJECT_NAME)
DESCRIPTION := AWS SSO CLI
BUILDINFOS ?= $(shell date +%FT%T%z)$(BUILDINFOSDET)
LDFLAGS := -X "main.Version=$(PROJECT_VERSION)" -X "main.Delta=$(PROJECT_DELTA)" -X "main.Buildinfos=$(BUILDINFOS)" -X "main.Tag=$(PROJECT_TAG)" -X "main.CommitID=$(PROJECT_COMMIT)"
OUTPUT_NAME := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION) # default for current platform
#ifeq ($(GOOS),darwin)
# https://github.com/golang/go/issues/61229#issuecomment-1988965927
# this doesn't work for homebrew with clang it seems: https://github.com/Homebrew/homebrew-core/pull/174439
#LDFLAGS := $(LDFLAGS) -extldflags=-Wl,-ld_classic
#endif
# go build flags
GOBFLAGS := -trimpath
# supported platforms for `make release`
WINDOWS_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-windows-amd64.exe
WINDOWS32_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-windows-386.exe
LINUX_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-amd64
LINUXARM64_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-arm64
DARWIN_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-darwin-amd64
DARWINARM64_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-darwin-arm64
ALL: $(DIST_DIR)$(PROJECT_NAME) ## Build binary for this platform
include help.mk # place after ALL target and before all other targets
$(DIST_DIR)$(PROJECT_NAME): $(wildcard */*.go) .prepare
go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(DIST_DIR)$(PROJECT_NAME) ./cmd/aws-sso/...
@echo "Created: $(DIST_DIR)$(PROJECT_NAME)"
INSTALL_PREFIX ?= /usr/local
install: $(DIST_DIR)$(PROJECT_NAME) ## install binary in $INSTALL_PREFIX
install -d $(INSTALL_PREFIX)/bin
install -c $(DIST_DIR)$(PROJECT_NAME) $(INSTALL_PREFIX)/bin
uninstall: ## Uninstall binary from $INSTALL_PREFIX
rm $(INSTALL_PREFIX)/bin/$(PROJECT_NAME)
release-brew: ## Create a PR against homebrew to bump the version
@echo "we are in the auto-bump list: https://github.com/Homebrew/homebrew-core/blob/master/.github/autobump.txt"
# VERSION=$(PROJECT_VERSION) ./scripts/release-check.sh
# brew update && brew bump-formula-pr --version $(PROJECT_VERSION) aws-sso-cli
release-tag: ## Tag our current HEAD as v$(PROJECT_VERSION)
git tag -sa v$(PROJECT_VERSION) -m 'release $(PROJECT_VERSION)'
VERSION=$(PROJECT_VERSION) ./scripts/release-check.sh
git push --tags
#DOWNLOAD_URL := https://synfin.net/misc/aws-sso-cli.$(PROJECT_VERSION).tar.gz
DOWNLOAD_URL ?= https://github.com/synfinatic/aws-sso-cli/archive/refs/tags/v$(PROJECT_VERSION).tar.gz
.PHONY: .shasum
.shasum:
@which shasum >/dev/null || (echo "Missing 'shasum' binary" ; exit 1)
@echo "foo" | shasum -a 256 >/dev/null || (echo "'shasum' does not support: -a 256"; exit 1)
.PHONY: package
package: linux linux-arm64 ## Build deb/rpm packages
docker build -t aws-sso-cli-builder:latest -f Dockerfile.package .
docker run --rm \
-v $$(pwd)/dist:/root/dist \
-e VERSION=$(PROJECT_VERSION) aws-sso-cli-builder:latest
tags: cmd/*/*.go internal/*/*.go internal/*/*/*.go ## Create tags file for vim, etc
@echo Make sure you have Go Tags installed: https://github.com/jstemmer/gotags
gotags -f tags -sort=true $$(find . -type f -name "*.go")
.build-release: windows windows32 linux linux-arm64 darwin darwin-arm64
.validate-release: ALL
@TAG=$$(./$(DIST_DIR)$(PROJECT_NAME) version 2>/dev/null | grep '(v$(PROJECT_VERSION))'); \
if test -z "$$TAG"; then \
echo "Build tag from does not match PROJECT_VERSION=v$(PROJECT_VERSION) in Makefile:" ; \
./$(DIST_DIR)$(PROJECT_NAME) version 2>/dev/null | grep built ; \
exit 1 ; \
fi
release: .validate-release .shasum clean .build-release package ## Build all our release binaries
cd dist && shasum -a 256 * | gpg --clear-sign >release.sig.asc
.PHONY: run
run: ## build and run using $PROGRAM_ARGS
go run ./cmd/aws-sso $(PROGRAM_ARGS)
.PHONY: delve
delve: ## debug binary using $PROGRAM_ARGS
dlv debug ./cmd/aws-sso -- $(PROGRAM_ARGS)
clean-all: clean ## clean _everything_
clean: ## Remove all binaries in dist
rm -rf dist/*
clean-go: ## Clean Go cache
go clean -i -r -cache -modcache
go-get: ## Get our go modules
go get -v all
.prepare: $(DIST_DIR)
.PHONY: build-race
build-race: .prepare ## Build race detection binary
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./cmd/aws-sso/...
debug: .prepare ## Run debug in dlv
dlv debug ./cmd/aws-sso
.PHONY: unittest
unittest: ## Run go unit tests
go test -ldflags='$(LDFLAGS)' -covermode=atomic -coverprofile=coverage.out ./...
.PHONY: test-race
test-race: ## Run `go test -race` on the code
@echo checking code for races...
go test -race ./...
.PHONY: vet
vet: ## Run `go vet` on the code
@echo checking code is vetted...
for x in $(shell go list ./...); do echo $$x ; go vet $$x ; done
test: vet unittest lint test-homebrew ## Run important tests
precheck: test test-fmt test-tidy ## Run all tests that happen in a PR
govulncheck: ## Run govulncheck
@govulncheck ./...
# run everything but `lint`and govulncheck because they run seperately
.build-tests: vet unittest test-tidy test-fmt test-homebrew
$(DIST_DIR):
@if test ! -d $(DIST_DIR); then mkdir -p $(DIST_DIR) ; fi
.PHONY: fmt
fmt: ## Format Go code
@gofmt -s -w */*/*.go
.PHONY: test-fmt
test-fmt: fmt ## Test to make sure code if formatted correctly
@if test `git diff cmd/aws-sso | wc -l` -gt 0; then \
echo "Code changes detected when running 'go fmt':" ; \
git diff -Xfiles ; \
exit -1 ; \
fi
.PHONY: test-tidy
test-tidy: ## Test to make sure go.mod is tidy
@go mod tidy
@if test `git diff go.mod | wc -l` -gt 0; then \
echo "Need to run 'go mod tidy' to clean up go.mod" ; \
exit -1 ; \
fi
lint: ## Run golangci-lint
golangci-lint run
test-homebrew: $(DIST_DIR)$(PROJECT_NAME) ## Run the homebrew tests
@$(DIST_DIR)$(PROJECT_NAME) --config /dev/null version 2>/dev/null | grep -q "AWS SSO CLI Version $(PROJECT_VERSION)"
@$(DIST_DIR)$(PROJECT_NAME) --config /dev/null 2>&1 | grep -q "no AWS SSO providers have been configured"
# Build targets for our supported plaforms
windows: $(WINDOWS_BIN) ## Build 64bit x86 Windows binary
$(WINDOWS_BIN): $(wildcard */*.go) .prepare
GOARCH=amd64 GOOS=windows go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(WINDOWS_BIN) ./cmd/aws-sso/...
@echo "Created: $(WINDOWS_BIN)"
windows32: $(WINDOWS32_BIN) ## Build 32bit x86 Windows binary
$(WINDOWS32_BIN): $(wildcard */*.go) .prepare
GOARCH=386 GOOS=windows go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(WINDOWS32_BIN) ./cmd/aws-sso/...
@echo "Created: $(WINDOWS32_BIN)"
linux: $(LINUX_BIN) ## Build Linux/x86_64 binary
$(LINUX_BIN): $(wildcard */*.go) .prepare
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(LINUX_BIN) ./cmd/aws-sso/...
@echo "Created: $(LINUX_BIN)"
linux-arm64: $(LINUXARM64_BIN) ## Build Linux/arm64 binary
$(LINUXARM64_BIN): $(wildcard */*.go) .prepare
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(LINUXARM64_BIN) ./cmd/aws-sso/...
@echo "Created: $(LINUXARM64_BIN)"
# macOS needs different build flags if you are cross-compiling because of the key chain
# See: https://github.com/99designs/aws-vault/issues/758
darwin: $(DARWIN_BIN) ## Build MacOS/x86_64 binary
$(DARWIN_BIN): $(wildcard */*.go) .prepare
ifeq ($(ARCH), x86_64)
CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) ./cmd/aws-sso/...
else
CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) \
go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) ./cmd/aws-sso/...
endif
@echo "Created: $(DARWIN_BIN)"
darwin-arm64: $(DARWINARM64_BIN) ## Build MacOS/ARM64 binary
$(DARWINARM64_BIN): $(wildcard */*.go) .prepare
ifeq ($(ARCH), arm64)
CGO_ENABLED=1 GOARCH=arm64 GOOS=darwin go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(DARWINARM64_BIN) ./cmd/aws-sso/...
else
CGO_ENABLED=1 GOARCH=arm64 GOOS=darwin SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) \
go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(DARWINARM64_BIN) ./cmd/aws-sso/...
endif
@echo "Created: $(DARWINARM64_BIN)"
$(OUTPUT_NAME): $(wildcard */*.go) .prepare
go build $(GOBFLAGS) -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./cmd/aws-sso/...
docs: docs/default-region.png ## Build document files
docs/default-region.png:
dot -o docs/default-region.png -Tpng docs/default-region.dot
.PHONY: loc
loc: ## Print LOC stats
wc -l $$(find . -name "*.go")
update-copyright: ## Update the copyright year on *.go
$(shell export YEAR=$$(date +%Y) && export LAST_YEAR=$$(($$(date +%Y)-1)) && \
sed -i '' -Ee "s|2021-${LAST_YEAR}|2021-${YEAR}|" $$(find . -name "*.go") mkdocs.yml)
@echo "Updated copyright to 2021-$$(date +%Y)"
serve-docs: ## Run mkdocs server on localhost:8000
docker build -t synfinatic/mkdocs-material:latest -f Dockerfile.mkdocs .
docker run --rm \
-v $$(pwd):/docs \
-p 8000:8000 \
synfinatic/mkdocs-material:latest
docker: ## Build docker image
docker build -t $(DOCKER_REPO)/$(DOCKER_PROJECT_NAME):$(PROJECT_VERSION) \
-t $(DOCKER_REPO)/$(DOCKER_PROJECT_NAME):latest .