-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
88 lines (70 loc) · 2.41 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
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOOS ?= linux
GOARCH ?= amd64
TARGETOS ?= $(GOOS)
TARGETARCH ?= $(GOARCH)
BIN_SUFFIX :=
ifeq ($(TARGETOS),windows)
BIN_SUFFIX := .exe
endif
VERSION ?= next
ifneq ($(CI_COMMIT_TAG),)
VERSION := $(CI_COMMIT_TAG:v%=%)
endif
# append commit-sha to next version
BUILD_VERSION := $(VERSION)
ifeq ($(BUILD_VERSION),next)
CI_COMMIT_SHA ?= $(shell git rev-parse HEAD)
BUILD_VERSION := $(shell echo "next-$(shell echo ${CI_COMMIT_SHA} | head -c 8)")
endif
LDFLAGS := -s -w -extldflags "-static" -X main.version=${BUILD_VERSION}
.PHONY: all
all: build
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
formatcheck:
@([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR) | head)" ]) || (echo "Source is unformatted"; exit 1)
format:
@gofmt -w ${GOFILES_NOVENDOR}
.PHONY: clean
clean:
go clean -i ./...
rm -rf release/
.PHONY: vet
vet:
@echo "Running go vet..."
CGO_ENABLED=0 go vet $(GO_PACKAGES)
.PHONY: test
test:
CGO_ENABLED=0 go test -cover ./...
# we can not use "-race" as test trigger write to os.stdout
build:
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o release/plugin-git${BIN_SUFFIX}
.PHONY: version
version:
@echo ${BUILD_VERSION}
release-binaries:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux-amd64_plugin-git
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux-arm64_plugin-git
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux-arm_plugin-git
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/windows-amd64_plugin-git.exe
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/windows-arm64_plugin-git.exe
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/darwin-amd64_plugin-git
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/darwin-arm64_plugin-git
release-tarball:
mkdir -p release
tar -cvzf release/plugin-git-src-$(BUILD_VERSION).tar.gz \
vendor/ \
*.go \
go.??? \
LICENSE \
Makefile
release-checksums:
# generate shas for tar files
(cd release/; sha256sum *plugin-git* > checksums.txt)
.PHONY: release
release: release-binaries release-tarball
$(MAKE) release-checksums