-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_pre_commit.sh
More file actions
executable file
·62 lines (51 loc) · 1.4 KB
/
Copy pathsetup_pre_commit.sh
File metadata and controls
executable file
·62 lines (51 loc) · 1.4 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
#!/bin/bash
set -e
# 安装 pre-commit 工具
if ! command -v pre-commit &> /dev/null
then
echo "pre-commit not found, installing..."
brew install pre-commit
else
echo "pre-commit is already installed"
fi
# 检查并 Go 版本
if ! command -v go &> /dev/null
then
echo "Go not found, please install Go first."
exit 1
else
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
MIN_GO_VERSION="1.22"
if [ "$(printf '%s\n' "$MIN_GO_VERSION" "$GO_VERSION" | sort -V | head -n1)" != "$MIN_GO_VERSION" ]; then
echo "Go version $GO_VERSION is not supported. Please install Go version $MIN_GO_VERSION or higher."
exit 1
fi
fi
# 安装 golangci-lint
if ! command -v golangci-lint &> /dev/null
then
echo "Installing golangci-lint..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
else
echo "golangci-lint is already installed"
fi
# 安装 typos
if ! command -v typos &> /dev/null
then
echo "Installing typos..."
brew install typos-cli
else
echo "typos is already installed"
fi
# 安装 swag
if ! command -v swag &> /dev/null
then
echo "Installing swag(v1.16.3)..."
go install github.com/swaggo/swag/cmd/swag@v1.16.3
else
echo "swag(v1.16.3) is already installed"
fi
# 安装 pre-commit hooks
echo "Installing pre-commit hooks..."
pre-commit install
echo "All done! pre-commit hooks are installed and configured."