-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
233 lines (180 loc) · 9.51 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
PACKAGE_NAME := github.com/keygen-sh/keygen-relay
PACKAGE_VERSION := $(shell cat VERSION)
PACKAGE_MAJOR := $(shell cat VERSION | cut -d. -f1)
PACKAGE_MINOR := $(shell cat VERSION | cut -d. -f2)
PACKAGE_PATCH := $(shell cat VERSION | cut -d. -f3 | cut -d- -f1)
PACKAGE_PRE := $(shell cat VERSION | grep -oP '(?<=-)[^+]*')
PACKAGE_BUILD := $(shell cat VERSION | grep -oP '(?<=\+).*')
PACKAGE_CHANNEL = stable
ifeq ($(findstring -rc.,$(PACKAGE_VERSION)), -rc.)
PACKAGE_CHANNEL = rc
else ifeq ($(findstring -beta.,$(PACKAGE_VERSION)), -beta.)
PACKAGE_CHANNEL = beta
else ifeq ($(findstring -alpha.,$(PACKAGE_VERSION)), -alpha.)
PACKAGE_CHANNEL = alpha
else ifeq ($(findstring -dev.,$(PACKAGE_VERSION)), -dev.)
PACKAGE_CHANNEL = dev
endif
BUILD_LDFLAGS := "-s -w -X $(PACKAGE_NAME)/cli.Version=$(PACKAGE_VERSION)"
BUILD_FLAGS = -v
ifdef DEBUG
BUILD_FLAGS += -x
endif
.PHONY: build
build:
go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o bin/relay ./cmd/relay
.PHONY: build-linux-386
build-linux-386:
CGO_ENABLED=1 GOOS=linux GOARCH=386 CC="zig cc -target x86-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-386-$(PACKAGE_VERSION) ./cmd/relay
.PHONY: build-linux-amd64
build-linux-amd64:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="zig cc -target x86_64-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-amd64-$(PACKAGE_VERSION) ./cmd/relay
.PHONY: build-linux-arm
build-linux-arm:
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC="zig cc -target arm-linux-gnueabihf" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-arm-$(PACKAGE_VERSION) ./cmd/relay
.PHONY: build-linux-arm64
build-linux-arm64:
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC="zig cc -target aarch64-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-arm64-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-linux-mips
# build-linux-mips:
# CGO_ENABLED=1 GOOS=linux GOARCH=mips GOMIPS=softfloat CC="zig cc -target mips-linux -mfloat-abi=soft" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-mips-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-linux-mipsle
# build-linux-mipsle:
# CGO_ENABLED=1 GOOS=linux GOARCH=mipsle GOMIPS=softfloat CC="zig cc -target mipsel-linux -mfloat-abi=soft" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-mipsle-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-linux-mips64
# build-linux-mips64:
# CGO_ENABLED=1 GOOS=linux GOARCH=mips64 GOMIPS=softfloat CC="zig cc -target mips64-linux -mfloat-abi=soft" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-mips64-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-linux-mips64le
# build-linux-mips64le:
# CGO_ENABLED=1 GOOS=linux GOARCH=mips64le GOMIPS=softfloat CC="zig cc -target mips64el-linux -mfloat-abi=soft" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-mips64le-$(PACKAGE_VERSION) ./cmd/relay
.PHONY: build-linux-s390x
build-linux-s390x:
CGO_ENABLED=1 GOOS=linux GOARCH=s390x CC="zig cc -target s390x-linux" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-linux-s390x-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-darwin-amd64
# build-darwin-amd64:
# CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-darwin-amd64-$(PACKAGE_VERSION) ./cmd/relay
# .PHONY: build-darwin-arm64
# build-darwin-arm64:
# CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC="zig cc -target aarch64-macos" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-darwin-arm64-$(PACKAGE_VERSION) ./cmd/relay
.PHONY: build-windows-386
build-windows-386:
CGO_ENABLED=1 GOOS=windows GOARCH=386 CC="zig cc -target x86-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-windows-386-$(PACKAGE_VERSION).exe ./cmd/relay
.PHONY: build-windows-amd64
build-windows-amd64:
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zig cc -target x86_64-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-windows-amd64-$(PACKAGE_VERSION).exe ./cmd/relay
.PHONY: build-windows-arm64
build-windows-arm64:
CGO_ENABLED=1 GOOS=windows GOARCH=arm64 CC="zig cc -target aarch64-windows" go build $(BUILD_FLAGS) -ldflags $(BUILD_LDFLAGS) -o dist/relay-windows-arm64-$(PACKAGE_VERSION).exe ./cmd/relay
.PHONY: build-installer
build-installer:
cp scripts/install.sh dist/install.sh
.PHONY: build-version
build-version:
cp VERSION dist/version
# .PHONY: build-image
# build-image:
# docker buildx build --platform "linux/amd64,linux/arm64" --output type=oci,dest=dist/relay-$(PACKAGE_VERSION).tar .
.PHONY: build-all
build-all: clean build-linux-386 build-linux-amd64 build-linux-arm build-linux-arm64 build-linux-s390x \
build-windows-386 build-windows-amd64 build-windows-arm64 build-installer build-version
.PHONY: release-new
release-new:
keygen new --name "Keygen Relay v$(PACKAGE_VERSION)" --channel $(PACKAGE_CHANNEL) --version $(PACKAGE_VERSION)
.PHONY: release-linux-386
release-linux-386:
keygen upload dist/relay-linux-386-$(PACKAGE_VERSION) --filename relay_linux_386 --release $(PACKAGE_VERSION) --platform linux --arch 386
.PHONY: release-linux-amd64
release-linux-amd64:
keygen upload dist/relay-linux-amd64-$(PACKAGE_VERSION) --filename relay_linux_amd64 --release $(PACKAGE_VERSION) --platform linux --arch amd64
.PHONY: release-linux-arm
release-linux-arm:
keygen upload dist/relay-linux-arm-$(PACKAGE_VERSION) --filename relay_linux_arm --release $(PACKAGE_VERSION) --platform linux --arch arm
.PHONY: release-linux-arm64
release-linux-arm64:
keygen upload dist/relay-linux-arm64-$(PACKAGE_VERSION) --filename relay_linux_arm64 --release $(PACKAGE_VERSION) --platform linux --arch arm64
# .PHONY: release-linux-mips
# release-linux-mips:
# keygen upload dist/relay-linux-mips-$(PACKAGE_VERSION) --filename relay_linux_mips --release $(PACKAGE_VERSION) --platform linux --arch mips
# .PHONY: release-linux-mipsle
# release-linux-mipsle:
# keygen upload dist/relay-linux-mipsle-$(PACKAGE_VERSION) --filename relay_linux_mipsle --release $(PACKAGE_VERSION) --platform linux --arch mipsle
# .PHONY: release-linux-mips64
# release-linux-mips64:
# keygen upload dist/relay-linux-mips64-$(PACKAGE_VERSION) --filename relay_linux_mips64 --release $(PACKAGE_VERSION) --platform linux --arch mips64
# .PHONY: release-linux-mips64le
# release-linux-mips64le:
# keygen upload dist/relay-linux-mips64le-$(PACKAGE_VERSION) --filename relay_linux_mips64le --release $(PACKAGE_VERSION) --platform linux --arch mips64le
.PHONY: release-linux-s390x
release-linux-s390x:
keygen upload dist/relay-linux-s390x-$(PACKAGE_VERSION) --filename relay_linux_s390x --release $(PACKAGE_VERSION) --platform linux --arch s390x
# .PHONY: release-darwin-amd64
# release-darwin-amd64:
# keygen upload dist/relay-darwin-amd64-$(PACKAGE_VERSION) --filename relay_darwin_amd64 --release $(PACKAGE_VERSION) --platform darwin --arch amd64
# .PHONY: release-darwin-arm64
# release-darwin-arm64:
# keygen upload dist/relay-darwin-arm64-$(PACKAGE_VERSION) --filename relay_darwin_arm64 --release $(PACKAGE_VERSION) --platform darwin --arch arm64
.PHONY: release-windows-386
release-windows-386:
keygen upload dist/relay-windows-386-$(PACKAGE_VERSION).exe --filename relay_windows_386.exe --release $(PACKAGE_VERSION) --platform windows --arch 386
.PHONY: release-windows-amd64
release-windows-amd64:
keygen upload dist/relay-windows-amd64-$(PACKAGE_VERSION).exe --filename relay_windows_amd64.exe --release $(PACKAGE_VERSION) --platform windows --arch amd64
.PHONY: release-windows-arm64
release-windows-arm64:
keygen upload dist/relay-windows-arm64-$(PACKAGE_VERSION).exe --filename relay_windows_arm64.exe --release $(PACKAGE_VERSION) --platform windows --arch arm64
.PHONY: release-installer
release-installer:
keygen upload dist/install.sh --release $(PACKAGE_VERSION)
.PHONY: release-version
release-version:
keygen upload dist/version --release $(PACKAGE_VERSION) --filetype txt
.PHONY: release-publish
release-publish:
keygen publish --release $(PACKAGE_VERSION)
.PHONY: release-tag
release-tag:
ifeq ($(PACKAGE_CHANNEL),stable)
keygen untag --release latest
keygen tag latest --release $(PACKAGE_VERSION)
endif
# .PHONY: release-image-new
# release-image-new:
# keygen new --name "Keygen Relay v$(PACKAGE_VERSION)" --channel $(PACKAGE_CHANNEL) --version $(PACKAGE_VERSION) --package relay
# .PHONY: release-image-tarball
# release-image-tarball:
# keygen upload dist/relay-$(PACKAGE_VERSION).tar --filename relay.tar --release $(PACKAGE_VERSION) --package relay
# .PHONY: release-image-tag
# release-image-tag:
# ifeq ($(PACKAGE_CHANNEL),stable)
# keygen untag latest v$(PACKAGE_MAJOR) v$(PACKAGE_MAJOR).$(PACKAGE_MINOR) --release latest --package relay
# keygen tag latest v$(PACKAGE_MAJOR) v$(PACKAGE_MAJOR).$(PACKAGE_MINOR) --release $(PACKAGE_VERSION) --package relay
# endif
# .PHONY: release-image
# release-image:
# release-image-new release-image-tarball release-image-tag
# FIXME(ezekg) refactor into release-cli
.PHONY: release
release: release-new release-linux-386 release-linux-amd64 release-linux-arm release-linux-arm64 \
release-linux-s390x release-windows-386 release-windows-amd64 release-windows-arm64 \
release-installer release-version release-publish release-tag
.PHONY: test
test:
go test -v -race ./...
.PHONY: test-integration
test-integration:
go test -v -tags=integration ./...
.PHONY: test-all
test-all: test test-integration
.PHONY: bench
bench:
go test -bench=. -benchmem -run=^# ./...
.PHONY: clean
clean:
go clean
rm -rf dist/*
.PHONY: vet
vet:
@go vet ./...
.PHONY: fmt
fmt:
@go fmt ./...