-
Notifications
You must be signed in to change notification settings - Fork 535
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
Changes from 5 commits
a707d84
d706c92
95c6e43
f5fe54e
55b9afc
757cc0b
df84f4b
fabe212
dbe1872
1fefa4e
676a55b
0cd474d
aa32cee
a6b717d
fab50db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @radeksimko 👋 ! Thank you, that's definitely a good point! We are going to update setup-go documentation with the new chapter related to this functionality with a more broad description of the input. |
||||||
stable: | ||||||
description: 'Whether to download only stable versions' | ||||||
default: 'true' | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. As the input |
||
if (!isMod) { | ||
return contents.trim(); | ||
} | ||
|
||
const match = contents.match(/^go (\d+(\.\d+)*)/m); | ||
return match ? match[1] : ''; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ export async function run() { | |
// versionSpec is optional. If supplied, install / use from the tool cache | ||
// If not supplied then problem matchers will still be setup. Useful for self-hosted. | ||
// | ||
let versionSpec = core.getInput('go-version'); | ||
const versionSpec = resolveVersionInput(); | ||
|
||
// stable will be true unless false is the exact input | ||
// since getting unstable versions should be explicit | ||
|
@@ -90,3 +90,21 @@ function isGhes(): boolean { | |
); | ||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; | ||
} | ||
|
||
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 commentThe 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) { | ||
return version; | ||
} | ||
|
||
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 commentThe 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. |
||
|
||
return version; | ||
} |
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.