golangci-lint-action: github action log output doesn't print the affected file name & line

Please include the following information:

Version of golangci-lint
      - id: golangci_configuration
        uses: andstor/file-existence-action@v1
        with:
          files: .golangci.yaml
      - name: Go Lint
        if: steps.golangci_configuration.outputs.files_exists == 'true'
        uses: golangci/golangci-lint-action@v2
        with:
          version: v1.30
Config file
run:
  timeout: 5m

  build-tags:
    - e2e

  skip-dirs:
    - pkg/client

linters:
  enable:
    - asciicheck
    - golint
    - gosec
    - prealloc
    - stylecheck
    - unconvert
    - unparam
  disable:
    - errcheck

issues:
  exclude-rules:
    - path: test # Excludes /test, *_test.go etc.
      linters:
        - gosec
        - unparam
Go environment
$ go version && go env
1.15
Verbose output of running

https://github.com/knative/networking/pull/233/checks?check_run_id=1275974348

I had to view the ‘files changed’ page to see the lints

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 51
  • Comments: 40 (10 by maintainers)

Commits related to this issue

Most upvoted comments

so where the error is shown (e.g. Files Changes, etc) is up to github annotation, but not golangci-lint.

I guess to clarify I was just hoping the file names would be displayed inline with the run golangci-lint steps logs in addition to the github annotations

ie. I marked the location in the logs with /// - when I run the action locally I see them appear

run golangci-lint
  Running [/home/runner/golangci-lint-1.31.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...  
  /// output file name and line
  Error: File is not `gofmt`-ed with `-s` (gofmt)
  /// output file name and line
  Error: File is not `goimports`-ed with -local github.com/golangci/golangci-lint (goimports)
  
  Error: issues found
  Ran golangci-lint in 58975ms

Workaround

    - uses: golangci/golangci-lint-action@v2
      with:
        args: "--out-${NO_FUTURE}format colored-line-number"

Explainer

I tried to override output format with

    - uses: golangci/golangci-lint-action@v2
      with:
        args: --out-format colored-line-number

Spplying multiple --out-format arguments to the linter works locally, unfortunately the github action has future proofing protection in place that says

Failed to run: Error: please, don't change out-format for golangci-lint: it can be broken in a future, Error: please, don't change out-format for golangci-lint: it can be broken in a future
    at /home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:6831:19
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:6713:71
    at new Promise (<anonymous>)
    at module.exports.__awaiter (/home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:6709:12)
    at runLint (/home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:6816:12)
    at /home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:6885:57
    at Object.<anonymous> (/home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:42546:28)
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/golangci/golangci-lint-action/v2/dist/run/index.js:42349:71

So in order to make the output useful in present you have to fool the future-proof protection like:

    - uses: golangci/golangci-lint-action@v2
      with:
        args: "--out-${NO_FUTURE}format colored-line-number"

Friendly bump

With the new version of the action (v3.6.0) you can now provide extra args to add extra output format.

Example:

    - name: Golangci Lint
      uses: golangci/golangci-lint-action@v3
      with:
        version: v1.53.2
        args: --out-format=colored-line-number

https://golangci-lint.run/usage/configuration/#output-configuration

Related to #769

Friendly bump.

I believe that showing file/line info in build log is absolutely a must. In cases when already existing project adds golangci-lint-action (microsoft/hcsshim#975 as an example), none of reported errors are in diff. Instead, they are in files that already exist. The same will happen for repos that update to a newer version of golangci-lint.

the action creates the comments, open the pull request changes page and you will see all issues. also the action does not allow overriding the format. If you want to see the list of issues in the jobs log, I would recommend you to add one more step:

    - name: errors
        run: golangci-lint run
        if: ${{ failure() }}

don’t worry about the running time, the second run will reuse the cache. In my case the action takes around 10 minutes, but the additional step takes 10 seconds

Friendly bump…

Is there any news about this? i am currently trying to implement this in a github repo and not seeing which file and line an error belongs to in a direct way (having to check the full text based logs) is pretty annoying.

The action specifically states that it is designed to be run in a push or pull request context.

This doesn’t guarantee that files with violations were changed by that push or pull request. Trivial counter-example: initial pull request that adds golangci-lint-action to the repo.

As well as if one to run the linter as a workflow_dispatch against a certain branch (not as a pull request run), then annotations are useless, as there are no files to browse to check them.

So having line numbers in the action run log is very much awaited

Kindly ping. I have this issue too - annotation links are not working.

The problem will be fixed with golangci-lint v1.58: the file information (path, position) will be displayed.

https://github.com/golangci/golangci-lint/pull/4685

I just saw this again using 3.7.0 of the action in a private repo.

image

Should have included:

golangci-lint run
ctrlr/openstack/auth_test.go:87:40: G601: Implicit memory aliasing in for loop. (gosec)
                                marshaledAuth, err := json.Marshal(&tc.returnPayload)
                                                                   ^

@stevenh glad you found a workaround!

Please note however that GitHub announced a while ago that the default shell was going to become PowerShell (shell: pwsh) on Windows runners. Apparently yours is still using shell: cmd, that’s why my suggested workaround didn’t work for you. cmd and pwsh have totally different syntaxes and behaviours regarding variables.

Still, I would advise paying attention to deprecation notices and switch to shell: pwsh ASAP to avoid surprises in the future.

Splitting per OS with the following fixed the unknown flag failure on windows.

It doesn’t follow the same pattern as Linux etc as blank variables on Windows doesn’t expand.

      - name: Go Lint Standard
        if: runner.os != 'Windows'
        uses: golangci/golangci-lint-action@v3
        with:
          version: ${{ matrix.golangci }}
          args: "--out-${NO_FUTURE}format colored-line-number"

      - name: Go Lint Windows
        if: runner.os == 'Windows'
        uses: golangci/golangci-lint-action@v3
        env:
          nofuture: out-format
        with:
          version: ${{ matrix.golangci }}
          args: "--%nofuture% colored-line-number"

If the solution is simply to pass the --out-format twice (which is technically what happens when the workaround described in https://github.com/golangci/golangci-lint-action/issues/119#issuecomment-981090648 is implemented), what prevents this format from becoming the default? Everybody gets the best of both worlds, right?

image

image

@isimluk Thank you for the fix, using

    - uses: golangci/golangci-lint-action@v2
      with:
        args: "--out-${NO_FUTURE}format colored-line-number"

I can now see the line and file names 👍🏻

@thebeline @SVilgelm sorry if this is something obvious that I’ve missed but in our case the annotations are actually on the wrong areas … what is the specific technical reason that this action can’t just print the lines to the output? Developers are used to looking at the output of failed actions and they know how to parse the output of golangci-lint. If they don’t want to take the extra click to go look at the GitHub annotations, why should they have to? What is stopping us from both providing the annotations and the simple log output?

The action specifically states that it is designed to be run in a push or pull request context.

This doesn’t guarantee that files with violations were changed by that push or pull request. Trivial counter-example: initial pull request that adds golangci-lint-action to the repo.

I can confirm that in the event of an initial pull request that adds this to the repo, if configured with only-new-issues: true, it will only run on a patch of the modified files in the PR.

All of that being said, you are not wrong, the Action as it is currently implemented can be run in any context, however the output is only tailored for two specific contexts. I am working on a PR to resolve this.

That being said, while my above suggestion of tab would likely resolve your issue in your specific use-case, I apologize for just submitting a PR that fixes the bug that allowed setting out-format.

For what it is worth, I am also going to be submitting a PR that will then address your use-case (as well as some others), so please keep an eye out and support it if it behaves as you desire.

Sure would be nice to see the affected filenames in the output on the GitHub website. It’s not even visible when I click “View raw logs”.

But I can repro the results by running golangci locally:

docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.37.1 golangci-lint run -v

… and see the filenames that way. Not great, but that unblocks me 👍

yes. we can also move file line and col variables out of :: syntax and add probrem matcher file.

https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md

Because file name and line number is written in :: syntax, github is not show this information in github actions logs.

I confirmed that.

on:
  push
jobs:
  test:
    runs-on: ubuntu-20.04
    steps:
      # `golangci-lint --output-format=github-actions` error message line format
      - run: echo '::error file=path/to/source.go,line=367,col=16::error message (lint tool name)'
      # improve format to output line number and file name to github actions log
      - run: echo '::error file=path/to/source.go,line=367,col=16::path/to/source.go:367:16:error message (lint tool name)'

github-actions-annotation

github-actions-log

link