diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml index 3f1fc19..e0c3825 100644 --- a/.github/workflows/cloc.yml +++ b/.github/workflows/cloc.yml @@ -13,11 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: pr - name: Checkout base code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.base.sha }} path: base diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e651212..f435fe8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,15 +19,15 @@ jobs: name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: 1.20.x - - uses: actions/checkout@v2 + go-version: stable + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v3.4.0 + uses: golangci/golangci-lint-action@v8.0.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.51.1 + version: v2.4.0 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml index 41767ba..531f975 100644 --- a/.github/workflows/gorelease.yml +++ b/.github/workflows/gorelease.yml @@ -9,29 +9,19 @@ concurrency: cancel-in-progress: true env: - GO_VERSION: 1.20.x + GO_VERSION: stable jobs: gorelease: runs-on: ubuntu-latest steps: - - name: Install Go stable - if: env.GO_VERSION != 'tip' - uses: actions/setup-go@v4 + - name: Install Go + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - name: Install Go tip - if: env.GO_VERSION == 'tip' - run: | - curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz - ls -lah gotip.tar.gz - mkdir -p ~/sdk/gotip - tar -C ~/sdk/gotip -xzf gotip.tar.gz - ~/sdk/gotip/bin/go version - echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Gorelease cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/go/bin/gorelease diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index 41f10cc..6a3e1b9 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -8,28 +8,18 @@ on: - created env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GO_VERSION: 1.20.x + GO_VERSION: stable jobs: build: name: Upload Release Assets runs-on: ubuntu-latest steps: - - name: Install Go stable - if: env.GO_VERSION != 'tip' - uses: actions/setup-go@v4 + - name: Install Go + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - name: Install Go tip - if: env.GO_VERSION == 'tip' - run: | - curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz - ls -lah gotip.tar.gz - mkdir -p ~/sdk/gotip - tar -C ~/sdk/gotip -xzf gotip.tar.gz - ~/sdk/gotip/bin/go version - echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build artifacts run: | make release-assets @@ -41,6 +31,14 @@ jobs: asset_path: ./linux_amd64.tar.gz asset_name: linux_amd64.tar.gz asset_content_type: application/tar+gzip + - name: Upload linux_amd64_dbg.tar.gz + if: hashFiles('linux_amd64_dbg.tar.gz') != '' + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./linux_amd64_dbg.tar.gz + asset_name: linux_amd64_dbg.tar.gz + asset_content_type: application/tar+gzip - name: Upload linux_arm64.tar.gz if: hashFiles('linux_arm64.tar.gz') != '' uses: actions/upload-release-asset@v1 diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 2817dcc..fddebcc 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -15,36 +15,25 @@ concurrency: env: GO111MODULE: "on" RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing. - COV_GO_VERSION: 1.20.x # Version of Go to collect coverage + COV_GO_VERSION: stable # Version of Go to collect coverage TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents jobs: test: strategy: matrix: - go-version: [ 1.13.x, 1.19.x, 1.20.x ] + go-version: [ 1.13.x, stable, oldstable ] runs-on: ubuntu-latest steps: - - name: Install Go stable - if: matrix.go-version != 'tip' - uses: actions/setup-go@v4 + - name: Install Go + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - - name: Install Go tip - if: matrix.go-version == 'tip' - run: | - curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz - ls -lah gotip.tar.gz - mkdir -p ~/sdk/gotip - tar -C ~/sdk/gotip -xzf gotip.tar.gz - ~/sdk/gotip/bin/go version - echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Go cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: # In order: # * Module download cache @@ -59,7 +48,7 @@ jobs: - name: Restore base test coverage id: base-coverage if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != '' - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | unit-base.txt @@ -88,14 +77,15 @@ jobs: id: annotate if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != '' run: | - curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.6/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz + curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz gocovdiff_hash=$(git hash-object ./gocovdiff) - [ "$gocovdiff_hash" == "8e507e0d671d4d6dfb3612309b72b163492f28eb" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1) - git fetch origin master ${{ github.event.pull_request.base.sha }} - REP=$(./gocovdiff -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV}) + [ "$gocovdiff_hash" == "c37862c73a677e5a9c069470287823ab5bbf0244" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1) + # Fetch PR diff from GitHub API. + curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} > pull_request.diff + REP=$(./gocovdiff -diff pull_request.diff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV}) echo "${REP}" cat gha-unit.txt - DIFF=$(test -e unit-base.txt && ./gocovdiff -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file") + DIFF=$(test -e unit-base.txt && ./gocovdiff -mod github.com/$GITHUB_REPOSITORY -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file") TOTAL=$(cat delta-cov-unit.txt) echo "rep<> $GITHUB_OUTPUT && echo "$REP" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT echo "diff<> $GITHUB_OUTPUT && echo "$DIFF" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT @@ -130,7 +120,7 @@ jobs: - name: Upload code coverage if: matrix.go-version == env.COV_GO_VERSION - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v5 with: - file: ./unit.coverprofile + files: ./unit.coverprofile flags: unittests diff --git a/.golangci.yml b/.golangci.yml index ec8ea23..f13b2c9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,73 +1,85 @@ -# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +# See https://golangci-lint.run/docs/linters/configuration/ +version: "2" run: tests: true - -linters-settings: - errcheck: - check-type-assertions: true - check-blank: true - gocyclo: - min-complexity: 20 - dupl: - threshold: 100 - misspell: - locale: US - unused: - check-exported: false - unparam: - check-exported: true - cyclop: - max-complexity: 15 - linters: - enable-all: true + default: all disable: + - nilnil - tparallel - - goerr113 + - err113 - errorlint - - lll - - maligned - - gochecknoglobals - - gomnd - - wrapcheck - - paralleltest + - noinlineerr + - wsl_v5 + - funcorder + - copyloopvar + - depguard + - dupword + - errname + - exhaustruct - forbidigo - - exhaustivestruct - - interfacer # deprecated - forcetypeassert - - scopelint # deprecated - - ifshort # too many false positives - - golint # deprecated - - varnamelen - - tagliatelle - - errname + - gochecknoglobals + - intrange - ireturn - - exhaustruct + - lll + - mnd - nonamedreturns - - nosnakecase - - structcheck - - varcheck - - deadcode + - paralleltest + - recvcheck + - tagalign + - tagliatelle - testableexamples - - dupword - -issues: - exclude-use-default: false - exclude-rules: - - linters: - - gomnd - - goconst - - goerr113 - - noctx - - funlen - - dupl - - structcheck - - unused - - unparam - - nosnakecase - path: "_test.go" - - linters: - - errcheck # Error checking omitted for brevity. - - gosec - path: "example_" - + - testifylint + - varnamelen + - wrapcheck + settings: + dupl: + threshold: 100 + errcheck: + check-type-assertions: true + check-blank: true + gocyclo: + min-complexity: 20 + cyclop: + max-complexity: 15 + misspell: + locale: US + unparam: + check-exported: true + exclusions: + generated: lax + rules: + - linters: + - gosec + - dupl + - funlen + - goconst + - mnd + - noctx + - unparam + - unused + path: _test.go + - linters: + - errcheck + - gosec + path: example_ + - linters: + - revive + text: 'unused-parameter: parameter' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 74dcb74..be4cf55 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v1.51.1" # Optional configuration to pinpoint golangci-lint version. +#GOLANGCI_LINT_VERSION := "v2.5.0" # Optional configuration to pinpoint golangci-lint version. # The head of Makefile determines location of dev-go to include standard targets. GO ?= go diff --git a/cmd/jsoncompact/main.go b/cmd/jsoncompact/main.go index 4253b39..509f099 100644 --- a/cmd/jsoncompact/main.go +++ b/cmd/jsoncompact/main.go @@ -40,7 +40,7 @@ func main() { //nolint input = flag.Arg(0) if input == "" { - _, _ = fmt.Fprintln(flag.CommandLine.Output(), "Missing input path argument, use `-` for stdin.") + _, _ = fmt.Fprintln(flag.CommandLine.Output(), "Missing input path argument, use `-` for stdin.") //nolint flag.Usage() return diff --git a/equal.go b/equal.go index b996c61..a19a768 100644 --- a/equal.go +++ b/equal.go @@ -198,7 +198,7 @@ func (c Comparer) filterExpected(expected []byte) ([]byte, error) { return nil, fmt.Errorf("failed to marshal var %s: %v", k, err) // Not wrapping to support go1.12. } - expected = bytes.Replace(expected, []byte(`"`+k+`"`), j, -1) //nolint:gocritic // To support go1.11. + expected = bytes.Replace(expected, []byte(`"`+k+`"`), j, -1) //nolint:gocritic,staticcheck // To support go1.11. } } diff --git a/go.mod b/go.mod index 813e8d9..56c5685 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/swaggest/assertjson go 1.17 require ( - github.com/bool64/dev v0.2.29 + github.com/bool64/dev v0.2.43 github.com/bool64/shared v0.1.5 github.com/iancoleman/orderedmap v0.3.0 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index 2da14ef..e6f44d8 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/bool64/dev v0.2.17/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= -github.com/bool64/dev v0.2.29 h1:x+syGyh+0eWtOzQ1ItvLzOGIWyNWnyjXpHIcpF2HvL4= -github.com/bool64/dev v0.2.29/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ= +github.com/bool64/dev v0.2.43/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=