actions / setup-go

Set up your GitHub Actions workflow with a specific version of Go
MIT License
1.41k stars 531 forks source link

Remove the description of the old go.mod specification #458

Closed 178inaba closed 7 months ago

178inaba commented 9 months ago

Description:

Starting from Go 1.21, the go.mod file now includes patch versions as well.

$ go1.21.0 mod init test
go: creating new go.mod: module test
$ cat go.mod
module test

go 1.21.0

This is explained in the official Go documentation.

Go 1.21 introduces a small change to the numbering of releases. In the past, we used Go 1.N to refer to both the overall Go language version and release family as well as the first release in that family. Starting in Go 1.21, the first release is now Go 1.N.0. Today we are releasing both the Go 1.21 language and its initial implementation, the Go 1.21.0 release. These notes refer to “Go 1.21”; tools like go version will report “go1.21.0” (until you upgrade to Go 1.21.1). See “Go versions” in the “Go Toolchains” documentation for details about the new version numbering. https://go.dev/doc/go1.21#introduction

setup-go retrieves the version of the go.mod file using the following code and can obtain the patch version as well.

https://github.com/actions/setup-go/blob/6c1fd22b67f7a7c42ad9a45c0f4197434035e429/src/installer.ts#L427

Test:

https://www.typescriptlang.org/play?#code/MYewdgzgLgBKZQKYIjAvDARAcxDAjAHQBMxhADJgNwBQ80MAtgIZTAAW6c4SKhLbdgAoA9AD1cMIQB0AJgGoZhOfICUAKlUjGq2vRAAbRIQMhsQgR10wYQA

Additionally, I fixed the following:

Related issue:

Fixes #461.

Check list:

This pull request is a documentation update itself. No testing is necessary.

gowridurgad commented 8 months ago

Hi @178inaba ,Could you please update the readme file with the below content, " The go-version-file input accepts a path to a go.mod file or a go.work file that contains the version of Go to be used by a project. The action will search for the latest available version sequentially in the runner's directory with the cached tools, in the [versions-manifest.json] (https://github.com/actions/go-versions/blob/main/versions- manifest.json) file or at the go servers." please add both with and without quotes here ,because both scenarios are working: go-version-file: 'path/to/go.mod' or go-version-file: path/to/go.mod

178inaba commented 8 months ago

@gowridurgad Thank you for the review!

The action will search for the latest available version sequentially in the runner's directory with the cached tools, in the versions-manifest.json file or at the go servers.

The go.mod file or go.work file now includes patch versions as well. Therefore, the version is fixed, and I thought there is no need to search for the latest version. Is this thinking incorrect?

please add both with and without quotes here ,because both scenarios are working: go-version-file: 'path/to/go.mod' or go-version-file: path/to/go.mod

The README includes a section on 'cache-dependency-path', but it is not enclosed in quotes. Therefore, I thought it would be better to align with this. https://github.com/actions/setup-go/blob/be1aa1186e83689f3e45adaf3697af86f816fb2e/README.md?plain=1#L175-L177

ldemailly commented 7 months ago

Searching for latest version is how it's been working before 1.22 / toolchain and I think it's the expected feature, I shouldn't need to keep changing my go.mod for a patch level and the go version in go.mod should be language version not a specific patch level (I complained as much in https://github.com/golang/go/issues/66175#issuecomment-2010343876)

178inaba commented 7 months ago

@ldemailly Thank you for commenting!

In toolchains from version 1.21 onwards, there have been errors when running go mod tidy if the patch version is not specified. Therefore, it is believed that specifying the patch version is required.

$ cat go.mod
module test

go 1.22
$ go1.21.0 mod tidy
go: downloading go1.22 (darwin/amd64)
go: download go1.22 for darwin/amd64: toolchain not available

I've read several issue comments, and the corrective approach seems to be changing the error messages to prompt modifications to the go.mod files.

https://github.com/golang/go/issues/66175#issuecomment-2035182462 https://github.com/golang/go/issues/62278#issuecomment-2032858417

aparnajyothi-y commented 7 months ago

Hello @178inaba , Your reasoning makes sense ,The go.mod file or go.work file now includes patch versions as well. Therefore, the version is fixed, and there is no need to search for the latest version but If you want to allow flexibility for using newer patch versions without updating the go.mod or go.work file, the current behavior can be beneficial and The versions-manifest.json file can help ensure that the action uses a version of Go that's tested. This could be beneficial for ensuring compatibility and stability.so could please update the readme file.

178inaba commented 7 months ago

@aparnajyothi-y Thank you for commenting!

I also verified that if I specified the toolchain as below, no error would occur with go mod tidy.

$ cat go.mod
module test

go 1.22

toolchain go1.22.0

In this case, setup-go will look for the latest patch version of 1.22. Therefore, I will add this behavior to the README.

178inaba commented 7 months ago

I have added the following:

The `go` directive in `go.mod` can specify a patch version or omit it altogether (e.g., `go 1.22.0` or `go 1.22`).  
If a patch version is specified, that specific patch version will be used.  
If no patch version is specified, it will search for the latest available patch version in the cache,
[versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json), and the
[official Go language website](https://golang.org/dl/?mode=json&include=all), in that order.
gowridurgad commented 7 months ago

Hi @178inaba, To avoid confusions, please revert this change or add both with and without quotes because both scenarios are working. go-version-file: 'path/to/go.mod' or go-version-file: path/to/go.mod

178inaba commented 7 months ago

@gowridurgad I reverted!

Mago16 commented 7 months ago

El El mar, 9 de abr de 2024 a la(s) 10:52 p.m., Priya Gupta < @.***> escribió:

@.**** approved this pull request.

— Reply to this email directly, view it on GitHub https://github.com/actions/setup-go/pull/458#pullrequestreview-1990790820, or unsubscribe https://github.com/notifications/unsubscribe-auth/AX4MPLHBF4IKJVYIA4MWNRTY4TAQ7AVCNFSM6AAAAABDNNFWHCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSOJQG44TAOBSGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>