Skip to content

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

Closed
@HaraldNordgren

Description

@HaraldNordgren

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions