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

github action log output doesn't print the affected file name & line #119

Closed
dprotaso opened this issue Oct 19, 2020 · 41 comments · Fixed by golangci/golangci-lint#4685
Closed

Comments

@dprotaso
Copy link

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

@boring-cyborg
Copy link

boring-cyborg bot commented Oct 19, 2020

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

@dprotaso dprotaso changed the title github action log output doesn't print the file name github action log output doesn't print the affected file name & line Oct 19, 2020
@sayboras
Copy link
Member

sayboras commented Oct 24, 2020

The above run seems not available now. I have created one dummy run to check here. The output is as per expectation.

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

Underlying golangci-lint-action is using github annotations for more user friendly, so where the error is shown (e.g. Files Changes, etc) is up to github annotation, but not golangci-lint. Related to #5.

I am closing this issue. Feel free to re-open if there is anything else that I could have missed.

@dprotaso
Copy link
Author

dprotaso commented Oct 27, 2020

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

@sayboras sayboras transferred this issue from golangci/golangci-lint Oct 27, 2020
@sayboras
Copy link
Member

@dprotaso Thanks for your clarification. As golangci-lint is showing file name + line number, I transfered this issue to golangci-lint-action repo.

$ golangci-lint run ./...        
pkg/golinters/unparam.go:7: File is not `gofmt`-ed with `-s` (gofmt)

pkg/golinters/unparam.go:14: File is not `goimports`-ed with -local github.com/golangci/golangci-lint (goimports)

@sayboras sayboras reopened this Oct 27, 2020
@sayboras sayboras added bug Something isn't working good first issue Good for newcomers hacktoberfest Label for hacktoberfest hacktoberfest-accepted hacktoberfest PR help wanted Extra attention is needed labels Oct 27, 2020
@ernado
Copy link
Member

ernado commented Nov 2, 2020

Can somebody confirm that it is on our side and it is technically possible to adjust the way how github annotations are represented in logs?

AFAIK annotation format already contains file name + line number, but github is not showing this info in logs for some reason.

I've tried to investigate this problem, but I can't find complete documentation for github annotations and how to manipulate them, so I'll be grateful for any help.

@takehito
Copy link

takehito commented Dec 3, 2020

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

@ernado
Copy link
Member

ernado commented Dec 3, 2020

Great, so fix should be trivial?

Upd: oh, seems like we can only fix that via duplicating link to file

@takehito
Copy link

takehito commented Dec 3, 2020

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

@ss89
Copy link

ss89 commented Feb 7, 2021

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.

@r10r
Copy link

r10r commented Feb 15, 2021

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

@aimichal
Copy link

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 👍

@pkuca
Copy link

pkuca commented Feb 24, 2021

I changed the printer for github to do a format similar to eslint compact.

$ golangci-lint run --out-format=github-actions ./...
::error file=sample.go,line=12,col=10::Error return value of `retError` is not checked (errcheck) ([	retError()])
::error file=sample.go,line=13,col=11::Error return value of `retError2` is not checked (errcheck) ([	retError2()])
::error file=sample.go,line=16,col=9::Error return value of `h.Write` is not checked (errcheck) ([	h.Write([]byte(data))])

$ golangci-lint run --out-format=github-actions ./...
sample.go: line 12, col 10, error - Error return value of `retError` is not checked (errcheck)
sample.go: line 13, col 11, error - Error return value of `retError2` is not checked (errcheck)
sample.go: line 16, col 9, error - Error return value of `h.Write` is not checked (errcheck)

Now, once I can test that the output format will work in general instead of just on the sample.go file, we can use a problem matcher file that's almost the same as the example here? https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md#single-line-matchers

@slonopotamus
Copy link

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.

@hellt
Copy link

hellt commented Mar 19, 2021

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

@thebeline
Copy link
Contributor

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

There are a few things to unpack here: The action specifically states that it is designed to be run in a push or pull request context. Running in other contexts, where "there are no files to browse" is not an officially supported use-case as it stands (however, this check is not performed, so you can use this action effectively anywhere).

That being said: While not "officially" supported (in-fact, the code attempts to prevent it, but seems to be bugged at the moment), I believe you can get the results you are looking for by setting args: --out-format=tab, which will result in output such as below:

  utils/ui_utils.go:137:19                                     gomnd       mnd: Magic number: 20, in <argument> detected
  utils/ui_utils.go:147                                        lll         line is 124 characters
  utils/ui_utils.go:149                                        lll         line is 106 characters
  utils/ui_utils.go:152                                        lll         line is 106 characters

If you still want the annotation feature on push and pull request contexts, you would need a .yml configured to trigger on push/pull and one triggered for for any other workflows (with the output set to tab).

@slonopotamus

This comment was marked as off-topic.

@thebeline

This comment was marked as off-topic.

oleg-jukovec added a commit to tarantool/go-tarantool that referenced this issue Dec 27, 2022
After the patch golangci-lint prints a file and a line number [1].

1. golangci/golangci-lint-action#119

Closes #231
oleg-jukovec added a commit to tarantool/go-tarantool that referenced this issue Dec 27, 2022
After the patch golangci-lint prints a file and a line number [1].

1. golangci/golangci-lint-action#119

Closes #231
oleg-jukovec added a commit to tarantool/go-tarantool that referenced this issue Dec 27, 2022
The patch adds a second golangci-lint run that prints errors in
human-readable format [1].

1. golangci/golangci-lint-action#119

Closes #231
oleg-jukovec added a commit to tarantool/go-tarantool that referenced this issue Dec 28, 2022
The patch adds a second golangci-lint run that prints errors in
human-readable format [1].

1. golangci/golangci-lint-action#119

Closes #231
0-haha pushed a commit to 0-haha/gnet that referenced this issue Jan 25, 2023
@ldez ldez removed help wanted Extra attention is needed hacktoberfest Label for hacktoberfest hacktoberfest-accepted hacktoberfest PR labels Jun 12, 2023
@ldez
Copy link
Member

ldez commented Jun 12, 2023

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

@ldez ldez added area: output and removed good first issue Good for newcomers bug Something isn't working labels Jun 19, 2023
@sparr

This comment was marked as off-topic.

@schmidtw

This comment was marked as outdated.

tasn pushed a commit to standard-webhooks/standard-webhooks that referenced this issue Sep 27, 2023
This PR solves few issues:
- uses newer version of the actions
- triggers on changes on the ci file
- add better args for the linting : golangci/golangci-lint-action#119 (comment)
- runs golang tests
@ldez ldez mentioned this issue Feb 16, 2024
3 tasks
@ldez
Copy link
Member

ldez commented May 1, 2024

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

golangci/golangci-lint#4685

@ldez
Copy link
Member

ldez commented May 4, 2024

I added a new option annotations, which may be useful to some of you.

I added this option for several reasons:

  • The number of annotations is limited.
  • Some people don't want to use annotations and just want the classic colored-line-number format.

If you set annotations to false, the output format(s) will follow the golangci-lint configuration file (or CLI flags from args) and use the same default as golangci-lint (i.e. colored-line-number).

https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#annotations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment