-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Lint | ||
|
||
# 定义触发条件:在 `dev` 分支的 push 或 pull request 事件触发工作流 | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
pull_request: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
lint: | ||
# 指定工作流运行在最新的 Ubuntu 环境中 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# 第一步:检查出代码 | ||
- name: Checkout code | ||
uses: actions/checkout@v2 # 使用 GitHub 提供的 checkout 动作,确保代码在工作流环境中可用 | ||
|
||
# 第二步:设置 Go 环境 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 # 指定 Go 版本为 1.21 | ||
|
||
# 第三步:缓存 golangci-lint 的缓存文件 | ||
- name: Cache golangci-lint cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/golangci-lint # 指定缓存路径 | ||
key: ${{ runner.os }}-golangci-lint-${{ hashFiles('**/*.go') }} # 使用 Go 文件的哈希值作为缓存键值 | ||
restore-keys: | | ||
${{ runner.os }}-golangci-lint- # 当精确匹配失败时尝试还原此键,提升缓存命中率 | ||
# 第四步:安装 golangci-lint | ||
- name: Install golangci-lint | ||
run: | | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1 # 从官方脚本安装指定版本的 golangci-lint | ||
# 第五步:检查 golangci-lint 配置文件是否存在 | ||
- name: Check for golangci-lint config file | ||
run: | | ||
if [ ! -f .golangci.yml ]; then | ||
echo "golangci-lint config file (.golangci.yml) not found!"; # 若文件不存在,则输出错误信息 | ||
exit 1; # 退出并返回错误状态码 | ||
fi | ||
# 第六步:运行 golangci-lint | ||
- name: Run golangci-lint | ||
run: | | ||
golangci-lint run --config .golangci.yml --timeout=5m # 执行 lint 检查,使用指定的配置文件并设置超时时间为 5 分钟 |