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

typecheck fails on first CI run #902

Closed
3 tasks done
pgier opened this issue Nov 17, 2023 · 6 comments
Closed
3 tasks done

typecheck fails on first CI run #902

pgier opened this issue Nov 17, 2023 · 6 comments
Labels
question Further information is requested

Comments

@pgier
Copy link

pgier commented Nov 17, 2023

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 seeing seeing typecheck errors always on the first run of my pull request CI. When I manually re-run the failed job, then the lint succeeds.

  Running [/home/runner/golangci-lint-1.55.2-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  Error: "github.com/golang-jwt/jwt/v5" imported as jwt and not used (typecheck)
  Error: tenantPlanRes.ClusterName undefined (type CreateStreamingTenantResponse has no field or method ClusterName) (typecheck)
  Error: tenantPlanRes.AdminURL undefined (type CreateStreamingTenantResponse has no field or method AdminURL) (typecheck)

The problem just started recently (past two weeks) and the problem doesn't seem to happen with 1.54.x.

Version of golangci-lint

1.55.2

Version of the GitHub Action

v3

Workflow file

  golang-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v4
        with:
          go-version: 1.21
      - uses: golangci/golangci-lint-action@v3
        with:
          # Set to 1.54 to avoid typecheck failures on first run
          version: v1.54.2
          # Disable the package cache to avoid log errors
          # see: https://github.com/golangci/golangci-lint-action/issues/135
          skip-pkg-cache: true

Go version

1.21

Code example or link to a public repository

I checked the code related to the reported errors and found that they are not valid. Running golangci-lint locally also works fine.

@bombsimon
Copy link
Member

bombsimon commented Nov 17, 2023

Have you read Why do you have typecheck errors?

typecheck is not a real linter but golangci-lint's way of presenting compilation/module/run errors.

What happens if you try to compile your code before the linting step with go build ./...?

@pgier
Copy link
Author

pgier commented Nov 17, 2023

Yes, I read the notes about typecheck and followed the instructions there but it didn't help.
I think I've narrowed down the issue. I'm seeing the same issue sometimes with v1.54.2, so it doesn't seem to be related to the 1.55 upgrade. However, in all the failures, it looks like the setup-go action is not finding local cache.

Run actions/setup-go@v4
  with:
    go-version: 1.21
    check-latest: false
    token: ***
    cache: true
Setup go version spec 1.21
Found in cache @ /opt/hostedtoolcache/go/1.21.3/x64
Added go to the path
Successfully set up Go version 1.21
/opt/hostedtoolcache/go/1.21.3/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.21.3/x64/bin/go env GOCACHE
/home/runner/go/pkg/mod
/home/runner/.cache/go-build
Cache is not found
go version go1.21.3 linux/amd64

Whereas with the successful runs, setup-go finds the local cache.

/home/runner/.cache/go-build
Received 134217728 of 511766649 (26.2%), 126.9 MBs/sec
Received 335544320 of 511766649 (65.6%), 159.0 MBs/sec
Received 511766649 of 511766649 (100.0%), 164.9 MBs/sec
Cache Size: ~488 MB (511766649 B)
/usr/bin/tar -xf /home/runner/work/_temp/c2939fd8-9587-42a2-81aa-4e1750096bad/cache.tzst -P -C /home/runner/work/bellburnell/bellburnell --use-compress-program unzstd
Cache restored successfully
Cache restored from key: setup-go-Linux-ubuntu22-go-1.21.3-e3e0a5df9b4329f309a1660fef499b27d262892d31bfd97eec3382ce8fa9124b

I didn't think it would be necessary to run a go build before the lint but I can try it.

@bombsimon
Copy link
Member

I didn't think it would be necessary to run a go build before the lint but I can try it.

Sorry, I misread parts of your ticket and didn't realize it worked by just retrying. It's so common with these typecheck issues that I didn't read your ticket properly.

go build is not required, I was mostly curious what output it would give since typecheck isn't always the best way to present these issues.

@ldez ldez added the question Further information is requested label Dec 18, 2023
@ohad83
Copy link

ohad83 commented Dec 19, 2023

I'm having a similar issue.
When running something like this:

jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v4
        with:
          go-version: "1.21"
          cache: false
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.55.2

I get typecheck failures. When I added a go build before the lint, it worked, and now if I use:


jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v4
        with:
          go-version: "1.21"

      - run: go mod download

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.55.2
          skip-pkg-cache: true

It works.

@pgier Did you find a different solution?

SamYuan1990 added a commit to SamYuan1990/tape that referenced this issue Dec 21, 2023
Signed-off-by: Sam Yuan <yy19902439@126.com>
SamYuan1990 added a commit to Hyperledger-TWGC/tape that referenced this issue Dec 21, 2023
* fix lint issue ref golangci/golangci-lint-action#902

Signed-off-by: Sam Yuan <yy19902439@126.com>

* fix up

Signed-off-by: Sam Yuan <yy19902439@126.com>

* fix up

Signed-off-by: Sam Yuan <yy19902439@126.com>

* fix up

Signed-off-by: Sam Yuan <yy19902439@126.com>

---------

Signed-off-by: Sam Yuan <yy19902439@126.com>
@pgier
Copy link
Author

pgier commented Dec 21, 2023

@ohad83 looks like you didn't have to run a full go build just a go mod download is that correct?
I didn't find a different solution, I was trying to avoid a full build every time before linting just to reduce the CI feedback loop. I tried changing various caching options without success. It's a bit hard to test because the issue is intermittent for me.

@pgier
Copy link
Author

pgier commented Dec 21, 2023

Running a go build or just go mod download before linting does appear to fix the issue for me.

@ldez ldez closed this as completed Feb 8, 2024
generalmimon added a commit to kaitai-io/kaitai_struct_go_runtime that referenced this issue Mar 29, 2024
This is recommended by the `golangci-lint` README, see
https://github.com/golangci/golangci-lint-action/blob/e637d2bbe4e0571eb57bfc3615ba14992312228d/README.md#compatibility:

> * `v4.0.0+` requires an explicit setup-go installation step before
>   using this action: `uses: actions/setup-go@v5`. The
>   `skip-go-installation` option has been removed.

`go mod download` is also run before `golangci-lint` just in case
because it fixed some people's problems (see
golangci/golangci-lint-action#902 (comment)).
It is also re-added to the "Test" job, because it turned out that
`actions/setup-go@v5` doesn't download dependencies as I thought it
would.
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

4 participants