Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
302 lines (262 loc) · 8.29 KB
/
Copy pathMakefile
File metadata and controls
302 lines (262 loc) · 8.29 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
SHELL = bash
BUILD_INFO = $(shell server/gen_build_info.sh base64)
VERSION = $(shell server/gen_build_info.sh version)
# External ldflags: default to -static for static builds on linux.
# macOS (Darwin) does not support full static linking; avoid -static there.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
EXTLDFLAGS :=
else
EXTLDFLAGS := -static
endif
ifeq ($(strip $(EXTLDFLAGS)),)
BUILD_FLAG = -ldflags="-X github.com/root-gg/plik/server/common.buildInfoString=$(BUILD_INFO) -w -s"
else
BUILD_FLAG = -ldflags="-X github.com/root-gg/plik/server/common.buildInfoString=$(BUILD_INFO) -w -s -extldflags=$(EXTLDFLAGS)"
endif
BUILD_TAGS = -tags osusergo,netgo,sqlite_omit_load_extension
GO_BUILD = go build $(BUILD_FLAG) $(BUILD_TAGS)
COVER_FILE = /tmp/plik.coverprofile
RACE_FLAGS := $(if $(NO_RACE),,-race)
RACE_ENV := $(if $(NO_RACE),,GORACE="halt_on_error=1")
GO_TEST = $(RACE_ENV) go test $(BUILD_FLAG) $(BUILD_TAGS) $(RACE_FLAGS) -cover -coverprofile=$(COVER_FILE) -p 1
ifdef ENABLE_RACE_DETECTOR
GO_BUILD := GORACE="halt_on_error=1" $(GO_BUILD) -race
endif
all: clean clean-frontend frontend clients server
###
# Build frontend ressources
###
frontend:
@cd webapp && npm ci && npm run build
###
# Build plik server for the current architecture
###
server:
@server/gen_build_info.sh info
@echo "Building Plik server → ./server/plikd"
@cd server && $(GO_BUILD) -o plikd
###
# Build plik client for the current architecture
###
client:
@server/gen_build_info.sh info
@echo "Building Plik client → ./client/plik"
@cd client && $(GO_BUILD) -o plik ./
###
# Build clients for all architectures
###
clients:
@releaser/build_clients.sh
###
# Display build info
###
build-info:
@server/gen_build_info.sh info
###
# Display version
###
version:
@server/gen_build_info.sh version
###
# Run linters
###
lint:
@FAIL=0 ;echo -n " - go fmt :" ; OUT=`gofmt -l client server plik` ; \
if [[ -z "$$OUT" ]]; then echo " OK" ; else echo " FAIL"; echo "$$OUT"; FAIL=1 ; fi ;\
echo -n " - go vet :" ; OUT=`go vet ./... 2>&1` ; \
if [[ -z "$$OUT" ]]; then echo " OK" ; else echo " FAIL"; echo "$$OUT"; FAIL=1 ; fi ;\
echo -n " - go fix :" ; BEFORE=`git diff --name-only` ; go fix ./... 2>&1 ; AFTER=`git diff --name-only` ; \
if [[ "$$BEFORE" == "$$AFTER" ]]; then echo " OK" ; else echo " FAIL"; diff <(echo "$$BEFORE") <(echo "$$AFTER") | grep '^>' | sed 's/^> / /'; FAIL=1 ; fi ;\
test $$FAIL -eq 0
###
# Run vulnerability check (requires: go install golang.org/x/vuln/cmd/govulncheck@latest)
###
vuln:
@echo "Running govulncheck..."
@govulncheck ./... || true
@echo ""
@echo "Running npm audit..."
@cd webapp && npm audit || true
###
# Run fmt
###
fmt:
@gofmt -w -s client server plik
###
# Run go fix
###
gofix:
@go fix -v ./...
###
# Run tests
###
test:
@if curl -s 127.0.0.1:8080 > /dev/null ; then echo "Plik server probably already running" ; exit 1 ; fi
@$(GO_TEST) ./... 2>&1 | grep -v "no test files"; test $${PIPESTATUS[0]} -eq 0
###
# Run webapp unit tests (vitest)
###
test-frontend:
@cd webapp && npm ci && npm test
###
# Run webapp e2e tests (playwright — builds frontend+server, starts fresh plikd)
###
test-frontend-e2e: frontend server
@cd webapp && npm ci && npx playwright install chromium
@cd webapp && npx playwright test $(if $(HEADED),--headed)
###
# Run bash client tests (unit + e2e against a temporary server)
###
test-bash-client: server
@echo "Running bash client unit tests..."
@bash client/plik_bash_test.sh --unit
@echo ""
@echo "Starting plik server for integration tests..."
@cd server && ./plikd > /dev/null 2>&1 &
@sleep 2
@echo "Running bash client integration tests..."
@bash client/plik_bash_test.sh; EXIT=$$?; \
kill $$(lsof -ti:8080) 2>/dev/null || true; \
exit $$EXIT
###
# Open last cover profile in web browser
###
cover:
@if [[ ! -f $(COVER_FILE) ]]; then echo "Please run \"make test\" first to generate a cover profile" ; exit 1; fi
@go tool cover -html=$(COVER_FILE)
@echo "Check your web browser to see the cover profile"
###
# Run integration tests for all available backends
###
test-backends:
@testing/test_backends.sh
###
# Run integration tests for a single backend
# Usage: make test-backend mariadb
###
ifeq (test-backend,$(firstword $(MAKECMDGOALS)))
BACKEND_ARG := $(wordlist 2,2,$(MAKECMDGOALS))
$(eval $(BACKEND_ARG):;@:)
endif
test-backend:
@testing/test_backends.sh $(BACKEND_ARG)
###
# Build documentation
###
docs: client
@cd docs && npm ci && bash inject_version.sh && bash copy_architecture.sh && bash inject_plikrc.sh && bash inject_help.sh && npm run build
###
# Build a docker image locally
###
docker:
@docker buildx build --progress=plain --load -t rootgg/plik:dev .
###
# Create release archives
###
release:
@releaser/release.sh
###
# Create release archives, build a multiarch Docker image and push to Docker Hub
###
release-and-push-to-docker-hub:
@PUSH_TO_DOCKER_HUB=true releaser/release.sh
###
# Regenerate Helm chart README from values.yaml annotations
# Auto-installs helm-docs via go install if not found
###
helm-docs:
@command -v helm-docs >/dev/null 2>&1 || { echo "Installing helm-docs..." && go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest; }
@helm-docs --chart-search-root ./charts
###
# Package Helm chart locally (auto-detects version from git tags)
###
helm: helm-docs
@DRY_RUN=true releaser/helm_release.sh $(VERSION)
###
# Package and install Helm chart locally
###
helm-install: helm
@helm install plik releases/plik-helm-$(VERSION).tgz
###
# Build Debian packages locally for all Linux architectures
# Requires: nfpm (go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest)
# Requires: cross-compilers (apt install crossbuild-essential-{armhf,arm64,i386})
# Set DEB_TARGETS to override (e.g. DEB_TARGETS=amd64)
###
DEB_TARGETS ?= amd64 386 arm64 arm
deb: frontend clients
@echo ""
@echo " Building Debian packages for $(VERSION)"
@echo ""
@mkdir -p releases
@for GOARCH in $(DEB_TARGETS); do \
DEB_ARCH=$$GOARCH ; \
CROSS_CC="" ; \
case "$$GOARCH" in \
amd64) CROSS_CC="" ;; \
386) DEB_ARCH="i386" ; CROSS_CC="i686-linux-gnu-gcc" ;; \
arm64) CROSS_CC="aarch64-linux-gnu-gcc" ;; \
arm) DEB_ARCH="armhf" ; CROSS_CC="arm-linux-gnueabihf-gcc" ;; \
*) echo " Error: unknown GOARCH $$GOARCH, update the case statement in the deb target" ; exit 1 ;; \
esac ; \
if [ -n "$$CROSS_CC" ] && ! command -v "$$CROSS_CC" >/dev/null 2>&1; then \
echo " Skipping $$DEB_ARCH ($$CROSS_CC not found)" ; \
continue ; \
fi ; \
echo "" ; \
echo " Building plik server ($$DEB_ARCH)" ; \
GOOS=linux GOARCH=$$GOARCH CGO_ENABLED=1 CC=$$CROSS_CC $(GO_BUILD) -o server/plikd ./server ; \
rm -rf release && mkdir -p release/server release/webapp ; \
cp server/plikd release/server/plikd ; \
cp server/plikd.cfg release/server/plikd.cfg ; \
cp -r webapp/dist release/webapp/dist ; \
cp -r clients release/clients ; \
cp -r changelog release/changelog ; \
echo " Packaging plik-server ($$DEB_ARCH)" ; \
VERSION=$(VERSION) DEB_ARCH=$$DEB_ARCH \
nfpm pkg --config releaser/nfpm-server.yaml --packager deb --target releases/ ; \
if [ -f "release/clients/linux-$$GOARCH/plik" ]; then \
echo " Packaging plik-client ($$DEB_ARCH)" ; \
mkdir -p release/client ; \
cp "release/clients/linux-$$GOARCH/plik" release/client/plik ; \
VERSION=$(VERSION) DEB_ARCH=$$DEB_ARCH \
nfpm pkg --config releaser/nfpm-client.yaml --packager deb --target releases/ ; \
fi ; \
done
@rm -rf release
@echo ""
@echo " Packages built:"
@ls -l releases/*.deb
###
# Remove server build files
###
clean:
@rm -rf server/plikd
@rm -rf client/plik
@rm -rf clients
@rm -rf servers
@rm -rf release
@rm -rf releases
###
# Remove frontend build files
###
clean-frontend:
@rm -rf webapp/dist
###
# Remove all build files and node modules
###
clean-all: clean clean-frontend
@rm -rf webapp/node_modules
###
# Publish existing .deb packages to the gh-pages APT repository
# Run after "make deb" to push packages without a full release
###
deb-publish:
@SKIP_BUILD=true releaser/apt_release.sh $(VERSION)
###
# Since the client/server/version directories are not generated
# by make, we must declare these targets as phony to avoid :
# "make: `client' is up to date" cases at compile time
###
.PHONY: client clients server release helm helm-docs helm-install deb deb-publish docs test-backend test-bash-client test-frontend test-frontend-e2e