-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
77 lines (62 loc) · 3.34 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
.PHONY: staticcheck dependency clean build release all
PKGS := $(shell go list ./...)
REPO := github.com/guessi/kubectl-grep
BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GITVERSION := $(shell git describe --tags --abbrev=8)
GOVERSION := $(shell go version | cut -d' ' -f3)
LDFLAGS := -s -w -X "$(REPO)/cmd.gitVersion=$(GITVERSION)" -X "$(REPO)/cmd.goVersion=$(GOVERSION)" -X "$(REPO)/cmd.buildTime=$(BUILDTIME)"
default: build
staticcheck:
@echo "Setup staticcheck..."
@go install honnef.co/go/tools/cmd/staticcheck@latest
@echo "Check staticcheck version..."
staticcheck --version
@echo "Run staticcheck..."
@for i in $(PKGS); do echo $${i}; staticcheck $${i}; done
test:
go version
go fmt ./...
go vet ./...
# go test -v ./...
dependency:
go mod download
build-linux-x86_64:
@echo "Creating Build for Linux (x86_64)..."
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o ./releases/$(GITVERSION)/Linux-x86_64/kubectl-grep
@cp ./LICENSE ./releases/$(GITVERSION)/Linux-x86_64/LICENSE
@tar zcf ./releases/$(GITVERSION)/kubectl-grep-Linux-x86_64.tar.gz -C releases/$(GITVERSION)/Linux-x86_64 kubectl-grep LICENSE
build-linux-arm64:
@echo "Creating Build for Linux (arm64)..."
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o ./releases/$(GITVERSION)/Linux-arm64/kubectl-grep
@cp ./LICENSE ./releases/$(GITVERSION)/Linux-arm64/LICENSE
@tar zcf ./releases/$(GITVERSION)/kubectl-grep-Linux-arm64.tar.gz -C releases/$(GITVERSION)/Linux-arm64 kubectl-grep LICENSE
build-darwin-x86_64:
@echo "Creating Build for macOS (x86_64)..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o ./releases/$(GITVERSION)/Darwin-x86_64/kubectl-grep
@cp ./LICENSE ./releases/$(GITVERSION)/Darwin-x86_64/LICENSE
@tar zcf ./releases/$(GITVERSION)/kubectl-grep-Darwin-x86_64.tar.gz -C releases/$(GITVERSION)/Darwin-x86_64 kubectl-grep LICENSE
build-darwin-arm64:
@echo "Creating Build for macOS (arm64)..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o ./releases/$(GITVERSION)/Darwin-arm64/kubectl-grep
@cp ./LICENSE ./releases/$(GITVERSION)/Darwin-arm64/LICENSE
@tar zcf ./releases/$(GITVERSION)/kubectl-grep-Darwin-arm64.tar.gz -C releases/$(GITVERSION)/Darwin-arm64 kubectl-grep LICENSE
build-windows-x86_64:
@echo "Creating Build for Windows (x86_64)..."
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o ./releases/$(GITVERSION)/Windows-x86_64/kubectl-grep.exe
@cp ./LICENSE ./releases/$(GITVERSION)/Windows-x86_64/LICENSE.txt
@tar zcf ./releases/$(GITVERSION)/kubectl-grep-Windows-x86_64.tar.gz -C releases/$(GITVERSION)/Windows-x86_64 kubectl-grep.exe LICENSE.txt
build-linux: build-linux-x86_64 build-linux-arm64
build-darwin: build-darwin-x86_64 build-darwin-arm64
build-windows: build-windows-x86_64
build: build-linux build-darwin build-windows
clean:
@echo "Cleanup Releases..."
rm -rvf ./releases/*
release:
@echo "Creating Releases..."
@curl -LO https://github.com/tcnksm/ghr/releases/download/v0.17.0/ghr_v0.17.0_linux_amd64.tar.gz
@tar --strip-components=1 -xvf ghr_v0.17.0_linux_amd64.tar.gz ghr_v0.17.0_linux_amd64/ghr
./ghr -version
./ghr -replace -recreate -token ${GITHUB_TOKEN} $(GITVERSION) releases/$(GITVERSION)/
sha1sum releases/$(GITVERSION)/*.tar.gz > releases/$(GITVERSION)/SHA1SUM
all: staticcheck dependency clean build