Skip to content

Set GOTOOLCHAIN=local if go-version[-file] is set and GOTOOLCHAIN is not already present #491

@Frederick888

Description

@Frederick888

Description:
When a user sets go-version[-file] explicitly, they'd often expect the version (range) to be enforced.

So I think we should set GOTOOLCHAIN=local to disable automatic toolchain switching in this case.

This is similar to #420 but with a bit more details.

Justification:
We maintain a few libraries where we want to make sure they are compatible with the last two Go major version releases (1.X and 1.X-1 to be clear, i.e. minor versions in SemVer).

We don't dictate which Go version contributors use, especially patch versions, but we have set up a GHA matrix like:

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        go_version:
          - 1.21.x
          - 1.22.x
    steps:
      - uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go_version }}

Now for example, someone who uses Go 1.22.x may accidentally put a go 1.22.5 line in go.mod, and both jobs in the testing matrix will still pass. If it isn't caught in review, due to the changes since Go 1.21, AFAIU the library will require its consumers to upgrade to Go 1.22.5+, which is apparently unexpected.

So I think when a user specifies a Go version, we should set GOTOOLCHAIN=local to disable this new Go behaviour. If they do want it to happen, they can set an Action or job level GOTOOLCHAIN=auto (or don't set go-version[-file] if they don't care about it at all).

Are you willing to submit a PR?

Yes.

Metadata

Metadata

Assignees

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