Skip to content

Commit

Permalink
添加了go语言工作流
Browse files Browse the repository at this point in the history
  • Loading branch information
Dopoil committed Oct 13, 2024
1 parent e176196 commit af1c060
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions go-ci.yml
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 工具进行安全扫描

0 comments on commit af1c060

Please sign in to comment.