8000 Annotations fail for mono-repo if not using 'args: --path-prefix=' (but this makes CI very slow) · Issue #1228 · golangci/golangci-lint-action · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Annotations fail for mono-repo if not using 'args: --path-prefix=' (but this makes CI very slow) #1228

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

Closed
3 tasks done
HaraldNordgren opened this issue May 4, 2025 · 5 comments
Labels
question Further information is requested

Comments

@HaraldNordgren
Copy link
Contributor
HaraldNordgren commented May 4, 2025

Welcome

  • Yes, I understand that the GitHub action repository is not the repository of golangci-lint itself.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

Description of the problem

I'm setting up golangci-lint GH action and it works almost. I follow the "Go Workspace Example" from https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#how-to-use (but for me each lint job runs as as step in my regular build job, I have 50+ services/jobs already, so it seemed easiest to do it that way.)

By running my job with debug logging turned on I see that file is dropped:

2025-05-04T13:19:13.0562816Z ::group::run golangci-lint
2025-05-04T13:19:13.0562996Z ##[group]run golangci-lint
2025-05-04T13:19:13.0569558Z Running [/home/runner/golangci-lint-2.0.2-linux-amd64/golangci-lint config path] in [/home/runner/work/hive/hive/hava-pkg] ...
2025-05-04T13:19:13.1467153Z Running [/home/runner/golangci-lint-2.0.2-linux-amd64/golangci-lint config verify] in [/home/runner/work/hive/hive/hava-pkg] ...
2025-05-04T13:19:13.4391753Z Running [/home/runner/golangci-lint-2.0.2-linux-amd64/golangci-lint run --path-prefix=hava-pkg] in [/home/runner/work/hive/hive/hava-pkg] ...
2025-05-04T13:20:44.2554131Z ##[debug]Dropping file value '/home/runner/work/hive/hive/hava-pkg/hava-pkg/docker_helpers/directus.go'. Path does not exist
2025-05-04T13:20:44.2563028Z ##[error]hava-pkg/hava-pkg/docker_helpers/directus.go:86:21: response body must be closed (bodyclose)
2025-05-04T13:20:44.2572240Z 		_, err := http.Get(directusUrl + "/server/health")
2025-05-04T13:20:44.2572883Z 		                  ^
2025-05-04T13:20:44.2573228Z 1 issues:
2025-05-04T13:20:44.2573536Z * bodyclose: 1
2025-05-04T13:20:44.2573758Z 
2025-05-04T13:20:44.2586460Z ##[error]issues found

Notice that the path has a weird structure, it contains the working directory twice: /home/runner/work/hive/hive/hava-pkg/hava-pkg/docker_helpers/directus.go. Here 'hive' is my repo and 'hava-pkg' my working directory.

Issues are successfully reported as issues on the jobs themselves itself, see image below:

Image

But annotations fail to be shown in the "Files changed" tab on the pull request, see image below, where no annotation shows up:

Image

Root cause could be that the working-directory though path-prefix (https://github.com/golangci/golangci-lint-action/blob/main/src/run.ts#L127) gets added twice to the path that attempts to be sent to GitHub annotations and it rejects it.

One (bad) workaround is to run my job step like this:

      - name: Run golangci-lint
        if: always()
        uses: golangci/golangci-lint-action@v7
        with:
          working-directory: ${{ matrix.service }}
          args: --path-prefix= #Adding this to make the annotations work
          version: v2.0

However, this has balloons the time by 10x, presumably each CI job runs the linting for all the other services as well?

Version of golangci-lint

v2.0.2

Version of the GitHub Action

v7

Workflow file

---
name: build-go

on:
  push:
    paths:
      - 'go.mod'
      - 'cmd/**'
      - 'pkg/**'
      - 'hava-pkg/**'
      - 'services/**'
      - '.github/workflows/go.yaml'

jobs:
  gen_build_list:
    runs-on: ubuntu-latest
    outputs:
      services: ${{ steps.gen_list.outputs.services }}
    steps:
      - name: Check out source code
        uses: actions/checkout@v4
        with:
          fetch-depth: 100

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: 'go.mod'
          check-latest: true

      - run: git fetch origin master

      - id: gen_list
        run: echo "${SERVICES}" # Redacted

  build:
    permissions:
      contents: 'write'
      pull-requests: 'write'
      id-token: 'write'
      checks: 'write'

    needs: gen_build_list
    if: needs.gen_build_list.outputs.services != '[]'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        service: ${{ fromJSON(needs.gen_build_list.outputs.services) }}
    steps:
      - name: Check out source code
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: 'go.mod'
          check-latest: true

      - name: build ${{ matrix.service }}
        env:
          GOPRIVATE: "github.com/dietdoctor/*"
        run: go run ./cmd/hive build ${{ matrix.service }}

      - name: Run golangci-lint
        if: always()
        uses: golangci/golangci-lint-action@v7
        with:
          working-directory: ${{ matrix.service }}
          version: v2.0

Golangci-lint configuration

version: "2"

run:
  timeout: 5m

linters:
  enable:
    - bodyclose
    - goconst
    - makezero
    - rowserrcheck
    - sqlclosecheck
    - testifylint
    - unparam
    - whitespace
  exclusions:
    paths:
      - services/ddapi/pkg/schema
      - services/subscriptions
    rules:
      - path: '(^pkg/|^services/users/)'
        linters:
          - bodyclose
          - goconst
          - makezero
          - rowserrcheck
          - sqlclosecheck
          - testifylint
          - unparam
          - whitespace

Go version

go1.24.2

Code example or link to a public repository

// add your code here
@HaraldNordgren HaraldNordgren changed the title Annotations fail for mono-repo wihout using 'args: --path-prefix=' Annotations fail for mono-repo if not using 'args: --path-prefix=' May 4, 2025
@HaraldNordgren HaraldNordgren changed the title Annotations fail for mono-repo if not using 'args: --path-prefix=' Annotations fail for mono-repo if not using 'args: --path-prefix=' (but this makes CI very slow) May 4, 2025
@ldez ldez added the question Further information is requested label May 4, 2025
@ldez
Copy link
Member
ldez commented May 4, 2025

hello,

I recommend using golangci-lint v2.1 and the cli flag --path-mode=abs.

@ldez ldez closed this as completed May 4, 2025
@HaraldNordgren
Copy link
Contributor Author
HaraldNordgren commented May 4, 2025

@ldez Thanks a lot! 🙌

Should this be the default behavior when running with 'working-directory'?

Or should we add it to the example code for workspaces? Seems like other people would have the same issue.

Either way I can take a stab at it if you agree.

@HaraldNordgren
Copy link
Contributor Author

@ldez I created a PR here if you want to take a look: #1229

@ldez
Copy link
Member
ldez commented May 4, 2025

As a first non-breaking step, I would prefer an update of the documentation.

The update of the action requires more changes than just adding the arg, I would like to handle this part by myself if possible for you. (FYI, I'm already working on that, but you opened a PR before I finished my work)

@HaraldNordgren
Copy link
Contributor Author

Sounds good! Thanks for a great GitHub action by the way! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants
0