mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: add lint for codersdk dependencies (#14638)
This commit is contained in:
@@ -451,6 +451,7 @@ lint/ts:
|
||||
|
||||
lint/go:
|
||||
./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)
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run
|
||||
.PHONY: lint/go
|
||||
|
||||
Executable
+20
@@ -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"
|
||||
Executable
+25
@@ -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
|
||||
Reference in New Issue
Block a user