Skip to content

Commit

Permalink
ci: 1
Browse files Browse the repository at this point in the history
  • Loading branch information
light-speak committed Oct 30, 2024
1 parent d17ef19 commit affcf59
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 56 deletions.
48 changes: 41 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,63 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true

- name: Install dependencies
run: go mod download

- name: Run Tests
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
run: |
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: success()
with:
file: ./coverage.txt
flags: unittests
fail_ci_if_error: false

lint:
if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m
skip-cache: true

security:
if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
steps:
- uses: actions/checkout@v3

- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
if: github.event.pull_request.head.repo.full_name == github.repository
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Run CodeQL Analysis
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

sonarcloud:
Expand All @@ -66,6 +91,15 @@ jobs:
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Run Tests for SonarCloud
run: |
go test -coverprofile=coverage.out -json > test-report.json ./...
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
logs
.VSCodeCounter/**
.DS_Store
.idea
.idea
coverage.txt
coverage.out
test-report.json
63 changes: 15 additions & 48 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,31 @@
# 基本运行配置
run:
timeout: 5m
go: '1.23'
modules-download-mode: readonly
allow-parallel-runners: true
deadline: 5m
tests: false
skip-dirs:
- vendor
- third_party
- internal
- go/pkg/mod
- usr/local/go/src
- opt/hostedtoolcache/go

# 输出格式配置
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
sort-results: true

# 启用的 linters
linters:
disable-all: true
enable:
# 错误检查
- errcheck # 检查错误处理
- gosec # 安全性检查
- govet # Go 原生静态分析

# 代码质量
- gosimple # 代码简化建议
- staticcheck # 静态分析
- unused # 未使用的代码
- ineffassign # 无效赋值

# 代码风格
- gofmt # 格式化检查
- goimports # import 格式化
- misspell # 拼写检查
- revive # 代码风格检查
- gofmt
- govet
- errcheck
- staticcheck
- gosimple
- ineffassign
- unused
disable:
- typecheck

# linter 具体设置
linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/light-speak/lighthouse
govet:
check-shadowing: false
enable-all: false
Expand All @@ -62,24 +42,11 @@ linters-settings:

# 问题处理规则
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0

# 排除规则
exclude-rules:
# 测试文件规则
- path: _test\.go
linters:
- errcheck
- revive

# Go 1.23 特定问题
- text: "cannot range over"
linters: [typecheck]
- text: "cannot infer"
linters: [typecheck]
- text: "undefined"
linters: [typecheck]
- text: "missing return"
linters: [typecheck]
- gosec

max-issues-per-linter: 0
max-same-issues: 0
12 changes: 12 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sonar.projectKey=your-project-key
sonar.organization=your-organization

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out
sonar.go.tests.reportPaths=test-report.json

sonar.sourceEncoding=UTF-8

0 comments on commit affcf59

Please sign in to comment.