chore: add lint for codersdk dependencies (#14638)

This commit is contained in:
Ethan
2024-09-12 15:34:03 +10:00
committed by GitHub
parent efd532e1d7
commit 33e896d404
3 changed files with 46 additions and 0 deletions
+1
View File
@@ -451,6 +451,7 @@ lint/ts:
lint/go: lint/go:
./scripts/check_enterprise_imports.sh ./scripts/check_enterprise_imports.sh
./scripts/check_codersdk_imports.sh
linter_ver=$(shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/contents/Dockerfile | cut -d '=' -f 2) linter_ver=$(shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/contents/Dockerfile | cut -d '=' -f 2)
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run
.PHONY: lint/go .PHONY: lint/go
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# This file checks all codersdk imports to be sure it doesn't import any packages
# that are being replaced in go.mod.
set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot
deps=$(./scripts/list_dependencies.sh github.com/coder/coder/v2/codersdk)
set +e
replaces=$(grep "^replace" go.mod | awk '{print $2}')
conflicts=$(echo "$deps" | grep -xF -f <(echo "$replaces"))
if [ -n "${conflicts}" ]; then
error "$(printf 'codersdk cannot import the following packages being replaced in go.mod:\n%s' "${conflicts}")"
fi
log "codersdk imports OK"
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# This script lists all dependencies of a given package, including dependencies
# of test files.
# Usage: list_dependencies <package>
set -euo pipefail
if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 <package>"
exit 1
fi
package="$1"
all_deps=$(go list -f '{{join .Deps "\n"}}' "$package")
test_imports=$(go list -f '{{ join .TestImports " " }}' "$package")
xtest_imports=$(go list -f '{{ join .XTestImports " " }}' "$package")
for pkg in $test_imports $xtest_imports; do
deps=$(go list -f '{{join .Deps "\n"}}' "$pkg")
all_deps+=$'\n'"$deps"
done
echo "$all_deps" | sort | uniq