Skip to content

Commit 55c5e05

Browse files
committed
Use go run for tool dependencies, require go 1.17
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: #18867
1 parent efd10f1 commit 55c5e05

File tree

7 files changed

+60
-69
lines changed

7 files changed

+60
-69
lines changed

.drone.yml

Lines changed: 11 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ linters:
2323
fast: false
2424

2525
run:
26-
timeout: 3m
26+
timeout: 10m
2727
skip-dirs:
2828
- node_modules
2929
- public
@@ -64,7 +64,7 @@ linters-settings:
6464
- name: modifies-value-receiver
6565
gofumpt:
6666
extra-rules: true
67-
lang-version: 1.16
67+
lang-version: 1.17
6868

6969
issues:
7070
exclude-rules:

Makefile

Lines changed: 41 additions & 59 deletions
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 := 001044000
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,11 +241,8 @@ clean:
234241

235242
.PHONY: fmt
236243
fmt:
237-
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
238-
$(GO) install mvdan.cc/[email protected]; \
239-
fi
240244
@echo "Running gitea-fmt (with gofumpt)..."
241-
@$(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
245+
@MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
242246

243247
.PHONY: vet
244248
vet:
@@ -257,7 +261,7 @@ endif
257261

258262
.PHONY: generate-swagger
259263
generate-swagger:
260-
$(SWAGGER) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
264+
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
261265
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
262266
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
263267

@@ -273,24 +277,18 @@ swagger-check: generate-swagger
273277
.PHONY: swagger-validate
274278
swagger-validate:
275279
$(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
276-
$(SWAGGER) validate './$(SWAGGER_SPEC)'
280+
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
277281
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
278282

279283
.PHONY: errcheck
280284
errcheck:
281-
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
282-
$(GO) install github.com/kisielk/errcheck@8ddee489636a8311a376fc92e27a6a13c6658344; \
283-
fi
284285
@echo "Running errcheck..."
285-
@errcheck $(GO_PACKAGES)
286+
$(GO) run $(ERRCHECK_PACKAGE) $(GO_PACKAGES)
286287

287288
.PHONY: fmt-check
288289
fmt-check:
289-
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
290-
$(GO) install mvdan.cc/[email protected]; \
291-
fi
292290
# get all go files and run gitea-fmt (with gofmt) on them
293-
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \
291+
@diff=$$(MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \
294292
if [ -n "$$diff" ]; then \
295293
echo "Please run 'make fmt' and commit the result:"; \
296294
echo "$${diff}"; \
@@ -328,10 +326,7 @@ watch-frontend: node-check node_modules
328326

329327
.PHONY: watch-backend
330328
watch-backend: go-check
331-
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
332-
$(GO) install github.com/cosmtrek/air@bedc18201271882c2be66d216d0e1a275b526ec4; \
333-
fi
334-
air -c .air.toml
329+
$(GO) run $(AIR_PACKAGE) -c .air.toml
335330

336331
.PHONY: test
337332
test: test-frontend test-backend
@@ -611,33 +606,24 @@ $(DIST_DIRS):
611606

612607
.PHONY: release-windows
613608
release-windows: | $(DIST_DIRS)
614-
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
615-
$(GO) install src.techknowlogick.com/xgo@latest; \
616-
fi
617-
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) .
609+
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) .
618610
ifeq (,$(findstring gogit,$(TAGS)))
619-
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 .
611+
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 .
620612
endif
621613
ifeq ($(CI),drone)
622614
cp /build/* $(DIST)/binaries
623615
endif
624616

625617
.PHONY: release-linux
626618
release-linux: | $(DIST_DIRS)
627-
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
628-
$(GO) install src.techknowlogick.com/xgo@latest; \
629-
fi
630-
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) .
619+
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) .
631620
ifeq ($(CI),drone)
632621
cp /build/* $(DIST)/binaries
633622
endif
634623

635624
.PHONY: release-darwin
636625
release-darwin: | $(DIST_DIRS)
637-
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
638-
$(GO) install src.techknowlogick.com/xgo@latest; \
639-
fi
640-
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) .
626+
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) .
641627
ifeq ($(CI),drone)
642628
cp /build/* $(DIST)/binaries
643629
endif
@@ -652,10 +638,7 @@ release-check: | $(DIST_DIRS)
652638

653639
.PHONY: release-compress
654640
release-compress: | $(DIST_DIRS)
655-
@hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
656-
$(GO) install github.com/ulikunitz/xz/cmd/[email protected]; \
657-
fi
658-
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
641+
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PAGAGE) -k -9 $${file}; done;
659642

660643
.PHONY: release-sources
661644
release-sources: | $(DIST_DIRS)
@@ -685,6 +668,15 @@ deps-frontend: node_modules
685668
.PHONY: deps-backend
686669
deps-backend:
687670
$(GO) mod download
671+
$(GO) install $(AIR_PACKAGE)
672+
$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
673+
$(GO) install $(ERRCHECK_PACKAGE)
674+
$(GO) install $(GOFUMPT_PACKAGE)
675+
$(GO) install $(GOLANGCI_LINT_PACKAGE)
676+
$(GO) install $(GXZ_PAGAGE)
677+
$(GO) install $(MISSPELL_PACKAGE)
678+
$(GO) install $(SWAGGER_PACKAGE)
679+
$(GO) install $(XGO_PACKAGE)
688680

689681
node_modules: package-lock.json
690682
npm install --no-save
@@ -778,29 +770,19 @@ pr\#%: clean-all
778770
$(GO) run contrib/pr/checkout.go $*
779771

780772
.PHONY: golangci-lint
781-
golangci-lint: golangci-lint-check
782-
golangci-lint run --timeout 10m
783-
784-
.PHONY: golangci-lint-check
785-
golangci-lint-check:
786-
$(eval GOLANGCI_LINT_VERSION := $(shell printf "%03d%03d%03d" $(shell golangci-lint --version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
787-
$(eval MIN_GOLANGCI_LINT_VER_FMT := $(shell printf "%g.%g.%g" $(shell echo $(MIN_GOLANGCI_LINT_VERSION) | grep -o ...)))
788-
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
789-
echo "Downloading golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT}"; \
790-
export BINARY="golangci-lint"; \
791-
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); \
792-
elif [ "$(GOLANGCI_LINT_VERSION)" -lt "$(MIN_GOLANGCI_LINT_VERSION)" ]; then \
793-
echo "Downloading newer version of golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT}"; \
794-
export BINARY="golangci-lint"; \
795-
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); \
796-
fi
773+
golangci-lint:
774+
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
775+
776+
# workaround step for the lint-backend-windows CI task because 'go run' can not
777+
# have distinct GOOS/GOARCH for its build and run steps
778+
.PHONY: golangci-lint-windows
779+
golangci-lint-windows:
780+
@GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE)
781+
golangci-lint run
797782

798783
.PHONY: editorconfig-checker
799784
editorconfig-checker:
800-
@hash editorconfig-checker > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
801-
$(GO) install github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@50adf46752da119dfef66e57be3ce2693ea4aa9c; \
802-
fi
803-
editorconfig-checker templates
785+
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates
804786

805787
.PHONY: docker
806788
docker:

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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,
@@ -271,9 +271,9 @@ func main() {
271271
log.Print("the -d option is not supported by gitea-fmt")
272272
}
273273
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-l"), containsString(subArgs, "-w")))
274-
cmdErrors = append(cmdErrors, passThroughCmd("gofumpt", append([]string{"-extra", "-lang", "1.16"}, substArgs...)))
274+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", "1.17"}, substArgs...)))
275275
case "misspell":
276-
cmdErrors = append(cmdErrors, passThroughCmd("misspell", substArgs))
276+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("MISSPELL_PACKAGE")}, substArgs...)))
277277
default:
278278
log.Fatalf("unknown cmd: %s %v", subCmd, subArgs)
279279
}

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.16.0
22-
minGoVersion: 1.16
22+
minGoVersion: 1.17
2323
goVersion: 1.17
2424
minNodeVersion: 12.17
2525

go.mod

Lines changed: 1 addition & 1 deletion
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)