mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Proposal to include a tidy check
(#27204)
* Initial tidy-check proposal * Add tidy check to Drone & CircleCI definitions Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
60cf95fa21
commit
b33dcf8213
@ -829,6 +829,7 @@ jobs:
|
||||
./pkg/services/provisioning/notifiers/... \
|
||||
./pkg/services/provisioning/values/... \
|
||||
./pkg/plugins/backendplugin/...
|
||||
./scripts/tidy-check.sh
|
||||
|
||||
test-frontend:
|
||||
executor: node
|
||||
|
@ -34,6 +34,7 @@ steps:
|
||||
- golangci-lint run --config scripts/go/configs/.golangci.toml ./pkg/...
|
||||
- revive -formatter stylish -config scripts/go/configs/revive.toml ./pkg/...
|
||||
- ./scripts/revive-strict
|
||||
- ./scripts/tidy-check.sh
|
||||
environment:
|
||||
CGO_ENABLED: 1
|
||||
depends_on:
|
||||
@ -257,6 +258,7 @@ steps:
|
||||
- golangci-lint run --config scripts/go/configs/.golangci.toml ./pkg/...
|
||||
- revive -formatter stylish -config scripts/go/configs/revive.toml ./pkg/...
|
||||
- ./scripts/revive-strict
|
||||
- ./scripts/tidy-check.sh
|
||||
environment:
|
||||
CGO_ENABLED: 1
|
||||
depends_on:
|
||||
|
8
Makefile
8
Makefile
@ -4,7 +4,7 @@
|
||||
|
||||
-include local/Makefile
|
||||
|
||||
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go revive golangci-lint test-go test-js test run run-frontend clean devenv devenv-down revive-strict protobuf help
|
||||
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go revive golangci-lint tidy-check test-go test-js test run run-frontend clean devenv devenv-down revive-strict protobuf help
|
||||
|
||||
GO = GO111MODULE=on go
|
||||
GO_FILES ?= ./pkg/...
|
||||
@ -95,7 +95,11 @@ golangci-lint: scripts/go/bin/golangci-lint
|
||||
--config ./scripts/go/configs/.golangci.toml \
|
||||
$(GO_FILES)
|
||||
|
||||
lint-go: golangci-lint revive revive-strict # Run all code checks for backend.
|
||||
tidy-check:
|
||||
@echo "check whether go.mod and go.sum are consistent"
|
||||
@scripts/tidy-check.sh
|
||||
|
||||
lint-go: golangci-lint revive revive-strict tidy-check # Run all code checks for backend.
|
||||
|
||||
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
|
||||
shellcheck: $(SH_FILES) ## Run checks for shell scripts.
|
||||
|
@ -250,6 +250,7 @@ def lint_backend_step(edition):
|
||||
'golangci-lint run --config scripts/go/configs/.golangci.toml ./pkg/...',
|
||||
'revive -formatter stylish -config scripts/go/configs/revive.toml ./pkg/...',
|
||||
'./scripts/revive-strict',
|
||||
'./scripts/tidy-check.sh',
|
||||
],
|
||||
}
|
||||
|
||||
|
35
scripts/tidy-check.sh
Executable file
35
scripts/tidy-check.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
|
||||
# Verify that Go is properly installed and available
|
||||
command -v go >/dev/null 2>&1 || { echo 'please install Go or use an image that has it'; exit 1; }
|
||||
|
||||
backup_go_mod_files()
|
||||
{
|
||||
mod=$(mktemp)
|
||||
cp go.mod "$mod"
|
||||
|
||||
sum=$(mktemp)
|
||||
cp go.sum "$sum"
|
||||
}
|
||||
|
||||
restore_go_mod_files()
|
||||
{
|
||||
cp "$mod" go.mod
|
||||
rm "$mod"
|
||||
|
||||
cp "$sum" go.sum
|
||||
rm "$sum"
|
||||
}
|
||||
|
||||
# Backup current go.mod and go.sum files
|
||||
backup_go_mod_files
|
||||
|
||||
# Defer the go.mod and go.sum files backup recovery
|
||||
trap restore_go_mod_files EXIT
|
||||
|
||||
# Tidy go.mod and go.sum files
|
||||
go mod tidy
|
||||
|
||||
diff "$mod" go.mod || { echo "your go.mod is inconsistent"; exit 1; }
|
||||
diff "$sum" go.sum || { echo "your go.sum is inconsistent"; exit 1; }
|
Loading…
Reference in New Issue
Block a user