diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml new file mode 100644 index 0000000..2c3dbc9 --- /dev/null +++ b/.github/workflows/pull.yml @@ -0,0 +1,42 @@ +name: PR检查 +on: + pull_request_target: + types: [assigned, opened, synchronize, reopened] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: "1.24" + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Tidy Modules + run: go mod tidy + + - name: golangci-lint + uses: golangci/golangci-lint-action@master + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..1724676 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,36 @@ +name: 推送检查 +on: [ push ] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: "1.24" + + - name: Check out code into the Go module directory + uses: actions/checkout@master + + - name: Tidy Modules + run: go mod tidy + + - name: Run Lint + uses: golangci/golangci-lint-action@master + with: + version: latest + + - name: Commit back + if: ${{ !github.head_ref }} + continue-on-error: true + run: | + git config --local user.name 'github-actions[bot]' + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add --all + git commit -m "chore(lint): 改进代码样式" + + - name: Create Pull Request + if: ${{ !github.head_ref }} + continue-on-error: true + uses: peter-evans/create-pull-request@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67149cc..613a4e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: "1.24" - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..81d50a5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,75 @@ +linters-settings: + errcheck: + ignoretests: true + + goimports: + local-prefixes: github.com/fumiama/go-nd-portal + + forbidigo: + # Forbid the following identifiers + forbid: + - ^fmt\.Errorf$ # consider errors.Errorf in github.com/pkg/errors + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + fast: false + enable: + - bodyclose + #- depguard + - dogsled + - errcheck + #- exportloopref + - exhaustive + #- funlen + #- goconst + - gocritic + #- gocyclo + - gofmt + - goimports + - goprintffuncname + #- gosec + - gosimple + - govet + - ineffassign + #- misspell + - nolintlint + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - prealloc + - predeclared + - asciicheck + - revive + - forbidigo + - makezero + +run: + # default concurrency is a available CPU number. + # concurrency: 4 # explicitly omit this value to fully utilize available resources. + deadline: 5m + issues-exit-code: 1 + tests: false + go: '1.24' + +# output configuration options +output: + formats: + - format: "colored-line-number" + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + +issues: + # Fix found issues (if it's supported by the linter) + fix: true + exclude-use-default: false + exclude: + - "Error return value of .((os.)?std(out|err)..*|.*Close|.*Seek|.*Flush|os.Remove(All)?|.*print(f|ln)?|os.(Un)?Setenv). is not check" + - 'identifier ".*" contain non-ASCII character: U\+.*'