Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
name: deploy
name: Lint & Test

on:
push:
branches: [ master ]
pull_request:
branches:
- master
branches: [ master ]

jobs:
build:

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Create cache directories
run: |
mkdir -p ~/.cache/golangci-lint
mkdir -p ~/.cache/go-build

- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Go Lint Cache
uses: actions/cache@v4
with:
path: ~/.cache/golangci-lint/
key: go-lint-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-lint-cache-${{ runner.os }}-

- name: Go Mod Cache
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
key: go-mod-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-mod-cache-${{ runner.os }}-

- name: Debug Cache Path
run: |
ls -la ~/.cache/golangci-lint/ || echo "golangci cache path does not exist"
ls -la ~/.cache/go-build || echo "go-build cache path does not exist"

- name: Check go mod
run: |
go env
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
args: --timeout=10m --verbose
skip-cache: false
env:
GOLANGCI_LINT_CACHE: go-lint-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
53 changes: 53 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "2"
issues:
fix: true
linters:
default: none
enable:
- govet
Comment on lines +6 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

你好,感谢你添加了 golangci-lint 的支持!这是一个很好的改进。
不过,目前只启用了 govet 这一个 linter。为了更好地保证代码质量和发现潜在问题,我建议启用更多有用的 linter。例如:

  • staticcheck: 一个强大的静态分析工具集,可以发现很多细微的 bug。
  • unused: 检查未使用的代码。
  • ineffassign: 检查未使用的变量赋值。
  • errcheck: 检查未处理的 error 返回值。
  • gofumpt: 确保代码格式一致。

启用这些 linter 可以帮助我们更早地发现问题,提升代码的健壮性。

  enable:
    - govet
    - staticcheck
    - unused
    - ineffassign
    - errcheck
    - gofumpt

exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- internal/example
- cmds
- vendor
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
- gofmt
- gofumpt
settings:
gofumpt:
extra-rules: true
goimports:
# A list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: []
local-prefixes:
- github.com/pubgo/opendoc
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: false
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'

exclusions:
paths:
- internal/example
- vendor
- examples$
- proto
1 change: 0 additions & 1 deletion .version

This file was deleted.

1 change: 1 addition & 0 deletions .version/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.2
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ run-example:

goimports:
goimports -w -local github.com/pubgo/opendoc .

refactor:
gofumpt -l -w -extra .

lint:
golangci-lint run --timeout=10m --verbose
Loading