diff --git a/dist/post_run/index.js b/dist/post_run/index.js index f86b54a..3fe5749 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -97912,6 +97912,10 @@ const isLessVersion = (a, b) => { }; const getRequestedVersion = () => { 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"; if (workingDirectory) { @@ -97925,6 +97929,24 @@ const getRequestedVersion = () => { core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`); } } + if (requestedVersion == "" && versionFilePath) { + if (workingDirectory) { + versionFilePath = path_1.default.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_1.default.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; diff --git a/dist/run/index.js b/dist/run/index.js index 98236e9..5a83821 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -97912,6 +97912,10 @@ const isLessVersion = (a, b) => { }; const getRequestedVersion = () => { 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"; if (workingDirectory) { @@ -97925,6 +97929,24 @@ const getRequestedVersion = () => { core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`); } } + if (requestedVersion == "" && versionFilePath) { + if (workingDirectory) { + versionFilePath = path_1.default.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_1.default.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;