-
-
Notifications
You must be signed in to change notification settings - Fork 100
feat: add version-file input
#542
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||||||||||||
| import * as core from '@actions/core'; | ||||||||||||||||||
| import * as fs from 'fs'; | ||||||||||||||||||
| import path from 'path'; | ||||||||||||||||||
| import {Inputs} from './context'; | ||||||||||||||||||
|
|
||||||||||||||||||
| export function getRequestedVersion(inputs: Inputs): string { | ||||||||||||||||||
| let requestedVersion = inputs.version; | ||||||||||||||||||
| let versionFilePath = inputs.versionFile; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (requestedVersion && versionFilePath) { | ||||||||||||||||||
| core.warning( | ||||||||||||||||||
| `Both version (${requestedVersion}) and version-file (${versionFilePath}) inputs are specified, only version will be used` | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (requestedVersion == '' && versionFilePath) { | ||||||||||||||||||
| const workingDirectory = inputs.workdir; | ||||||||||||||||||
| if (workingDirectory) { | ||||||||||||||||||
| versionFilePath = path.join(workingDirectory, versionFilePath); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!fs.existsSync(versionFilePath)) { | ||||||||||||||||||
| throw new Error(`The specified GoReleaser version file at: ${versionFilePath} does not exist`); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+11
to
+18
|
||||||||||||||||||
|
|
||||||||||||||||||
| const content = fs.readFileSync(versionFilePath, 'utf-8'); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (path.basename(versionFilePath) === '.tool-versions') { | ||||||||||||||||||
| // asdf/mise file. | ||||||||||||||||||
| const match = content.match(/^goreleaser\s+([^\n#]+)/m); | ||||||||||||||||||
|
||||||||||||||||||
| const match = content.match(/^goreleaser\s+([^\n#]+)/m); | |
| const match = content.match(/^\s*goreleaser\s+([^\n#]+)/m); |
Copilot
AI
Mar 3, 2026
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.
If .tool-versions doesn’t contain a goreleaser ... entry, this sets requestedVersion to an empty string, which will likely cause a confusing failure later during install. Prefer throwing a clear error when no matching entry is found (e.g., file exists but no goreleaser line), so users get an actionable message.
| requestedVersion = match ? 'v' + match[1].trim().replace(/^v/gi, '') : ''; | |
| if (!match) { | |
| throw new Error( | |
| `No 'goreleaser' entry found in ${versionFilePath}. ` + | |
| "Please add a line like 'goreleaser <version>' or specify the version input directly." | |
| ); | |
| } | |
| requestedVersion = 'v' + match[1].trim().replace(/^v/gi, ''); |
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 wonder if it would be better to simplify all this making
version-filehaving precedenceso, if
version-fileis given, use it, or errorotherwise, use
version, which would also mean we don't need to manually default to~> v2wdyt?
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 think it is a better solution indeed because then I can revert all the changes about how the default version is computed.
I've taken much inspiration from the current implementation in the goreleaser action, so I've essentially implemented the same behavior.
Let me change it with your suggestion.