-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Makefile
165 lines (135 loc) · 6.13 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
NAME := jcli
CGO_ENABLED = 0
BUILD_GOOS=$(shell go env GOOS)
GO := go
BUILD_TARGET = build
COMMIT := $(shell git rev-parse --short HEAD)
BIN_PATH:=$(shell rm -rf jcli && which jcli)
# CHANGE_LOG := $(shell echo -n "$(shell hub release show $(shell hub release --include-drafts -L 1))" | base64)
VERSION := dev-$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
BUILDFLAGS = -ldflags "-X github.com/linuxsuren/cobra-extension/version.version=$(VERSION) \
-X github.com/linuxsuren/cobra-extension/version.commit=$(COMMIT) \
-X github.com/linuxsuren/cobra-extension/version.date=$(shell date +'%Y-%m-%d')"
MAIN_SRC_FILE = main.go
PATH := $(PATH):$(PWD)/bin
.PHONY: build
build: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=$(BUILD_GOOS) GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/$(BUILD_GOOS)/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/$(BUILD_GOOS)/$(NAME)
rm -rf $(NAME) && ln -s bin/$(BUILD_GOOS)/$(NAME) $(NAME)
darwin: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/darwin/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/darwin/$(NAME)
rm -rf $(NAME) && ln -s bin/darwin/$(NAME) $(NAME)
linux: pre-build
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/linux/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/linux/$(NAME)
rm -rf $(NAME)
ln -s bin/linux/$(NAME) $(NAME)
win: pre-build
go get github.com/inconshreveable/mousetrap
go get github.com/mattn/go-isatty
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=386 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/windows/$(NAME).exe $(MAIN_SRC_FILE)
build-all: darwin linux win
init: gen-mock
gen-mock:
go get github.com/golang/mock/gomock
go install github.com/golang/mock/mockgen
mockgen -destination ./mock/mhttp/roundtripper.go -package mhttp net/http RoundTripper
release: build-all
mkdir -p release
cd ./bin/darwin; upx $(NAME); tar -zcvf ../../release/$(NAME)-darwin-amd64.tar.gz $(NAME); cd ../../release/; shasum -a 256 $(NAME)-darwin-amd64.tar.gz > $(NAME)-darwin-amd64.txt
cd ./bin/linux; upx $(NAME); tar -zcvf ../../release/$(NAME)-linux-amd64.tar.gz $(NAME); cd ../../release/; shasum -a 256 $(NAME)-linux-amd64.tar.gz > $(NAME)-linux-amd64.txt
cd ./bin/windows; upx $(NAME).exe; tar -zcvf ../../release/$(NAME)-windows-386.tar.gz $(NAME).exe; cd ../../release/; shasum -a 256 $(NAME)-windows-386.tar.gz > $(NAME)-windows-386.txt
clean: ## Clean the generated artifacts
rm -rf bin release
rm -rf coverage.out
rm -rf app/cmd/test-app.xml
rm -rf app/test-app.xml
rm -rf util/test-utils.xml
copy: build
sudo cp bin/$(BUILD_GOOS)/$(NAME) $(BIN_PATH)
get-golint:
go get -u golang.org/x/lint/golint
tools: i18n-tools get-golint
i18n-tools:
go get -u github.com/gosexy/gettext/go-xgettext
# go get -u github.com/go-bindata/go-bindata/...
# go get -u github.com/kevinburke/go-bindata/...
go-bindata-download-linux:
mkdir -p bin
curl -L https://github.com/kevinburke/go-bindata/releases/download/v3.11.0/go-bindata-linux-amd64 -o bin/go-bindata
chmod u+x bin/go-bindata
gen-data-linux: go-bindata-download-linux
cd app/i18n && ../../bin/go-bindata -o bindata.go -pkg i18n jcli/zh_CN/LC_MESSAGES/
go-bindata-download-darwin:
mkdir -p bin
curl -L https://github.com/kevinburke/go-bindata/releases/download/v3.11.0/go-bindata-darwin-amd64 -o bin/go-bindata
chmod u+x bin/go-bindata
gen-data-darwin: go-bindata-download-darwin
cd app/i18n && ../../bin/go-bindata -o bindata.go -pkg i18n jcli/zh_CN/LC_MESSAGES/
verify: dep tools lint
pre-build: fmt vet
export GO111MODULE=on
export GOPROXY=https://goproxy.io
go mod tidy
vet:
go vet ./...
lint: vet
golint -set_exit_status app/cmd/...
golint -set_exit_status app/helper/...
golint -set_exit_status app/i18n/i18n.go
golint -set_exit_status app/.
golint -set_exit_status client/...
golint -set_exit_status util/...
fmt:
go fmt ./util/...
go fmt ./client/...
go fmt ./app/...
gofmt -s -w .
test-slow:
# JENKINS_VERSION=2.190.3 go test ./e2e/... -v -count=1 -parallel 1
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestBashCompletion$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestZshCompletion$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestPowerShellCompletion$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestListComputers$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestConfigList$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestConfigGenerate$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestConfigList$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestShowCurrentConfig$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestCrumb$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestDoc$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestSearchPlugins$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestListPlugins$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestCheckUpdateCenter$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestInstallPlugin$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestDownloadPlugin$
go test github.com/jenkins-zh/jenkins-cli/e2e -v -test.run ^TestListQueue$
test:
mkdir -p bin
go test ./util ./app/health ./app/i18n ./app/cmd/common -v -count=1 -coverprofile coverage.out
# go test ./util -v -count=1
# go test ./client -v -count=1 -coverprofile coverage.out
# go test ./app -v -count=1
# go test ./app/health -v -count=1
# go test ./app/helper -v -count=1
# go test ./app/i18n -v -count=1
# go test ./app/cmd -v -count=1
test-release:
goreleaser release --rm-dist --snapshot --skip-publish
dep:
go get github.com/AlecAivazis/survey/v2
go get github.com/spf13/cobra
go get github.com/spf13/viper
go get gopkg.in/yaml.v2
go get github.com/Pallinder/go-randomdata
go install github.com/gosuri/uiprogress
JCLI_FILES="app/cmd/*.go"
gettext:
go-xgettext -k=i18n.T "${JCLI_FILES}" > app/i18n/jcli.pot
gen-data:
cd app/i18n && go-bindata -o bindata.go -pkg i18n jcli/zh_CN/LC_MESSAGES/
image:
docker build . -t jenkinszh/$(NAME)
setup-env-centos:
yum install make golang -y