@@ -25,9 +25,18 @@ HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
25
25
COMMA := ,
26
26
27
27
XGO_VERSION := go-1.17.x
28
- MIN_GO_VERSION := 001016000
28
+ MIN_GO_VERSION := 001017000
29
29
MIN_NODE_VERSION := 012017000
30
- MIN_GOLANGCI_LINT_VERSION := 001043000
30
+
31
+ AIR_PACKAGE ?= github.com/cosmtrek/air@bedc18201271882c2be66d216d0e1a275b526ec4
32
+ EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@50adf46752da119dfef66e57be3ce2693ea4aa9c
33
+ ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@8ddee489636a8311a376fc92e27a6a13c6658344
34
+ GOFUMPT_PACKAGE ?= mvdan.cc/
[email protected]
35
+ GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/
[email protected]
36
+ GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/
[email protected]
37
+ MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/
[email protected]
38
+ SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/
[email protected]
39
+ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
31
40
32
41
DOCKER_IMAGE ?= gitea/gitea
33
42
DOCKER_TAG ?= latest
@@ -125,8 +134,6 @@ ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
125
134
GO_SOURCES += $(BINDATA_DEST)
126
135
endif
127
136
128
- # To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
129
- SWAGGER := $(GO ) run github.com/go-swagger/go-swagger/cmd/swagger
130
137
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
131
138
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
132
139
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
@@ -234,8 +241,8 @@ clean:
234
241
235
242
.PHONY : fmt
236
243
fmt :
237
- @echo " Running gitea-fmt(with gofmt )..."
238
- @$( GO ) run build/code-batch-process.go gitea-fmt -s -w ' {file-list}'
244
+ @echo " Running gitea-fmt (with gofumpt )..."
245
+ @MISSPELL_PACKAGE= $( MISSPELL_PACKAGE ) GOFUMPT_PACKAGE= $( GOFUMPT_PACKAGE ) $( GO ) run build/code-batch-process.go gitea-fmt -w ' {file-list}'
239
246
240
247
.PHONY : vet
241
248
vet :
@@ -254,7 +261,7 @@ endif
254
261
255
262
.PHONY : generate-swagger
256
263
generate-swagger :
257
- $(SWAGGER ) generate spec -x " $( SWAGGER_EXCLUDE) " -o ' ./$(SWAGGER_SPEC)'
264
+ $(GO ) run $( SWAGGER_PACKAGE ) generate spec -x " $( SWAGGER_EXCLUDE) " -o ' ./$(SWAGGER_SPEC)'
258
265
$(SED_INPLACE ) ' $(SWAGGER_SPEC_S_TMPL)' ' ./$(SWAGGER_SPEC)'
259
266
$(SED_INPLACE ) $(SWAGGER_NEWLINE_COMMAND ) ' ./$(SWAGGER_SPEC)'
260
267
@@ -270,21 +277,18 @@ swagger-check: generate-swagger
270
277
.PHONY : swagger-validate
271
278
swagger-validate :
272
279
$(SED_INPLACE ) ' $(SWAGGER_SPEC_S_JSON)' ' ./$(SWAGGER_SPEC)'
273
- $(SWAGGER ) validate ' ./$(SWAGGER_SPEC)'
280
+ $(GO ) run $( SWAGGER_PACKAGE ) validate ' ./$(SWAGGER_SPEC)'
274
281
$(SED_INPLACE ) ' $(SWAGGER_SPEC_S_TMPL)' ' ./$(SWAGGER_SPEC)'
275
282
276
283
.PHONY : errcheck
277
284
errcheck :
278
- @hash errcheck > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
279
- $(GO ) install github.com/kisielk/errcheck@8ddee489636a8311a376fc92e27a6a13c6658344; \
280
- fi
281
285
@echo " Running errcheck..."
282
- @errcheck $(GO_PACKAGES )
286
+ $( GO ) run $( ERRCHECK_PACKAGE ) $(GO_PACKAGES )
283
287
284
288
.PHONY : fmt-check
285
289
fmt-check :
286
290
# get all go files and run gitea-fmt (with gofmt) on them
287
- @diff=$$($( GO ) run build/code-batch-process.go gitea-fmt -s -d '{file-list}') ; \
291
+ @diff=$$(MISSPELL_PACKAGE= $( MISSPELL_PACKAGE ) GOFUMPT_PACKAGE= $( GOFUMPT_PACKAGE ) $( GO ) run build/code-batch-process.go gitea-fmt -l '{file-list}' ) ; \
288
292
if [ -n " $$ diff" ]; then \
289
293
echo " Please run 'make fmt' and commit the result:" ; \
290
294
echo " $$ {diff}" ; \
@@ -323,10 +327,7 @@ watch-frontend: node-check node_modules
323
327
324
328
.PHONY : watch-backend
325
329
watch-backend : go-check
326
- @hash air > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
327
- $(GO ) install github.com/cosmtrek/air@bedc18201271882c2be66d216d0e1a275b526ec4; \
328
- fi
329
- air -c .air.toml
330
+ $(GO ) run $(AIR_PACKAGE ) -c .air.toml
330
331
331
332
.PHONY : test
332
333
test : test-frontend test-backend
@@ -599,33 +600,24 @@ $(DIST_DIRS):
599
600
600
601
.PHONY : release-windows
601
602
release-windows : | $(DIST_DIRS )
602
- @hash xgo > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
603
- $(GO ) install src.techknowlogick.com/xgo@latest; \
604
- fi
605
- CGO_CFLAGS=" $( CGO_CFLAGS) " xgo -go $(XGO_VERSION ) -buildmode exe -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' -linkmode external -extldflags "-static" $(LDFLAGS)' -targets ' windows/*' -out gitea-$(VERSION ) .
603
+ CGO_CFLAGS=" $( CGO_CFLAGS) " $(GO ) run $(XGO_PACKAGE ) -go $(XGO_VERSION ) -buildmode exe -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' -linkmode external -extldflags "-static" $(LDFLAGS)' -targets ' windows/*' -out gitea-$(VERSION ) .
606
604
ifeq (,$(findstring gogit,$(TAGS ) ) )
607
- CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo gogit $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION)-gogit .
605
+ CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo gogit $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION)-gogit .
608
606
endif
609
607
ifeq ($(CI ) ,drone)
610
608
cp /build/* $(DIST)/binaries
611
609
endif
612
610
613
611
.PHONY : release-linux
614
612
release-linux : | $(DIST_DIRS )
615
- @hash xgo > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
616
- $(GO ) install src.techknowlogick.com/xgo@latest; \
617
- fi
618
- CGO_CFLAGS=" $( CGO_CFLAGS) " xgo -go $(XGO_VERSION ) -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' -linkmode external -extldflags "-static" $(LDFLAGS)' -targets ' $(LINUX_ARCHS)' -out gitea-$(VERSION ) .
613
+ CGO_CFLAGS=" $( CGO_CFLAGS) " $(GO ) run $(XGO_PACKAGE ) -go $(XGO_VERSION ) -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' -linkmode external -extldflags "-static" $(LDFLAGS)' -targets ' $(LINUX_ARCHS)' -out gitea-$(VERSION ) .
619
614
ifeq ($(CI ) ,drone)
620
615
cp /build/* $(DIST)/binaries
621
616
endif
622
617
623
618
.PHONY : release-darwin
624
619
release-darwin : | $(DIST_DIRS )
625
- @hash xgo > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
626
- $(GO ) install src.techknowlogick.com/xgo@latest; \
627
- fi
628
- CGO_CFLAGS=" $( CGO_CFLAGS) " xgo -go $(XGO_VERSION ) -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' $(LDFLAGS)' -targets ' darwin-10.12/amd64,darwin-10.12/arm64' -out gitea-$(VERSION ) .
620
+ CGO_CFLAGS=" $( CGO_CFLAGS) " $(GO ) run $(XGO_PACKAGE ) -go $(XGO_VERSION ) -dest $(DIST ) /binaries -tags ' netgo osusergo $(TAGS)' -ldflags ' $(LDFLAGS)' -targets ' darwin-10.12/amd64,darwin-10.12/arm64' -out gitea-$(VERSION ) .
629
621
ifeq ($(CI ) ,drone)
630
622
cp /build/* $(DIST)/binaries
631
623
endif
@@ -640,10 +632,7 @@ release-check: | $(DIST_DIRS)
640
632
641
633
.PHONY : release-compress
642
634
release-compress : | $(DIST_DIRS )
643
- @hash gxz > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
644
- $(GO ) install github.com/ulikunitz/xz/cmd/
[email protected] ; \
645
- fi
646
- cd $(DIST ) /release/; for file in ` find . -type f -name " *" ` ; do echo " compressing $$ {file}" && gxz -k -9 $$ {file}; done ;
635
+ cd $(DIST ) /release/; for file in ` find . -type f -name " *" ` ; do echo " compressing $$ {file}" && $( GO) run $( GXZ_PAGAGE) -k -9 $$ {file}; done ;
647
636
648
637
.PHONY : release-sources
649
638
release-sources : | $(DIST_DIRS )
@@ -673,6 +662,15 @@ deps-frontend: node_modules
673
662
.PHONY : deps-backend
674
663
deps-backend :
675
664
$(GO ) mod download
665
+ $(GO ) install $(AIR_PACKAGE )
666
+ $(GO ) install $(EDITORCONFIG_CHECKER_PACKAGE )
667
+ $(GO ) install $(ERRCHECK_PACKAGE )
668
+ $(GO ) install $(GOFUMPT_PACKAGE )
669
+ $(GO ) install $(GOLANGCI_LINT_PACKAGE )
670
+ $(GO ) install $(GXZ_PAGAGE )
671
+ $(GO ) install $(MISSPELL_PACKAGE )
672
+ $(GO ) install $(SWAGGER_PACKAGE )
673
+ $(GO ) install $(XGO_PACKAGE )
676
674
677
675
node_modules : package-lock.json
678
676
npm install --no-save
@@ -766,22 +764,19 @@ pr\#%: clean-all
766
764
$(GO ) run contrib/pr/checkout.go $*
767
765
768
766
.PHONY : golangci-lint
769
- golangci-lint : golangci-lint-check
770
- golangci-lint run --timeout 10m
771
-
772
- .PHONY : golangci-lint-check
773
- golangci-lint-check :
774
- $(eval GOLANGCI_LINT_VERSION := $(shell printf "% 03d% 03d% 03d" $(shell golangci-lint --version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ') ;) )
775
- $(eval MIN_GOLANGCI_LINT_VER_FMT := $(shell printf "% g.% g.% g" $(shell echo $(MIN_GOLANGCI_LINT_VERSION ) | grep -o ...) ) )
776
- @hash golangci-lint > /dev/null 2>&1 ; if [ $$ ? -ne 0 ]; then \
777
- echo " Downloading golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT} " ; \
778
- export BINARY=" golangci-lint" ; \
779
- curl -sfL " https://raw.githubusercontent.com/golangci/golangci-lint/v${MIN_GOLANGCI_LINT_VER_FMT} /install.sh" | sh -s -- -b $(GOPATH ) /bin v$(MIN_GOLANGCI_LINT_VER_FMT ) ; \
780
- elif [ " $( GOLANGCI_LINT_VERSION) " -lt " $( MIN_GOLANGCI_LINT_VERSION) " ]; then \
781
- echo " Downloading newer version of golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT} " ; \
782
- export BINARY=" golangci-lint" ; \
783
- curl -sfL " https://raw.githubusercontent.com/golangci/golangci-lint/v${MIN_GOLANGCI_LINT_VER_FMT} /install.sh" | sh -s -- -b $(GOPATH ) /bin v$(MIN_GOLANGCI_LINT_VER_FMT ) ; \
784
- fi
767
+ golangci-lint :
768
+ $(GO ) run $(GOLANGCI_LINT_PACKAGE ) run
769
+
770
+ # workaround step for the lint-backend-windows CI task because 'go run' can not
771
+ # have distinct GOOS/GOARCH for its build and run steps
772
+ .PHONY : golangci-lint-windows
773
+ golangci-lint-windows :
774
+ @GOOS= GOARCH= $(GO ) install $(GOLANGCI_LINT_PACKAGE )
775
+ golangci-lint run
776
+
777
+ .PHONY : editorconfig-checker
778
+ editorconfig-checker :
779
+ $(GO ) run $(EDITORCONFIG_CHECKER_PACKAGE ) templates
785
780
786
781
.PHONY : docker
787
782
docker :
0 commit comments