-
Notifications
You must be signed in to change notification settings - Fork 4
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
82 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,82 @@ | ||
name: Go Project CI Workflow | ||
|
||
# 定义触发条件 | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
schedule: | ||
- cron: '0 2 * * *' # 每天凌晨 2 点定时触发 | ||
|
||
jobs: | ||
# 定义第一个Job,编译和测试 | ||
build-test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: ['1.19', '1.20'] # 测试不同的Go版本兼容性 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run unit tests | ||
run: go test ./... -v | ||
|
||
- name: Lint code | ||
run: | | ||
go vet ./... # 静态代码分析 | ||
golangci-lint run # 使用第三方 lint 工具检查 | ||
- name: Check formatting | ||
run: go fmt ./... | ||
|
||
# 定义第二个 Job,测试代码覆盖率 | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
needs: build-test | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run coverage tests | ||
run: | | ||
go test ./... -coverprofile=coverage.out | ||
go tool cover -func=coverage.out | ||
- name: Upload coverage report | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: coverage-report | ||
path: coverage.out | ||
|
||
# 定义第三个 Job,进行安全扫描 | ||
security-scan: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Security check | ||
run: gosec ./... # 使用 gosec 工具进行安全扫描 |