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 go-version-from-file option #62
Conversation
👋🏻 Is there anything in particular blocking this PR from being merged? |
Echoing the above, is there anything the community can do to help get this enhancement reviewed? It would be very useful to replace a workaround we use in a few dozen repositories that my team manages. |
goodluk so I like to aplikasion |
It would be great if this option can also read and extract the go version from a |
@ccremer I agree that such thing would be helpful, but it seems to me like a separate feature, as the complexity of pulling any content out of |
That's what I meant with
I implied that extracting requires parsing in that context :) I imagined something like
In any case, there are already workarounds to extract the version from go.mod. |
|
I second this, some repositories do not implement a |
Wow Best |
The Go version is already included in Essentially that would be something like this: This could be an alternative option as well. Instead "from file" a "from go mod" or something See #174 (comment) |
I think those are two different things. The version in |
Hi, @jojo43 |
@IvanZosimov |
Thanks for your answer, @jojo43 What we are planning to implement:
|
@IvanZosimov |
Hi @jojo43 main
branch (now it's attached to the master)?
action.yml
Outdated
@@ -4,6 +4,8 @@ author: 'GitHub' | |||
inputs: | |||
go-version: | |||
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' | |||
go-version-from-file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go-version-from-file: | |
go-version-file: |
action.yml
Outdated
@@ -4,6 +4,8 @@ author: 'GitHub' | |||
inputs: | |||
go-version: | |||
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' | |||
go-version-from-file: | |||
description: Path to the file with the Go version. go-version overwrites this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: Path to the file with the Go version. go-version overwrites this. | |
description: 'Path to the go.mod file.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IvanZosimov FWIW as an end user I would find the original description more accurate. While I guess none of us can predict what % of users will end up specifying go.mod
and what other % .go-version
, but I assume (hope) that the intention is to support both and so the description should reflect that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @radeksimko
function resolveVersionInput(): string { | ||
let version = core.getInput('go-version'); | ||
const versionFilePath = core.getInput('go-version-file'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add here the warning when the user specifies both inputs:
if (version && versionFilePath) {
core.warning(
'Both go-version and go-version-file inputs are specified, only go-version will be used'
);
}
src/installer.ts
Outdated
@@ -266,3 +266,12 @@ export function makeSemver(version: string): string { | |||
|
|||
return `${verPart}${prereleasePart}`; | |||
} | |||
|
|||
export function parseGoVersionFile(contents: string, isMod: boolean): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the input go-version-file
should contain the path to a go.mod
file (we'll deliberately ask our customers to put there a path to go.mod
file ), I'd suggest not using isMod
parameter in this function and don't check whether path refers to 'go.mod' file.
src/main.ts
Outdated
if (versionFilePath) { | ||
version = installer.parseGoVersionFile( | ||
fs.readFileSync(versionFilePath).toString(), | ||
path.basename(versionFilePath) === 'go.mod' | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest keeping this conditional statement very similar to the one in setup-node action. Otherwise, some important functionality will be lost.
@IvanZosimov |
Hello @jojo43. Could you please add new job in |
Thanks a bunch to @jojo43 for pushing this! Nevertheless, please take into consideration @radeksimko remarks, because they are spot-on, IMHO. For a CI-CD workflow, you typically want to select the exact point revision you are using, not what happens to be the last one available (if you want reproducible builds, that is). Otherwise you can end up with a non-functioning build, and be flabbergasted about why. For instance, in the 1.16.x or 1.17.x series there was a point release that changed the behavior of the web server, requiring changes to code using it, otherwise your program wouldn't build. I wholeheartedly recommend the approach shown here, where the Go version is read from a My 2¢. Thanks again! |
Hi, @jojo43
|
Shifted chapter related to retrieving go version from go.mod file and updated yml example
Change README.md file
Hi all, Thank you for working on this! While reading this thread, I'm not sure why the Is it just an out of scope for the initial implementation? or it won't be supported by design? |
Hi, @minamijoyo Cheers! |
@IvanZosimov Thank you for the reply. Sounds good |
I added an option
go-version-from-file
as suggested in #23 (comment) .