Skip to content

Commit bb99f17

Browse files
Use go run for tool dependencies, require go 1.17 (go-gitea#18874)
This ensures the tools only run in the versions we've tested and it also does not polute PATH with those tools so they are truly isolated. This syntax of `go run` requires go 1.17, so the minimum version is set accordingly. Fixes: go-gitea#18867 Co-authored-by: techknowlogick <[email protected]>
1 parent 9bcbbd4 commit bb99f17

File tree

7 files changed

+68
-60
lines changed

7 files changed

+68
-60
lines changed

.drone.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,24 @@ steps:
4949
GOSUMDB: sum.golang.org
5050
TAGS: bindata sqlite sqlite_unlock_notify
5151
depends_on: [deps-backend]
52+
volumes:
53+
- name: deps
54+
path: /go
5255

5356
- name: lint-backend-windows
5457
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
5558
commands:
56-
- make golangci-lint vet
59+
- make golangci-lint-windows vet
5760
environment:
5861
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
5962
GOSUMDB: sum.golang.org
6063
TAGS: bindata sqlite sqlite_unlock_notify
6164
GOOS: windows
6265
GOARCH: amd64
6366
depends_on: [deps-backend]
67+
volumes:
68+
- name: deps
69+
path: /go
6470

6571
- name: lint-backend-gogit
6672
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
@@ -71,6 +77,9 @@ steps:
7177
GOSUMDB: sum.golang.org
7278
TAGS: bindata gogit sqlite sqlite_unlock_notify
7379
depends_on: [deps-backend]
80+
volumes:
81+
- name: deps
82+
path: /go
7483

7584
- name: checks-frontend
7685
image: node:16
@@ -100,7 +109,7 @@ steps:
100109
depends_on: [test-frontend]
101110

102111
- name: build-backend-no-gcc
103-
image: golang:1.16 # this step is kept as the lowest version of golang that we support
112+
image: golang:1.17 # this step is kept as the lowest version of golang that we support
104113
pull: always
105114
environment:
106115
GO111MODULE: on

.golangci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ linters:
2222
fast: false
2323

2424
run:
25-
timeout: 3m
25+
timeout: 10m
2626
skip-dirs:
2727
- node_modules
2828
- public
@@ -61,6 +61,9 @@ linters-settings:
6161
- name: errorf
6262
- name: duplicated-imports
6363
- name: modifies-value-receiver
64+
gofumpt:
65+
extra-rules: true
66+
lang-version: 1.17
6467

6568
issues:
6669
exclude-rules:

Makefile

+45-50
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
2525
COMMA := ,
2626

2727
XGO_VERSION := go-1.17.x
28-
MIN_GO_VERSION := 001016000
28+
MIN_GO_VERSION := 001017000
2929
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
3140

3241
DOCKER_IMAGE ?= gitea/gitea
3342
DOCKER_TAG ?= latest
@@ -125,8 +134,6 @@ ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
125134
GO_SOURCES += $(BINDATA_DEST)
126135
endif
127136

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
130137
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
131138
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
132139
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
@@ -234,8 +241,8 @@ clean:
234241

235242
.PHONY: fmt
236243
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}'
239246

240247
.PHONY: vet
241248
vet:
@@ -254,7 +261,7 @@ endif
254261

255262
.PHONY: generate-swagger
256263
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)'
258265
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
259266
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
260267

@@ -270,21 +277,18 @@ swagger-check: generate-swagger
270277
.PHONY: swagger-validate
271278
swagger-validate:
272279
$(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
273-
$(SWAGGER) validate './$(SWAGGER_SPEC)'
280+
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
274281
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
275282

276283
.PHONY: errcheck
277284
errcheck:
278-
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
279-
$(GO) install github.com/kisielk/errcheck@8ddee489636a8311a376fc92e27a6a13c6658344; \
280-
fi
281285
@echo "Running errcheck..."
282-
@errcheck $(GO_PACKAGES)
286+
$(GO) run $(ERRCHECK_PACKAGE) $(GO_PACKAGES)
283287

284288
.PHONY: fmt-check
285289
fmt-check:
286290
# 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}'); \
288292
if [ -n "$$diff" ]; then \
289293
echo "Please run 'make fmt' and commit the result:"; \
290294
echo "$${diff}"; \
@@ -323,10 +327,7 @@ watch-frontend: node-check node_modules
323327

324328
.PHONY: watch-backend
325329
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
330331

331332
.PHONY: test
332333
test: test-frontend test-backend
@@ -599,33 +600,24 @@ $(DIST_DIRS):
599600

600601
.PHONY: release-windows
601602
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) .
606604
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 .
608606
endif
609607
ifeq ($(CI),drone)
610608
cp /build/* $(DIST)/binaries
611609
endif
612610

613611
.PHONY: release-linux
614612
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) .
619614
ifeq ($(CI),drone)
620615
cp /build/* $(DIST)/binaries
621616
endif
622617

623618
.PHONY: release-darwin
624619
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) .
629621
ifeq ($(CI),drone)
630622
cp /build/* $(DIST)/binaries
631623
endif
@@ -640,10 +632,7 @@ release-check: | $(DIST_DIRS)
640632

641633
.PHONY: release-compress
642634
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;
647636

648637
.PHONY: release-sources
649638
release-sources: | $(DIST_DIRS)
@@ -673,6 +662,15 @@ deps-frontend: node_modules
673662
.PHONY: deps-backend
674663
deps-backend:
675664
$(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)
676674

677675
node_modules: package-lock.json
678676
npm install --no-save
@@ -766,22 +764,19 @@ pr\#%: clean-all
766764
$(GO) run contrib/pr/checkout.go $*
767765

768766
.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
785780

786781
.PHONY: docker
787782
docker:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ or if SQLite support is required:
7373

7474
The `build` target is split into two sub-targets:
7575

76-
- `make backend` which requires [Go 1.16](https://golang.org/dl/) or greater.
76+
- `make backend` which requires [Go 1.17](https://golang.org/dl/) or greater.
7777
- `make frontend` which requires [Node.js LTS](https://nodejs.org/en/download/) or greater and Internet connectivity to download npm dependencies.
7878

7979
When building from the official source tarballs which include pre-built frontend files, the `frontend` target will not be triggered, making it possible to build without Node.js and Internet connectivity.

build/code-batch-process.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func passThroughCmd(cmd string, args []string) error {
4040
}
4141
c := exec.Cmd{
4242
Path: foundCmd,
43-
Args: args,
43+
Args: append([]string{cmd}, args...),
4444
Stdin: os.Stdin,
4545
Stdout: os.Stdout,
4646
Stderr: os.Stderr,
@@ -270,9 +270,10 @@ func main() {
270270
if containsString(subArgs, "-w") {
271271
cmdErrors = append(cmdErrors, giteaFormatGoImports(files))
272272
}
273-
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", substArgs))
273+
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-l"), containsString(subArgs, "-w")))
274+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", "1.17"}, substArgs...)))
274275
case "misspell":
275-
cmdErrors = append(cmdErrors, passThroughCmd("misspell", substArgs))
276+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("MISSPELL_PACKAGE")}, substArgs...)))
276277
default:
277278
log.Fatalf("unknown cmd: %s %v", subCmd, subArgs)
278279
}

docs/config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.16.0
22-
minGoVersion: 1.16
21+
version: 1.16.4
22+
minGoVersion: 1.17
2323
goVersion: 1.17
2424
minNodeVersion: 12.17
2525

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.16
3+
go 1.17
44

55
require (
66
cloud.google.com/go v0.78.0 // indirect

0 commit comments

Comments
 (0)