Revert the minimal golang version requirement from 1.17 to 1.16 and add a warning in Makefile (#19319)

* Revert the minimal golang version requirement from 1.17 to 1.16 and add a warning in Makefile

* Apply suggestions from code review

Co-authored-by: John Olheiser <john.olheiser@gmail.com>

* 1.16

* Update modules/util/net.go

Co-authored-by: Gusted <williamzijl7@hotmail.com>

* correct bool conditional

yay tests for catching this :)

* Update hostmatcher.go

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
This commit is contained in:
Lunny Xiao 2022-04-06 01:32:24 +08:00 committed by GitHub
parent 14a6aafb50
commit 0704009dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 7 deletions

View File

@ -109,7 +109,7 @@ steps:
depends_on: [test-frontend] depends_on: [test-frontend]
- name: build-backend-no-gcc - name: build-backend-no-gcc
image: golang:1.17 # this step is kept as the lowest version of golang that we support image: golang:1.16 # this step is kept as the lowest version of golang that we support
pull: always pull: always
environment: environment:
GO111MODULE: on GO111MODULE: on

View File

@ -203,10 +203,13 @@ help:
go-check: go-check:
$(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2)) $(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
$(eval MIN_GO_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' '))) $(eval MIN_GO_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ')))
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');)) $(eval GO_VERSION_STR := $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+'))
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(GO_VERSION_STR)' | tr '.' ' ')))
@if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \ @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \ echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build, but $(GO_VERSION) was found. You can get an updated version at https://go.dev/dl/"; \
exit 1; \ exit 1; \
else \
echo "WARNING: Please ensure Go $(GO_VERSION_STR) is still maintained to avoid possible security problems. You can check it at https://go.dev/dl/"; \
fi fi
.PHONY: git-check .PHONY: git-check

View File

@ -19,7 +19,7 @@ params:
author: The Gitea Authors author: The Gitea Authors
website: https://docs.gitea.io website: https://docs.gitea.io
version: 1.16.4 version: 1.16.4
minGoVersion: 1.17 minGoVersion: 1.16
goVersion: 1.18 goVersion: 1.18
minNodeVersion: 12.17 minNodeVersion: 12.17

2
go.mod
View File

@ -1,6 +1,6 @@
module code.gitea.io/gitea module code.gitea.io/gitea
go 1.17 go 1.16
require ( require (
cloud.google.com/go v0.99.0 // indirect cloud.google.com/go v0.99.0 // indirect

View File

@ -8,6 +8,8 @@ import (
"net" "net"
"path/filepath" "path/filepath"
"strings" "strings"
"code.gitea.io/gitea/modules/util"
) )
// HostMatchList is used to check if a host or IP is in a list. // HostMatchList is used to check if a host or IP is in a list.
@ -102,11 +104,11 @@ func (hl *HostMatchList) checkIP(ip net.IP) bool {
for _, builtin := range hl.builtins { for _, builtin := range hl.builtins {
switch builtin { switch builtin {
case MatchBuiltinExternal: case MatchBuiltinExternal:
if ip.IsGlobalUnicast() && !ip.IsPrivate() { if ip.IsGlobalUnicast() && !util.IsIPPrivate(ip) {
return true return true
} }
case MatchBuiltinPrivate: case MatchBuiltinPrivate:
if ip.IsPrivate() { if util.IsIPPrivate(ip) {
return true return true
} }
case MatchBuiltinLoopback: case MatchBuiltinLoopback:

19
modules/util/net.go Normal file
View File

@ -0,0 +1,19 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package util
import (
"net"
)
// IsIPPrivate for net.IP.IsPrivate.
func IsIPPrivate(ip net.IP) bool {
if ip4 := ip.To4(); ip4 != nil {
return ip4[0] == 10 ||
(ip4[0] == 172 && ip4[1]&0xf0 == 16) ||
(ip4[0] == 192 && ip4[1] == 168)
}
return len(ip) == net.IPv6len && ip[0]&0xfe == 0xfc
}