Skip to content

More specific handling/detection of Go toolchain versions #457

Open
@matthewhughes934

Description

Description:

The goal is to just have an approach to manage toolchain installs, the following is a suggestion and open to discussion/changes:

  • If the user provides a specific version, ensure we use exactly that version (possibly requires setting GOTOOLCHAIN=local in the environment, see docs)
  • If the user provides a go-version-file, and:
    • The file has a toolchain directive: then use that since the docs say

      The toolchain line declares a suggested toolchain to use with the module or workspace

      This is in comparison with the go version, which is the minimum version of Go required to install the module (the assumption being: we're working within the module, not install it)

    • The file has no toolchain directive: then use the version from the go directive (current behaviour)

Justification:

At the moment this action does not consider toolchain versions. This leads to:

  • Some duplicate work, the action will install a version of Go, a toolchain will be detected, the toolchain will be detected and then another version of Go installed
  • Unexpected behaviour: if you specify this action runs with some Go version (e.g. 1.21.0) but your go.mod contains a toolchain directive for a newer version (e.g. 1.22.0) then, without any other configuration/environment setup, any go commands will be run using go 1.22.0
  • Tar errors on cache restore after toolchain installation #424 is related to not managing toolchain installs

You can see this in this example repo, which is just a repo with a go.mod whose go directive is 1.21.0 and whose toolchain directive is 1.22.0 and some actions that display the version of Go under some conditions, of interest is when we specify the action with version 1.21.0: we ask for 1.21.0 but a toolchain install will result in 1.22.0 being installed and run

Are you willing to submit a PR?

Yep, but there should be some discussion around which approach to take before implementing anything

EDIT: I noticed that the official Go docker images also set GOTOOLCHAIN=local https://github.com/docker-library/golang/blob/dae3405a325073e8ad7c8c378ebdf2540d8565c4/Dockerfile-linux.template#L162C3-L163C1 with some discussion on the linked issue there: docker-library/golang#472

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions