1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ export GOEXPERIMENT=jsonv2
5+
6+ # Print separator
7+ print_separator () {
8+ echo " =================================================="
9+ }
10+
11+ # Check if command exists
12+ command_exists () {
13+ if ! command -v " $1 " & > /dev/null; then
14+ return 1
15+ fi
16+ return 0
17+ }
18+
19+ # Install modernize
20+ install_modernize () {
21+ echo " modernize not found, installing..."
22+ go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest
23+ # Add GOPATH/bin to PATH if needed
24+ if ! command_exists modernize; then
25+ export PATH=" $PATH :$( go env GOPATH) /bin"
26+ fi
27+ if ! command_exists modernize; then
28+ echo " Error: Failed to install modernize. Please install it manually:"
29+ echo " go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest"
30+ exit 1
31+ fi
32+ echo " modernize installed successfully"
33+ }
34+
35+ # Show help
36+ show_help () {
37+ echo " Usage: ./check.sh [options]"
38+ echo " "
39+ echo " Runs code fixes, modernization, and tests"
40+ echo " "
41+ echo " Options:"
42+ echo " -h, --help Show this help message"
43+ exit 0
44+ }
45+
46+ # Parse arguments
47+ if [ $# -gt 0 ]; then
48+ case " $1 " in
49+ -h|--help)
50+ show_help
51+ ;;
52+ esac
53+ fi
54+
55+ # Check dependencies
56+ if ! command_exists go; then
57+ echo " Error: go is not installed"
58+ exit 1
59+ fi
60+
61+ # Check and install modernize if needed
62+ if ! command_exists modernize; then
63+ install_modernize
64+ fi
65+
66+ print_separator
67+ echo " Step 1/3: Running go fix..."
68+ print_separator
69+ go fix ./...
70+
71+ print_separator
72+ echo " Step 2/3: Running modernize..."
73+ print_separator
74+ modernize -test ./...
75+
76+ print_separator
77+ echo " Step 3/3: Running tests..."
78+ print_separator
79+ go test -gcflags=" all=-N -l" -count=1 ./...
80+
81+ print_separator
82+ echo " ✅ All checks passed!"
83+ print_separator
0 commit comments