Skip to content

Commit

Permalink
ci: add codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Dec 21, 2024
1 parent e01261a commit 8b3b0d9
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 15 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [main]
branches: [ "main" ]
pull_request:
branches: [main]
branches: [ "main" ]

jobs:
test:
Expand All @@ -13,27 +13,23 @@ jobs:
steps:
- uses: actions/checkout@v4

# 设置 Go 环境,使用 go.mod 中定义的版本
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod # 自动读取 go.mod 中的 Go 版本

- name: Install dependencies
go-version-file: 'go.mod'
cache: true

- name: Download dependencies
run: go mod download

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

- name: Run tests
- name: Run Tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt
fail_ci_if_error: false

build:
name: Build
Expand All @@ -44,7 +40,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod # 自动读取 go.mod 中的 Go 版本
go-version-file: 'go.mod'
cache: true

- name: Build
run: go build -v ./...
run: go build -v ./...
40 changes: 40 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '30 1 * * 1' # 每周一凌晨1:30运行

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:go"
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
push:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/*.md'

jobs:
lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.61

0 comments on commit 8b3b0d9

Please sign in to comment.