feat: add version-file option (#1320)
This commit is contained in:
committed by
GitHub
parent
a6071aaacb
commit
aa6fad0ea0
@@ -67,6 +67,12 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
||||
|
||||
const getRequestedVersion = (): Version => {
|
||||
let requestedVersion = core.getInput(`version`)
|
||||
let versionFilePath = core.getInput(`version-file`)
|
||||
|
||||
if (requestedVersion && versionFilePath) {
|
||||
core.warning(`Both version (${requestedVersion}) and version-file (${versionFilePath}) inputs are specified, only version will be used`)
|
||||
}
|
||||
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
|
||||
let goMod = "go.mod"
|
||||
@@ -83,6 +89,27 @@ const getRequestedVersion = (): Version => {
|
||||
}
|
||||
}
|
||||
|
||||
if (requestedVersion == "" && versionFilePath) {
|
||||
if (workingDirectory) {
|
||||
versionFilePath = path.join(workingDirectory, versionFilePath)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(`The specified golangci-lint version file at: ${versionFilePath} does not exist`)
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(versionFilePath, "utf-8")
|
||||
|
||||
if (path.basename(versionFilePath) === ".tool-versions") {
|
||||
// asdf/mise file.
|
||||
const match = content.match(/^golangci-lint\s+([^\n#]+)/m)
|
||||
requestedVersion = match ? "v" + match[1].trim().replace(/^v/gi, "") : ""
|
||||
} else {
|
||||
// .golangci-lint-version file.
|
||||
requestedVersion = "v" + content.trim().replace(/^v/gi, "")
|
||||
}
|
||||
}
|
||||
|
||||
const parsedRequestedVersion = parseVersion(requestedVersion)
|
||||
if (parsedRequestedVersion == null) {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user