diff --git a/.github/workflows/go-lint-cache.yml b/.github/workflows/go-lint-cache.yml new file mode 100644 index 00000000..780f62d4 --- /dev/null +++ b/.github/workflows/go-lint-cache.yml @@ -0,0 +1,59 @@ +name: Go Lint Cache + +# Action caches written by a pull request run are scoped to that pull request, +# so only runs on the default branch produce caches every pull request can +# restore. Without this workflow each pull request would recompile the whole +# package graph from scratch (~6 minutes for the root module, versus ~40s warm). +# +# This lives apart from go-lint.yml rather than as a conditional job inside it: +# a job skipped by `if` still surfaces as a check on every pull request, and +# GitHub renders its name with the matrix expression unexpanded. + +on: + push: + branches: [main] + paths: + - "**/*.go" + - "**/go.mod" + - "**/go.sum" + - ".golangci.yml" + - ".github/workflows/go-lint-cache.yml" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +env: + GO_VERSION: "1.26" + GOLANGCI_LINT_VERSION: "v2.12.2" + GOPROXY: https://proxy.golang.org,direct + +jobs: + warm-cache: + name: warm lint cache (${{ matrix.module }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + module: [".", "cli", "client"] + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-go@v6 + with: + go-version: ${{ env.GO_VERSION }} + cache-dependency-path: ${{ matrix.module }}/go.sum + + - uses: golangci/golangci-lint-action@v9 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + working-directory: ${{ matrix.module }} + # This workflow exists for its cache side effect only; the backlog of + # existing findings must not turn main red. The run still prints the + # full report, which makes a manual dispatch a useful backlog view. + args: --issues-exit-code=0 diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml new file mode 100644 index 00000000..68ae1527 --- /dev/null +++ b/.github/workflows/go-lint.yml @@ -0,0 +1,53 @@ +name: Go Lint + +# The repository carries a large backlog of pre-existing golangci-lint findings, +# so pull requests are only judged on the code they introduce (`only-new-issues`). +# That filter needs a pull request diff, which is why this workflow has no other +# trigger; the companion go-lint-cache.yml keeps the caches this job restores +# from warm on main. + +on: + pull_request: + paths: + - "**/*.go" + - "**/go.mod" + - "**/go.sum" + - ".golangci.yml" + - ".github/workflows/go-lint.yml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +env: + GO_VERSION: "1.26" + GOLANGCI_LINT_VERSION: "v2.12.2" + GOPROXY: https://proxy.golang.org,direct + +jobs: + golangci: + name: golangci-lint (${{ matrix.module }}) + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + module: [".", "cli", "client"] + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v6 + with: + go-version: ${{ env.GO_VERSION }} + cache-dependency-path: ${{ matrix.module }}/go.sum + + - uses: golangci/golangci-lint-action@v9 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + working-directory: ${{ matrix.module }} + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml index cf49aee7..63b35f01 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,13 +1,13 @@ -version: 2 -linters-settings: - lll: - line-length: 120 - tab-width: 4 +version: "2" linters: enable: - lll # 控制行宽 - govet - revive + settings: + lll: + line-length: 120 + tab-width: 4 formatters: enable: - gofmt