mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
scripts: Verify that we are not using restricted packages
It checks that we are not directly importing 'sync/atomic'. Signed-off-by: Javier Palomo <javier.palomo.almena@gmail.com>
This commit is contained in:
parent
e825a3fab3
commit
278d32748e
|
@ -118,7 +118,7 @@ endif
|
||||||
%: common-% ;
|
%: common-% ;
|
||||||
|
|
||||||
.PHONY: common-all
|
.PHONY: common-all
|
||||||
common-all: precheck style check_license lint unused build test
|
common-all: precheck restricted_imports style check_license lint unused build test
|
||||||
|
|
||||||
.PHONY: common-style
|
.PHONY: common-style
|
||||||
common-style:
|
common-style:
|
||||||
|
@ -270,6 +270,11 @@ proto:
|
||||||
@echo ">> generating code from proto files"
|
@echo ">> generating code from proto files"
|
||||||
@./scripts/genproto.sh
|
@./scripts/genproto.sh
|
||||||
|
|
||||||
|
.PHONY: common-restricted_imports
|
||||||
|
common-restricted_imports:
|
||||||
|
@echo ">> verifying that we are not using restricted packages"
|
||||||
|
@./scripts/check_restricted_imports.sh
|
||||||
|
|
||||||
ifdef GOLANGCI_LINT
|
ifdef GOLANGCI_LINT
|
||||||
$(GOLANGCI_LINT):
|
$(GOLANGCI_LINT):
|
||||||
mkdir -p $(FIRST_GOPATH)/bin
|
mkdir -p $(FIRST_GOPATH)/bin
|
||||||
|
|
27
scripts/check_restricted_imports.sh
Executable file
27
scripts/check_restricted_imports.sh
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Checks that restricted packages are not being imported.
|
||||||
|
# Run from repository root.
|
||||||
|
#set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
if ! [[ "$0" =~ "scripts/check_restricted_imports.sh" ]]; then
|
||||||
|
echo "must be run from repository root"
|
||||||
|
exit 255
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit_status=0
|
||||||
|
|
||||||
|
packages=(
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
for package in "${packages[@]}"
|
||||||
|
do
|
||||||
|
# Grep exits with 0 if there is at least one match
|
||||||
|
if output=$(grep -nir "${package}" --exclude-dir=vendor --exclude-dir=scripts ./*); then
|
||||||
|
exit_status=1
|
||||||
|
echo "Restricted package '${package}' is being used in the following files:"
|
||||||
|
echo "${output}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit ${exit_status}
|
Loading…
Reference in a new issue