Compare commits

...

14 Commits

Author SHA1 Message Date
silverwind 3f2b3bfe73
Merge 03dd059c20 into 970965f6d8 2024-04-28 12:14:26 +08:00
Chongyi Zheng 970965f6d8
Fix nil dereference on error (#30740)
In both cases, the `err` is nil because of `if` checks before

Reference: #30729
2024-04-28 12:13:57 +08:00
silverwind 03dd059c20
add || true 2024-04-27 22:30:08 +02:00
silverwind 3c48b39b8c
hide stderr 2024-04-27 22:03:17 +02:00
silverwind 399be95ce5
always run script in repo root 2024-04-27 21:10:40 +02:00
silverwind 7e54674daf
Update tools/lint-go-gopls.sh 2024-04-27 21:09:39 +02:00
silverwind 922fa2c954
add lint script 2024-04-27 21:06:52 +02:00
silverwind cab07abf55
Revert "run build before lint-backend"
This reverts commit f7b0d9a975.
2024-04-27 19:41:02 +02:00
silverwind f7b0d9a975
run build before lint-backend 2024-04-27 18:49:29 +02:00
silverwind 57287d7837
add to deps-tools 2024-04-27 14:42:01 +02:00
silverwind 2a7bd1a46b
fix cmd 2024-04-27 12:25:51 +02:00
silverwind 29774f7c84
use exact version 2024-04-27 12:19:47 +02:00
silverwind e86f46ba82
use go run 2024-04-27 12:19:02 +02:00
silverwind aed16ec656
Add `lint-go-gopls` 2024-04-27 12:03:33 +02:00
4 changed files with 34 additions and 6 deletions

View File

@ -36,6 +36,7 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.15.3
DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
@ -213,6 +214,7 @@ help:
@echo " - lint-go lint go files"
@echo " - lint-go-fix lint go files and fix issues"
@echo " - lint-go-vet lint go files with vet"
@echo " - lint-go-gopls lint go files with gopls"
@echo " - lint-js lint js files"
@echo " - lint-js-fix lint js files and fix issues"
@echo " - lint-css lint css files"
@ -366,7 +368,7 @@ lint-frontend: lint-js lint-css
lint-frontend-fix: lint-js-fix lint-css-fix
.PHONY: lint-backend
lint-backend: lint-go lint-go-vet lint-editorconfig
lint-backend: lint-go lint-go-vet lint-go-gopls lint-editorconfig
.PHONY: lint-backend-fix
lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
@ -424,7 +426,12 @@ lint-go-vet:
@GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
@$(GO) vet -vettool=gitea-vet ./...
.PHONY: lint-editorconfig
.PHONY: lint-go-gopls
lint-go-gopls:
@echo "Running gopls check..."
# TODO: Fix all errors and remove '|| true'
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA) || true
lint-editorconfig:
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
@ -864,6 +871,7 @@ deps-tools:
$(GO) install $(GO_LICENSES_PACKAGE)
$(GO) install $(GOVULNCHECK_PACKAGE)
$(GO) install $(ACTIONLINT_PACKAGE)
$(GO) install $(GOPLS_PACKAGE)
node_modules: package-lock.json
npm install --no-save

View File

@ -466,14 +466,15 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) {
log.Error("Error getting artifact: %v", err)
ctx.Error(http.StatusInternalServerError, err.Error())
return
} else if !exist {
}
if !exist {
log.Error("artifact with ID %d does not exist", artifactID)
ctx.Error(http.StatusNotFound, fmt.Sprintf("artifact with ID %d does not exist", artifactID))
return
}
if artifact.RunID != runID {
log.Error("Error dismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
ctx.Error(http.StatusBadRequest, err.Error())
log.Error("Error mismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
ctx.Error(http.StatusBadRequest)
return
}

View File

@ -504,7 +504,7 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
return nil, nil
}
if len(jobs) == 0 {
ctx.Error(http.StatusNotFound, err.Error())
ctx.Error(http.StatusNotFound)
return nil, nil
}

19
tools/lint-go-gopls.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
cd "$(dirname -- "${BASH_SOURCE[0]}")" && cd ..
# lint all go files with 'gopls check' and look for lines starting with the
# current absolute path, indicating a error was found. This is neccessary
# because the tool does not set non-zero exit code when errors are found.
# ref: https://github.com/golang/go/issues/67078
ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check $@ 2>/dev/null | grep -E "^$PWD");
NUM_ERRORS=$(echo "$ERROR_LINES" | wc -l)
if [ "$NUM_ERRORS" -eq "0" ]; then
exit 0;
else
echo "$ERROR_LINES"
echo "Found $NUM_ERRORS 'gopls check' errors"
exit 1;
fi