-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcheck.sh
More file actions
executable file
·87 lines (74 loc) · 2 KB
/
check.sh
File metadata and controls
executable file
·87 lines (74 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
set -euo pipefail
export GOEXPERIMENT=jsonv2
# Print separator
print_separator() {
echo "=================================================="
}
# Check if command exists
command_exists() {
if ! command -v "$1" &> /dev/null; then
return 1
fi
return 0
}
# Install modernize
install_modernize() {
echo "modernize not found, installing..."
go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest
# Add GOPATH/bin to PATH if needed
if ! command_exists modernize; then
export PATH="$PATH:$(go env GOPATH)/bin"
fi
if ! command_exists modernize; then
echo "Error: Failed to install modernize. Please install it manually:"
echo " go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest"
exit 1
fi
echo "modernize installed successfully"
}
# Show help
show_help() {
echo "Usage: ./check.sh [options]"
echo ""
echo "Runs code fixes, modernization, and tests"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
}
# Parse arguments
if [ $# -gt 0 ]; then
case "$1" in
-h|--help)
show_help
;;
esac
fi
# Check dependencies
if ! command_exists go; then
echo "Error: go is not installed"
exit 1
fi
# Check and install modernize if needed
if ! command_exists modernize; then
install_modernize
fi
# Find fmt.Errorf and errors.New function calls, excluding vendor directory
find . -type f -name '*.go' ! -path './vendor/*' -exec grep -Hn 'fmt\.Errorf' {} \;
find . -type f -name '*.go' ! -path './vendor/*' -exec grep -Hn 'errors\.New' {} \;
print_separator
echo "Step 1/3: Running go fix..."
print_separator
go fix ./...
print_separator
echo "Step 2/3: Running modernize..."
print_separator
modernize -test ./...
print_separator
echo "Step 3/3: Running tests..."
print_separator
go test -gcflags="all=-N -l" -count=1 ./...
print_separator
echo "✅ All checks passed!"
print_separator