-
Notifications
You must be signed in to change notification settings - Fork 99
/
Makefile
65 lines (52 loc) · 2.86 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
# TL;DR:
# make build: build locally
# make test: run all tests
# make test-unit: just unit tests
# make test-e2e: just e2e tests
# make release: after git tag, release to github and prepare krew file
.PHONY: test test-unit test-e2e build goreleaser release clean
os ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
arch ?= $(shell go env GOARCH | tr '[:upper:]' '[:lower:]')
underscore = $(word $2,$(subst _, ,$1))
test: test-unit test-e2e test-integration
test-unit:
go test -v ./...
test-e2e: dist/kubectl-neat_$(os)_$(arch)
bats ./test/e2e-cli.bats
test-integration: dist/kubectl-neat_$(os)_$(arch).tar.gz dist/kubectl-neat_$(os)_$(arch)*/kubectl-neat dist/checksums.txt
bats ./test/e2e-kubectl.bats
bats ./test/e2e-krew.bats
build: dist/kubectl-neat_$(os)_$(arch)
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
dist/kubectl-neat_%: $(SRC)
GOOS=$(call underscore,$*,1) GOARCH=$(call underscore,$*,2) go build -o dist/$(@F)
# release by default will not publish. run with `publish=1` to publish
goreleaserflags = --skip=publish --snapshot
ifdef publish
goreleaserflags =
endif
# relase always re-builds (no dependencies on purpose)
goreleaser: $(SRC)
goreleaser --clean $(goreleaserflags)
dist/kubectl-neat_darwin_arm64.tar.gz dist/kubectl-neat_darwin_amd64.tar.gz dist/kubectl-neat_linux_arm64.tar.gz dist/kubectl-neat_linux_amd64.tar.gz dist/checksums.txt: goreleaser
# no op recipe
@:
release: publish = 1
release: dist/kubectl-neat_darwin_arm64.tar.gz dist/kubectl-neat_darwin_amd64.tar.gz dist/kubectl-neat_linux_arm64.tar.gz dist/kubectl-neat_linux_amd64.tar.gz dist/checksums.txt
./krew-package.sh 'darwin' 'arm64' 'neat' './dist'
./krew-package.sh 'darwin' 'amd64' 'neat' './dist'
./krew-package.sh 'linux' 'arm64' 'neat' './dist'
./krew-package.sh 'linux' 'amd64' 'neat' './dist'
# merge
yq -o json "dist/kubectl-neat_darwin_amd64.yaml" > dist/darwin-amd64.json
yq -o json "dist/kubectl-neat_darwin_arm64.yaml" > dist/darwin-arm64.json
yq -o json "dist/kubectl-neat_linux_amd64.yaml" > dist/linux-amd64.json
yq -o json "dist/kubectl-neat_linux_arm64.yaml" > dist/linux-arm64.json
rm dist/kubectl-neat_darwin_arm64.yaml dist/kubectl-neat_darwin_amd64.yaml dist/kubectl-neat_linux_arm64.yaml dist/kubectl-neat_linux_amd64.yaml
jq --slurp '.[0].spec.platforms += .[1].spec.platforms | .[0]' 'dist/darwin-amd64.json' 'dist/darwin-arm64.json' > 'dist/darwin.json'
jq --slurp '.[0].spec.platforms += .[1].spec.platforms | .[0]' 'dist/linux-amd64.json' 'dist/linux-arm64.json' > 'dist/linux.json'
jq --slurp '.[0].spec.platforms += .[1].spec.platforms | .[0]' 'dist/linux.json' 'dist/darwin.json' > 'dist/kubectl-neat.json'
yq -o yaml --prettyPrint dist/kubectl-neat.json > dist/kubectl-neat.yaml
rm dist/kubectl-neat.json dist/darwin.json dist/linux.json dist/darwin-amd64.json dist/darwin-arm64.json dist/linux-amd64.json dist/linux-arm64.json
clean:
rm -rf dist