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

Add $GOPATH/bin to $PATH #14

Closed
lmittmann opened this issue Aug 16, 2019 · 25 comments
Closed

Add $GOPATH/bin to $PATH #14

lmittmann opened this issue Aug 16, 2019 · 25 comments
Assignees
Labels
enhancement New feature or request

Comments

@lmittmann
Copy link

lmittmann commented Aug 16, 2019

When installing tools via go get (e.g. golint) they can not be ran without adding $GOPATH/bin to $PATH beforehand.

So for using e.g. golint one would need to write a step:

- run: |
    export PATH=$PATH:$(go env GOPATH)/bin
    go get -u golang.org/x/lint/golint
    golint -set_exit_status ./...

It would be cool, if setup-go could already do the export PATH=$PATH:$(go env GOPATH)/bin part, as this is a common need.

@geoah
Copy link

geoah commented Aug 16, 2019

GOBIN would be a better choice I think for this

@lmittmann
Copy link
Author

$GOBIN could be used as well, but it also needs to be added to $PATH. Since go env GOBIN is not set and $GOPATH/bin is the default installation path it's just simpler to add the default path to $PATH.

@damccorm
Copy link
Contributor

I think this should probably be resolved together with #12. Given my most recent comment in that issue, are you ok with closing here and following up there?

@damccorm damccorm self-assigned this Aug 19, 2019
aslakknutsen added a commit to maistra/istio-workspace that referenced this issue Aug 20, 2019
@lmittmann
Copy link
Author

@damccorm Let's track this issue here, as it seems like #12 is quite fuzzy.

@mvdan
Copy link

mvdan commented Sep 3, 2019

I think you're overthinking this. The official Go docker images simply hard-code PATH, as you can see here: https://github.com/docker-library/golang/blob/3a6407a6ff134ef6a0364ac061b0808f990ea14e/1.13-rc/alpine3.10/Dockerfile#L59-L60

Why not do the same? If anyone wants to set up a custom GOPATH or GOBIN, they can set up a custom PATH too. I'd prefer PATH to be simple and predictable.

jakewright added a commit to jakewright/home-automation that referenced this issue Sep 24, 2019
As stated in this issue, you can't run tools installed using go get without first updating $PATH.
actions/setup-go#14

Also add -set_exit_status to make golint return 1 if any issues are found.
https://github.com/golang/lint/blob/master/golint/golint.go#L24
nbari added a commit to immortal/immortal that referenced this issue Oct 20, 2019
@leighmcculloch
Copy link

You can avoid this issue by instead using the actions container param to run all the commands in the official golang Docker image. You can see what that looks like here:
https://github.com/stellar/go-xdr/blob/3aa3546/.github/workflows/build.yml

@mvdan
Copy link

mvdan commented Nov 19, 2019

@leighmcculloch I assume that won't work for testing on mac and windows, though, so fixing this bug is still very useful.

@sanemat
Copy link

sanemat commented Dec 9, 2019

I prefer this solution below. This works on windows, ubuntu, and mac.

    steps:
    - name: setup go
      uses: actions/setup-go@v1
      with:
        go-version: 1.x
    - name: setup env
      run: |
        echo "::set-env name=GOPATH::$(go env GOPATH)"
        echo "::add-path::$(go env GOPATH)/bin"
      shell: bash
    - name: checkout
      uses: actions/checkout@v1
      with:
        fetch-depth: 1
        path: src/github.com/${{ github.repository }}

https://stackoverflow.com/a/59242962/104080

jamezpolley added a commit to openaustralia/yinyo that referenced this issue Dec 18, 2019
Although Github Actions provides a Go action, that action doesn't set up the environment for use with Go.

actions/setup-go#14 suggests that this is broken-as-intended.

The two workarounds suggested there are using the Go container image to run tests; or to explicitly set up the environment like this.
@eduncan911
Copy link

eduncan911 commented Feb 7, 2020

@sanemat that still doesn't look right, as there is a bug in the checkout for that path property/option.

To get it to work, I had to hardcode my path - which is unacceptable to me in a github action as things should be evaluated per ENVs and template vars:

  go-test:
    strategy:
      matrix:
        go-version: [1.7.x, 1.13.x]
        platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:
    - name: setup env
      shell: bash
      run: |
        echo "::set-env name=GOPATH::${{ github.workspace }}/go"
        echo "::add-path::${{ github.workspace }}/go/bin"
    - name: Install Go
      if: success()
      uses: actions/setup-go@v1
      with:
        go-version: ${{ matrix.go-version }}
    - name: checkout
      uses: actions/checkout@v1
      with:
        fetch-depth: 1
        path: podcast/go/src/github.com/${{ github.repository }}
    - name: Run tests
      run: |
        go test -v -covermode=count 

Notice the path: podcast/go/src/github.com/${{ github.repository }}, which is prefixed with podcast because for some reason, $GITHUB_WORKSPACE is actually:

/home/runner/work/podcast/podcast/

Not what the path downloads to, which is:

/home/runner/work/podcast/

To make matters worse, you cannot access this above directory as there is no ENV var that sets it to be consumed. So it has to be hardcoded!

pshem added a commit to magetron/planning-poker-go that referenced this issue Feb 11, 2020
@bryanmacfarlane bryanmacfarlane added the enhancement New feature or request label Feb 11, 2020
@bryanmacfarlane
Copy link
Member

hopefully we can get to this soon as part of v2-beta.

gesellix added a commit to gesellix/couchdb-prometheus-exporter that referenced this issue Feb 12, 2020
gesellix added a commit to gesellix/couchdb-prometheus-exporter that referenced this issue Feb 12, 2020
@eduncan911
Copy link

eduncan911 commented Feb 13, 2020

So, the devs on the checkout action told me there was a newer version @v2 that fixes the WORKSPACE issue.

This worked for all of my other actions, and I can remove the hardcoded podcast prefix I previously had to do in the path attribute above.

  go-test:
    strategy:
      matrix:
        go-version: [1.7.x, 1.13.x]
        platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:
    - name: setup env
      shell: bash
      run: |
        echo "::set-env name=GOPATH::${{ github.workspace }}/go"
        echo "::add-path::${{ github.workspace }}/go/bin"
    - name: Install Go
      if: success()
      uses: actions/setup-go@v1
      with:
        go-version: ${{ matrix.go-version }}
    - name: checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: 1
        path: go/src/github.com/${{ github.repository }}
    - name: Run tests
      shell: bash
      run: |
        cd $GOPATH/src/github.com/${{ github.repository }}
        go test -v -covermode=count 

I'm happy with this for now, as it's now abstracted and I can copy it across all of my repos with no hardcoding of the repo itself.

However, it still seems very verbose: having to set the GOPATH and BIN in other actions, as well as specifying BASH everywhere so I can pickup that GOPATH.

@sefasenturk95
Copy link

I completely agree with @eduncan911, also because of this issue I have to run cd $GOPATH/src/github.com/${{ github.repository }} in every step..

@fsouza fsouza mentioned this issue Mar 2, 2020
scbizu added a commit to ezbuy/redis-orm that referenced this issue Mar 19, 2020
scbizu added a commit to ezbuy/redis-orm that referenced this issue Mar 19, 2020
@peterwillcn
Copy link

- name: Lint
  run: |
    GOBIN=$PWD/bin go install golang.org/x/lint/golint
    ./bin/golint ./...

@bryanmacfarlane
Copy link
Member

I'm working on this today. Sorry for the delay, I've been busy :)

I'm adding it to the v2-beta as v1 is sealed and new features are going into the v2 line.

@bryanmacfarlane
Copy link
Member

bryanmacfarlane commented Mar 26, 2020

I added this feature to the v2-beta. If some folks here can validate, I can take out of beta.

Here's it is being used and as you can see in "path" step, it's being added to the path now: https://github.com/bryanmacfarlane/actions-playground/runs/537349478?check_suite_focus=true

@fsouza
Copy link

fsouza commented Mar 26, 2020

@bryanmacfarlane works on all my repos that were using #41, thanks for implementing this! 🎉

Some examples:

@bryanmacfarlane
Copy link
Member

@fsouza - awesome. Note that you can also use setup-go@v2-beta and I'll make it v2 soon.

@bryanmacfarlane
Copy link
Member

Closing since solution is verified. If anyone has any issues trying it out with @v2-beta let me know and I'll look into it.

@arvenil
Copy link

arvenil commented Apr 22, 2020

@bryanmacfarlane
Hi, I just tried v2 and still having this problem.

Install
0s
##[error]Process completed with exit code 1.
Run go install -v ./...
go install: no install location for directory /home/runner/work/kata/kata/cmd/kata02 outside GOPATH
	For more details see: 'go help gopath'
go install: no install location for directory /home/runner/work/kata/kata/cmd/kata19 outside GOPATH
	For more details see: 'go help gopath'
##[error]Process completed with exit code 1.

https://github.com/arvenil/kata/runs/609649648?check_suite_focus=true
Any ideas?

@peterwillcn
Copy link

peterwillcn commented Apr 23, 2020 via email

@arvenil
Copy link

arvenil commented Apr 23, 2020

Nevermind. I got it working. The issues is that package is being put outside of GOPATH by setup-go. So I tried to go mod init; go mod vendor however another issue was that this "toy" project didn't had any other dependencies beside standard library so go mod refused to create vendor dir. I then manually created dummy vendor dir and it worked! Go tooling switched from treating this as project that should be in GOPATH to project that is using vendor dir even though there are no vendored dependencies ;)

mkdir vendor
touch vendor/modules.txt

@ydnar
Copy link

ydnar commented Apr 23, 2020

@arvenil does your go.mod have a Go 1.14 line in it? Is it in a monorepo with an existing vendor directory?

@arvenil
Copy link

arvenil commented Apr 23, 2020

@ydnar Yes

@ydnar
Copy link

ydnar commented Apr 23, 2020

@arvenil to fix this, either:

  1. Remove the Go 1.14 line from your go.mod file, or…
  2. Rename vendor to something else. If you have Ruby, for instance, move vendor/bundle to .bundle/vendor and cache gems there.

We had this problem and ended up doing (2).

@esoterikpen
Copy link

$GOBIN could be used as well, but it also needs to be added to $PATH. Since go env GOBIN is not set and $GOPATH/bin is the default installation path it's just simpler to add the default path to $PATH.

I know it's just simple common sense to you but to me... you're a freakin' GENIUS! 💎✨👍

It makes so much fucking sense to me now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.