From 21d83e81de011bc8f800a80e614d47427b7d2e9a Mon Sep 17 00:00:00 2001 From: Alexander Menshchikov Date: Wed, 24 Jul 2024 02:36:46 +0300 Subject: [PATCH] github actions --- .github/workflows/actions.yml | 59 +++++++++++++++++++++++++++++ .golangci.yml | 70 +++++++++++++++++++++++++++++++++++ go.work | 7 ++++ go.work.sum | 4 ++ 4 files changed, 140 insertions(+) create mode 100644 .github/workflows/actions.yml create mode 100644 .golangci.yml create mode 100644 go.work create mode 100644 go.work.sum diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..9869344 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,59 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + pull-requests: read + +env: + GO_VERSION: stable + GOLANGCI_LINT_VERSION: v1.59 + +jobs: + detect-modules: + runs-on: ubuntu-latest + outputs: + modules: ${{ steps.set-modules.outputs.modules }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - id: set-modules + run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT + + golangci: + name: lint + needs: detect-modules + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: golangci-lint ${{ matrix.modules }} + uses: golangci/golangci-lint-action@v6 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + working-directory: ${{ matrix.modules }} + + test: + needs: detect-modules + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Test with the Go CLI + run: go test -race diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..aa687d5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,70 @@ +output: + formats: + - format: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters-settings: + gocognit: + min-complexity: 10 + goconst: + min-len: 2 + min-occurrences: 2 + gosec: + excludes: + # _ instead of err checks + - G104 + govet: + enable-all: true + nakedret: + max-func-lines: 10 + nolintlint: + require-specific: true + prealloc: + range-loops: true + revive: + rules: + - name: unexported-return + disabled: true + staticcheck: + # SA5001: Allow to ignore returned error before deferring *.Close() + checks: ["all", "-SA5001"] + +linters: + disable-all: true + enable: + - bodyclose + - copyloopvar + - errcheck + - errorlint + - exportloopref + - gocheckcompilerdirectives + - gocognit + - goconst + - goimports + - gosec + - gosimple + - govet + - ineffassign + - intrange + - makezero + - mnd + - nakedret + - noctx + - nolintlint + - nosprintfhostport + - prealloc + - revive + - staticcheck + - tenv + - testpackage + - typecheck + - unconvert + - unused + - wastedassign + +issues: + exclude-rules: + - path: '(.+)_test\.go' + linters: + - gocognit diff --git a/go.work b/go.work new file mode 100644 index 0000000..74a2b8a --- /dev/null +++ b/go.work @@ -0,0 +1,7 @@ +go 1.20 + +use ( + ./closer + ./ctxkey + ./time +) diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..b839de6 --- /dev/null +++ b/go.work.sum @@ -0,0 +1,4 @@ +github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=