action-golangci-lint
action-golangci-lint copied to clipboard
Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler
Hi, I'm trying to use the linter with one of my private github go projects.
on: [pull_request]
jobs:
golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Configure git for private modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://MY_USER:${TOKEN}@github.com".insteadOf "https://github.com"
- name: vendor
run: go mod vendor
env:
GOPRIVATE: github.com/MYORG/*
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v1
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.golangci.yml -v"
My .golangci.yml file:
run:
modules-download-mode: vendor
This project uses Go Modules, and references a private repo in Github
the golangci-lint step fails with this error:
level=warning msg="Failed to discover go env: failed to run 'go env': exit status 2"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (imports|name|types_sizes|compiled_files|exports_file|files|deps) took 5.496611ms"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"```
Can you try reviewdog/[email protected]
? It could be regression by #17.
cc/ @shogo82148
I also released v1.1.5
which uses the latest golangci version ( v1.22
). It can also fix the problem, but i'm not sure.
Problem reproducible upstream w/ golangci-lint docker image: https://github.com/golangci/golangci-lint/issues/897
I'm having the same issue in the Action as well as locally w/ the same upstream docker image:
Ran with the step as follows:
- name: Run golangci-lint with reviewdog
uses: docker://reviewdog/action-golangci-lint:v1.1
with:
# GITHUB_TOKEN.
github_token: ${{ secrets.GITHUB_TOKEN }}
golangci_lint_flags: -v --build-tags=integration
Same error given the suggested docker run
invocation from golangci-lint
readme:
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.22-alpine golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (compiled_files|deps|files|imports|exports_file|name|types_sizes) took 671.7705ms"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 8 samples, avg is 68.7MB, max is 68.7MB"
level=info msg="Execution took 681.0258ms"
@ClaudiaJ
Can you try reviewdog/[email protected]?
https://github.com/reviewdog/action-golangci-lint/issues/21#issuecomment-570783269
Tested v1.1.2 just now, unfortunately the same error:
Run docker://reviewdog/action-golangci-lint:v1.1.2
with:
github_token: ***
golangci_lint_flags: -v --build-tags=integration
/usr/bin/docker run --name reviewdogactiongolangcilintv112_12e461 --label 671ee6 --workdir /github/workspace --rm -e INPUT_GITHUB_TOKEN -e INPUT_GOLANGCI_LINT_FLAGS -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/smoke-stack/smoke-stack":"/github/workspace" reviewdog/action-golangci-lint:v1.1.2
level=info msg="[config_reader] Config search paths: [./ /github/workspace /github /]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|imports|name|exports_file|files) took 658.016349ms"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 8 samples, avg is 68.4MB, max is 68.4MB"
level=info msg="Execution took 670.83099ms"
2020/01/07 14:35:10 [golangci-lint] reported: https://github.com/Mattel/smoke-stack/runs/377591212
Hmm, it's interesting if v1.1.2 doesn't work.
Just to confirm, does golangci-lint
itself work with your repository?
It does work outside of Docker, e.g. from host's PATH;
version v1.22.2 built from cb2f8ba on 2019-12-30T19:26:28Z
.
The docker container for golangci-lint:v1.22-alpine
does not work with the same error as noted above.
Do you use go mod vendor
or have private repo dependencies?
I do not use go mod vendor
, but I do recently as of this PR have private repo dependencies.
Let me try adding this step before golangci-lint
:
- name: Configure git for private modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://username:${TOKEN}@github.com".insteadOf "https://github.com"
and get back to you if that works, one moment please
Nope, that didn't work. Let me try removing that dependency then and see if that's the cause, or add a step to go mod download
before-hand 🤔
It seems golangci-lint doesn't use latest go/packages. https://github.com/golangci/golangci-lint/blob/d3e36a97cdc1c68566b0a274df367a44cd766cfb/go.mod#L55
So it doesn't include this commit to improve the error message.... https://github.com/golang/tools/commit/622ba90fc810a8f6a75d7631e0198f4a968987fa
I can now confirm that dumping my dependency on private repo does result in the golangci-lint
docker image working.
Adding go mod download
before the step did not seem to work around this.
go mod download
Probably because downloaded pkgs are not mounted (and i'm not sure how to do that).
Removing --global
from git config may work?
git config
in actions w/o --global
fails:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Not sure what that would buy me either if the downloaded packages aren't being mounted anyway? I'm figuring either I'd need access to pull private modules from within the container, or I'd need the private modules available to the container so that it wouldn't need to pull them.
I can confirm if we could mount the host's modules into the Action's container, this should work.
To test, I've downloaded modules for my project at the host, then tested the same Docker invocation that we found to fail upstream, mounting ${GOPATH}/pkg/mod
into the container, and passing --modules-download-mode=readonly
go mod download
docker run --rm \
-v ${GOPATH}/pkg/mod:/go/pkg/mod \
-v $(pwd):/app \
-w /app \
golangci/golangci-lint:v1.22.2-alpine \
golangci-lint run -v --modules-download-mode=readonly
Reading GH Action's documentation to see if we can mount a volume now.
I can also reproduce this and do not have any private Go modules imported.
Having the same issue
Maybe it's because they use actions/setup-go
in same job.
I think "golangci-lint image" and "reviewdog image" based on it expect "GOROOT" to be ~"/go"~ "/usr/local/go".
But, using actions/setup-go
will implicitly replace "GOROOT" with every step in the same job.
(and docker run with "-e GOROOT" options)
Please check the log of "Actions" that is folded.
I think it will be solved by dividing job
or override it with env
.
https://github.com/actions/setup-go/blob/9fbc767707c286e568c92927bbf57d76b73e0892/lib/installer.js#L122 https://github.com/actions/toolkit/tree/master/packages/core#exporting-variables
Got same error without any private deps.
I got this issue by running this on a private repo. I fixed it by making the repo open source. 🧀
I have the same issue. I found the workaround to remove this error:
level=warning msg="Failed to discover go env: failed to run 'go env': exit status 2"
.
I set the GOROOT variables only for golangci job (thanks @yokogawa-k)
- name: Lint
uses: reviewdog/[email protected]
env:
GOROOT: "/go"
with:
golangci_lint_flags: "--disable-all -E errcheck"
github_token: ${{ secrets.github_token }}
But I still have this issue:
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
Any workaround ?
@smutel
My previous GOROOT configuration was wrong, and I misunderstood it as GOPATH. I'm sorry.
However, it is still a problem to replace GOROOT, so could you try to change GOROOT to /usr/local/go
(not /go
)?
https://github.com/reviewdog/action-golangci-lint/pull/46 should fix this issue. Can anyone try the new version?