Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with GitHub action: File is not gofmt-ed with -s (gofmt) with version 1.48.0 #3069

Closed
4 tasks done
sebastian-quintero opened this issue Aug 5, 2022 · 4 comments
Closed
4 tasks done
Labels
bug Something isn't working

Comments

@sebastian-quintero
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

This github action is failing saying that File is not gofmt-ed with -s (gofmt). It is failing on three separate files. Running the same version locally reveals that the files are ok. I tried to gofmt the files with -s and -w to no avail. Locally, there are no changes and everything looks ok. This started happening after the update to v1.48.0 on the GitHub action, given that we use the latest.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.48.0 built from 2d8fea8 on 2022-08-04T09:19:19Z
Smart, fast linters runner. Run it in cloud for every GitHub pull request on https://golangci.com

Usage:
  golangci-lint [flags]
  golangci-lint [command]

Available Commands:
  cache       Cache control and information
  completion  Generate the autocompletion script for the specified shell
  config      Config
  help        Help
  linters     List current linters configuration
  run         Run the linters
  version     Version

Flags:
      --color string              Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
  -j, --concurrency int           Concurrency (default NumCPU) (default 10)
      --cpu-profile-path string   Path to CPU profile output file
  -h, --help                      help for golangci-lint
      --mem-profile-path string   Path to memory profile output file
      --trace-path string         Path to trace output file
  -v, --verbose                   verbose output
      --version                   Print version

Use "golangci-lint [command] --help" for more information about a command.

Configuration file

$ cat .golangci.yml
# Options for analysis running. Details: https://golangci-lint.run/usage/configuration/#run-configuration
run:
  timeout: 5m
  go: "1.18"

# Configures linters. Details: https://golangci-lint.run/usage/linters
linters-settings:
  # Pick up duplicate code after severe repetition.
  dupl:
    threshold: 200
  # Only allow certain modules to be imported.
  gomodguard:
    allowed:
      modules:
        -
  # Functions cannot exceed this cyclomatic complexity.
  gocyclo:
    min-complexity: 10
  # Set correct go version.
  gofumpt:
    lang-version: "1.18"
  gosimple:
    go: "1.18"
  staticcheck:
    go: "1.18"
  stylecheck:
    go: "1.18"
  # Check case of struct tags
  tagliatelle:
    case:
      use-field-name: true
      rules:
        json: snake
  # Check line length
  lll:
    line-length: 80

# Specifies which linters are enabled. Full list: https://golangci-lint.run/usage/linters/
linters:
  # Some linters are just too strict.
  disable-all: true
  enable:
    # Checks whether HTTP response body is closed successfully.
    - bodyclose
    # containedctx is a linter that detects struct contained context.Context field.
    - containedctx
    # Check the function whether use a non-inherited context.
    - contextcheck
    # Finds unused code.
    - deadcode
    # check declaration order and count of types, constants, variables and functions.
    - decorder
    # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
    - dogsled
    # Tool for code clone detection
    - dupl
    # Errcheck is a program for checking for unchecked errors in go programs.
    # These unchecked errors can be critical bugs in some cases.
    - errcheck
    # Gci controls golang package import order and makes it always deterministic.
    - gci
    # Finds repeated strings that could be replaced by a constant.
    - goconst
    # Provides diagnostics that check for bugs, performance and style issues.
    # Extensible without recompilation through dynamic rules. Dynamic rules are
    # written declaratively with AST patterns, filters, report message and
    # optional suggestion.
    - gocritic
    # Computes and checks the cyclomatic complexity of functions.
    - gocyclo
    # Check if comments end in a period.
    - godot
    # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s
    # option to check for code simplification.
    - gofmt
    # Gofumpt checks whether code was gofumpt-ed.
    - gofumpt
    # In addition to fixing imports, goimports also formats your code in the
    # same style as gofmt.
    - goimports
    # Allow and block list linter for direct Go module dependencies. This is
    # different from depguard where there are different block types for example
    # version constraints and module recommendations.
    - gomodguard
    # Linter for Go source code that specializes in simplifying a code.
    - gosimple
    # Vet examines Go source code and reports suspicious constructs, such as
    # Printf calls whose arguments do not align with the format string.
    - govet
    # Enforces consistent import aliases.
    - importas
    # Detects when assignments to existing variables are not used.
    - ineffassign
    # Reports long lines.
    - lll
    # Finds commonly misspelled English words in comments.
    - misspell
    # Finds naked returns in functions greater than a specified function length.
    - nakedret
    # Reports deeply nested if statements.
    - nestif
    # Finds the code that returns nil even if it checks that the error is not nil.
    - nilerr
    # noctx finds sending http request without context.Context.
    - noctx
    # Finds slice declarations that could potentially be preallocated.
    - prealloc
    # Find code that shadows one of Go's predeclared identifiers.
    - predeclared
    # Fast, configurable, extensible, flexible, and beautiful linter for Go.
    # Drop-in replacement of golint.
    - revive
    # Staticcheck is a go vet on steroids, applying a ton of static analysis checks.
    - staticcheck
    # Finds unused struct fields.
    - structcheck
    # Stylecheck is a replacement for golint.
    - stylecheck
    # Checks the struct tags.
    - tagliatelle
    # Like the front-end of a Go compiler, parses and type-checks Go code.
    - typecheck
    # Remove unnecessary type conversions.
    - unconvert
    # Reports unused function parameters.
    - unparam
    # Checks Go code for unused constants, variables, functions and types.
    - unused
    # Finds unused global variables and constants.
    - varcheck
    # wastedassign finds wasted assignment statements.
    - wastedassign
    # Tool for detection of leading and trailing whitespace.
    - whitespace

# List of regexps of issue texts to exclude. Details: https://golangci-lint.run/usage/configuration/#issues-configuration
issues:
  # Disable default exclude patterns to surface commonly-ignored linting errors.
  exclude-use-default: false
  exclude-rules:
    # Many individual router tests use the same base and this implies
    # duplication. The code is not abstracted into a single function to keep the
    # testable examples in a nice compact format with all information provided in
    # a single snippet.
    - path: route/example_option_test\.go
      linters:
        - dupl
    - path: route/example_router_test\.go
      linters:
        - dupl

Go environment

$ go version && go env
go version go1.18.5 darwin/arm64
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/sebastian-quintero/Library/Caches/go-build"
GOENV="/Users/sebastian-quintero/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/sebastian-quintero/go/pkg/mod"
GONOPROXY="github.com/nextmv-io/*"
GONOSUMDB="github.com/nextmv-io/*"
GOOS="darwin"
GOPATH="/Users/sebastian-quintero/go"
GOPRIVATE="github.com/nextmv-io/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sebastian-quintero/github/sdk/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_m/5zls419934123jw62wrrv_6h0000gn/T/go-build1568123854=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/sebastian-quintero/github/sdk /Users/sebastian-quintero/github /Users/sebastian-quintero /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 41 linters: [bodyclose containedctx contextcheck deadcode decorder dogsled dupl errcheck gci goconst gocritic gocyclo godot gofmt gofumpt goimports gomodguard gosimple govet importas ineffassign lll misspell nakedret nestif nilerr noctx prealloc predeclared revive staticcheck structcheck stylecheck tagliatelle typecheck unconvert unparam unused varcheck wastedassign whitespace]
INFO [loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|files|imports|exports_file|name) took 87.080583ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 3.571666ms
WARN [linters context] contextcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key.
INFO [linters context/goanalysis] analyzers took 1.511115069s with top 10 stages: buildir: 524.757498ms, buildssa: 71.963165ms, the_only_name: 67.553087ms, gofumpt: 60.326085ms, dupl: 58.8185ms, goimports: 50.800833ms, gocritic: 47.7995ms, gci: 32.130916ms, S1038: 29.116542ms, commentmap: 27.071501ms
WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters context] wastedassign is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
INFO [runner] Issues before processing: 12, after processing: 0
INFO [runner] Processors filtering stat (out/in): cgo: 12/12, skip_dirs: 12/12, identifier_marker: 12/12, path_prettifier: 12/12, autogenerated_exclude: 12/12, filename_unadjuster: 12/12, skip_files: 12/12, exclude: 12/12, exclude-rules: 0/12
INFO [runner] processing took 511.418µs with stages: identifier_marker: 360.292µs, autogenerated_exclude: 92.333µs, skip_dirs: 19.083µs, path_prettifier: 16.5µs, exclude-rules: 9.458µs, cgo: 2.958µs, nolint: 2.417µs, filename_unadjuster: 2.166µs, max_same_issues: 1.583µs, severity-rules: 876ns, exclude: 834ns, max_from_linter: 793ns, skip_files: 459ns, uniq_by_line: 458ns, source_code: 291ns, path_shortener: 291ns, diff: 209ns, sort_results: 167ns, path_prefixer: 125ns, max_per_file_from_linter: 125ns
INFO [runner] linters took 1.037388542s with stages: goanalysis_metalinter: 1.03676075s, structcheck: 12.333µs, contextcheck: 8.25µs, wastedassign: 6.25µs
INFO File cache stats: 30 entries of total size 205.9KiB
INFO Memory: 13 samples, avg is 197.0MB, max is 259.3MB
INFO Execution took 1.134769917s

Code example or link to a public repository

/*
Package model provides modeling components, such as domains and ranges.

Create individual integer domains.

    d1 := model.NewDomain() // empty domain
    d2 := model.NewDomain(model.NewRange(1, 10))
    d3 := model.NewDomain(model.NewRange(1, 10), model.MewRange(21, 30))
    d4 := model.Singleton(42)
    d5 := model.Multiple(2, 4, 6, 8)

Create sequences of domains.

    domains1 := model.NewDomains(d1, d2, d3, d4, d5)
    domains2 := model.Repeat(5, d1) // 5 empty domains
*/
package model

The following files have the same error:

@sebastian-quintero sebastian-quintero added the bug Something isn't working label Aug 5, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 5, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@sebastian-quintero
Copy link
Author

Ok so I downloaded go1.19:

$ go install golang.org/dl/go1.19@latest
$ go1.19 download

Then I ran the fmt linter on my project:

$ go1.19 fmt ./...

To my surprise, it did correct all of the issues that the golangci-lint action was complaining (and others, that it was sure to complain about). That fixes it. But the bug for me is still there: using go1.18.5 and golangci-lint v1.48.0 fails in the action but not locally. I assume the action uses go1.19 in the back, but it shouldn't, as I'm specifying go 1.18 in the .yml:

name: go lint
on: [push]
jobs:
  sdk:
    runs-on: ubuntu-latest
    steps:
      - name: set up go
        uses: actions/setup-go@v3
        with:
          go-version: 1.18
        id: go

      - name: git clone
        uses: actions/checkout@v3

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: latest

@dvdscripter
Copy link

dvdscripter commented Aug 5, 2022

Same. I'm using go-version >=1.18 and version latest

@ldez
Copy link
Member

ldez commented Aug 5, 2022

Close in favor of golangci/golangci-lint-action#535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants