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

Gomod pipe should include config env so it works with Go Workspaces and Go.mod replace directives #3426

Closed
3 tasks done
bithavoc opened this issue Oct 1, 2022 · 2 comments · Fixed by #3434
Closed
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@bithavoc
Copy link

bithavoc commented Oct 1, 2022

What happened?

goreleaser recommends using goreleaser build instead of go build to keep a single source of truth which is useful in development environments.

When working with a Go Workspace go.work, goreleaser build needs to be combined with env GOWORK=off but is not included when doing go list -m, see below.

We have a goreleaser config with the following content:

builds:
  -
    main: ./cmd/station-agent
    binary: station-agent
    env:
      - GOWORK=off
    goos:
      - linux
    goarch:
      - amd64
      - arm
      - arm64
    flags:
      - -mod=vendor
      - -tags="linux" # sqlite3 requirement https://github.com/mattn/go-sqlite3#linux
      - -v

In the step/pipe loading go mod information, goreleaser build tries to run go list -m but it fails with the following error:

failed to get module path: exit status 1: go: open /tmp/sdk-go/go.mod: no such file or directory

That's because there are some replace directives in my go.mod file.

This is not a problem outside goreleaser if we set the env variable GOWORK=off as in GOWORK=off go list -m -mod=vendor.

I already include - GOWORK=off as part of my env but internal/pipe/gomod/gomod.go is not using to call go list -m.

How can we reproduce this?

  1. Create a project with a go module
  2. Use a replace directive in go.mod
  3. use go workspaces (go.work)
  4. Run goreleaser build

goreleaser version

goreleaser version dev
goos: linux
goarch: amd64
module version: v1.11.4, checksum: h1:bmXfkrBa6xv3WzzZM7U0QCOmpFAanIm+91tFB4DYUnI=

https://goreleaser.com

GoReleaser Check

  • goreleaser check shows no errors

Search

  • I did search for other open and closed issues before opening this.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

I can send a PR to make sure we execute the external command with ctx.Config.Env

@bithavoc bithavoc added bug Something isn't working triage Issue pending triage by one of the maintainers labels Oct 1, 2022
@caarlos0 caarlos0 added enhancement New feature or request and removed bug Something isn't working triage Issue pending triage by one of the maintainers labels Oct 4, 2022
@caarlos0
Copy link
Member

caarlos0 commented Oct 4, 2022

so, there is a gomod.env options you can set, but seems like its not being used... will fix that, and this is indeed a bug

@caarlos0 caarlos0 added bug Something isn't working and removed enhancement New feature or request labels Oct 4, 2022
caarlos0 added a commit that referenced this issue Oct 4, 2022
Fixes  #3426

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants