-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
135 lines (97 loc) · 4.57 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
SHELL := /bin/bash
NAME := captain-hook
BINARY_NAME := captain-hook
GO := GO111MODULE=on GO15VENDOREXPERIMENT=1 go
GO_NOMOD := GO111MODULE=off go
PACKAGE_NAME := github.com/jenkins-infra/captain-hook
ROOT_PACKAGE := github.com/jenkins-infra/captain-hook
ORG := jenkins-infra
# set dev version unless VERSION is explicitly set via environment
VERSION ?= $(shell echo "$$(git describe --abbrev=0 --tags 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/ | grep -v e2e)
PEGOMOCK_PACKAGE := github.com/petergtz/pegomock
GO_DEPENDENCIES := $(shell find . -type f -name '*.go')
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
SHA1 := $(shell git rev-parse HEAD 2> /dev/null || echo 'unknown')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
INSPECT_LABELS := $(shell inspect labels 2> /dev/null || echo '--label "inspect.not.installed=true"')
BUILDFLAGS := -trimpath -ldflags \
" -X $(ROOT_PACKAGE)/pkg/version.Version=$(VERSION)\
-X $(ROOT_PACKAGE)/pkg/version.Revision=$(REV)\
-X $(ROOT_PACKAGE)/pkg/version.BuiltBy=make \
-X $(ROOT_PACKAGE)/pkg/version.Sha1=$(SHA1)\
-X $(ROOT_PACKAGE)/pkg/version.Branch='$(BRANCH)'\
-X $(ROOT_PACKAGE)/pkg/version.BuildDate='$(BUILD_DATE)'\
-X $(ROOT_PACKAGE)/pkg/version.GoVersion='$(GO_VERSION)'"
CGO_ENABLED = 0
BUILDTAGS :=
GOPATH1=$(firstword $(subst :, ,$(GOPATH)))
export PATH := $(PATH):$(GOPATH1)/bin
CLIENTSET_NAME_VERSIONED := v0.15.11
build: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILDTAGS) $(BUILDFLAGS) -o build/$(BINARY_NAME) cmd/$(NAME)/$(NAME).go
linux: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/linux/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/linux/$(NAME)
dist: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o dist/captain-hook-linux_linux_amd64/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x dist/captain-hook-linux_linux_amd64/$(NAME)
docker build --platform linux/amd64 -t jenkinsciinfra/captain-hook:dev $(INSPECT_LABELS) .
docker push jenkinsciinfra/captain-hook:dev --disable-content-trust=true
diff:
helm diff upgrade --install captain-hook charts/captain-hook --set image.pullPolicy=Always --set replicaCount=1
deploy:
helm upgrade --install captain-hook charts/captain-hook --set image.pullPolicy=Always --set replicaCount=1
arm: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm $(GO) build $(BUILDFLAGS) -o build/arm/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/arm/$(NAME)
win: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/win/$(NAME)-windows-amd64.exe cmd/$(NAME)/$(NAME).go
darwin: $(GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/darwin/$(NAME) cmd/$(NAME)/$(NAME).go
chmod +x build/darwin/$(NAME)
deploy-local: build
mkdir -p ~/bin
cp build/$(BINARY_NAME) ~/bin/$(BINARY_NAME)
all: version check
check: fmt lint build test
version:
echo "Go version: $(GO_VERSION)"
test:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -coverprofile=coverage.out $(PACKAGE_DIRS)
testv:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -test.v $(PACKAGE_DIRS)
testrich:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) richgo test -test.v $(PACKAGE_DIRS)
test1:
DISABLE_SSO=true CGO_ENABLED=$(CGO_ENABLED) $(GO) test -count=1 -short ./... -test.v -run $(TEST)
cover:
$(GO) tool cover -func coverage.out | grep total
coverage:
$(GO) tool cover -html=coverage.out
install: $(GO_DEPENDENCIES)
GOBIN=${GOPATH1}/bin $(GO) install $(BUILDFLAGS) cmd/$(NAME)/$(NAME).go
get-fmt-deps: ## Install goimports
$(GO_NOMOD) get golang.org/x/tools/cmd/goimports
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)
fmt: importfmt
@FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)`
@([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
clean:
rm -rf build release
modtidy:
$(GO) mod tidy
mod: modtidy build
.PHONY: dist release clean
generate-fakes:
$(GO) generate ./...
generate-all: generate-fakes
.PHONY: goreleaser
goreleaser:
step-go-releaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION)
lint:
golangci-lint run