kevincobain2000 / gobrew

Go version manager, written in Go. Super simple tool to install and manage Go versions. Install go without root. Gobrew doesn't require shell rehash.
https://medium.com/web-developer/go-version-manager-gobrew-c8750157dfe6
MIT License
358 stars 24 forks source link

Support for Go workspaces #184

Closed AviDuda closed 4 months ago

AviDuda commented 5 months ago

Go workspaces have a Go version specified in them but gobrew doesn't support it at the moment.

My use case: I have a Nx monorepo with a mix of Go and React apps. These apps are in apps/<dir>, but VS Code's Go extension complains when I don't have the go.work file in the root directory of the monorepo.

This is the error when opening any Go file:

This file is within module "apps/<dir>", which is not included in your workspace. To fix this problem, you can add a go.work file that uses this directory.

Being able to detect the current Go version from the go.work file would help a lot so I could easily wire it up to GitHub Actions builds without having to manually edit it in multiple places.

kevincobain2000 commented 5 months ago

Interesting. I am not familiar with go.work so I'd have to read up or take suggestions.

If you have a go.mod file inside your work space, then just hitting gobrew command should bring up the interactive and ask you to change the go version based on go.mod. For actions, you can use gobrew noninteractive

Hope that helped

kevincobain2000 commented 5 months ago

And for the action, you can also do this

      - uses: kevincobain2000/action-gobrew@v2
        working-directory: myapp
        with:
          version: mod
AviDuda commented 4 months ago

I wasn't familiar with it either, it surprised me when I saw the error. The Go extension links to this document.

This is my current go.work file in the root directory:

go 1.20

use ./apps/my-app

Thanks for the tip about the action, I missed that I can do this. Would be nice to explicitly mention in the readme that mod is a valid gobrew version name (it's in the CLI help and in the action example but it's easily missable, looks like the help command in the readme is outdated).

Edit: Looks like the working-directory doesn't support uses, it supports only run steps.

kevincobain2000 commented 4 months ago

Edit: Looks like the working-directory doesn't support uses, it supports only run steps.

Oh yea, right

This should fix it https://github.com/kevincobain2000/action-gobrew/pull/3

kevincobain2000 commented 4 months ago

And

looks like the help command in the readme is outdated

Would be nice to explicitly mention in the readme that mod is a valid gobrew version name

Yea, sorry, README was a bit out of touch. I have updated it now.

This should fix it https://github.com/kevincobain2000/gobrew/pull/185

kevincobain2000 commented 4 months ago

All pushed and merged.