Skip to content

Commit

Permalink
add: 添加备注
Browse files Browse the repository at this point in the history
  • Loading branch information
moocss committed Nov 16, 2023
1 parent 74b4852 commit d14da90
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
APP_PATH:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SCRIPTS_PATH:=$(APP_PATH)/scripts

.PHONY: setup fmt lint test mocks test_coverage tidy check docker_up docker_down

GO_PKGS := $(shell go list -f {{.Dir}} ./...)

# 初始化环境
setup:
@sh ./scripts/setup.sh
@echo "初始化开发环境......"
@find "$(SCRIPTS_PATH)" -type f -name '*.sh' -exec chmod +x {} \;
@sh ${SCRIPTS_PATH}/setup.sh
@make tidy

# 代码风格
fmt:
@sh ./scripts/fmt.sh
@sh ${SCRIPTS_PATH}/fmt.sh

# 静态扫描
lint:
@golangci-lint run -c .golangci.yml

Expand All @@ -22,16 +30,21 @@ test_coverage:
mocks:
@go generate ./...

# 依赖清理
tidy:
@go mod tidy -v

check:
@echo "整理项目依赖中......"
@$(MAKE) --no-print-directory tidy
@echo "代码风格检查中......"
@$(MAKE) --no-print-directory fmt
@$(MAKE) --no-print-directory tidy
@echo "代码静态扫描中......"
@$(MAKE) lint

# docker 安装并运行服务
# 启动本地研发 docker 依赖
docker_up:
docker-compose -f scripts/docker/docker-compose.yml up -d
# docker 停止服务
# 停止本地研发 docker
docker_down:
docker-compose -f scripts/docker/docker-compose.yml down -v
3 changes: 2 additions & 1 deletion scripts/fmt.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh

goimports -l -w $(find . -type f -name '*.go' -not -path "./.idea/*")
goimports -l -w $(find . -type f -name '*.go' -not -path "./.idea/*")
gofumpt -l -w $(find . -type f -name '*.go' -not -path "./.idea/*")
30 changes: 26 additions & 4 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#!/bin/sh

SOURCE_COMMIT=.github/pre-commit
# Check Go installation
echo "检查 Go版本、Docker、Docker Compose V2......"
GO_VERSION="1.21" # Specify the required Go version
if ! command -v go >/dev/null || [[ ! "$(go version | awk '{print $3}')" == *"$GO_VERSION"* ]]; then
echo "Go $GO_VERSION 未安装或者版本不正确"
exit 1 # 退出并返回错误代码
fi

if ! command -v docker >/dev/null; then
echo "Docker 未安装"
exit 1 # Exit with an error code
fi

if ! command -v docker compose >/dev/null; then
echo "Docker Compose V2未安装"
exit 1 # Exit with an error code
fi

DIR="$(cd "$(dirname "$0")" && pwd)"
SOURCE_COMMIT=$DIR/git/pre-commit
TARGET_COMMIT=.git/hooks/pre-commit
SOURCE_PUSH=.github/pre-push
SOURCE_PUSH=$DIR/git/pre-push
TARGET_PUSH=.git/hooks/pre-push

# copy pre-commit file if not exist.
Expand All @@ -22,7 +41,10 @@ test -x $TARGET_PUSH || chmod +x $TARGET_PUSH
test -x $TARGET_COMMIT || chmod +x $TARGET_COMMIT

echo "安装 golangci-lint..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2

echo "安装 goimports..."
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/cmd/goimports@latest

echo "安装 gofumpt......"
go install mvdan.cc/gofumpt@latest

0 comments on commit d14da90

Please sign in to comment.