mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2026-01-16 04:14:30 +07:00
feat: add version-file option (#1320)
This commit is contained in:
committed by
GitHub
parent
a6071aaacb
commit
aa6fad0ea0
22
dist/run/index.js
generated
vendored
22
dist/run/index.js
generated
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user