From f931f449cb7fbf2e6495c1677494999e20a6b35d Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Tue, 27 Oct 2020 01:21:40 +0100 Subject: [PATCH] Try to get version from go.mod file --- src/version.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/version.ts b/src/version.ts index c06580640d..5a036722f2 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,5 +1,6 @@ import * as core from "@actions/core" import * as httpm from "@actions/http-client" +import * as fs from 'fs' // TODO: make a class export type Version = { @@ -9,6 +10,7 @@ export type Version = { } | null const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/ +const modVersionRe = /github.com\/golangci\/golangci-lint\sv(.+)/ const parseVersion = (s: string): Version => { if (s == "latest" || s == "") { @@ -56,7 +58,16 @@ const isLessVersion = (a: Version, b: Version): boolean => { } const getRequestedLintVersion = (): Version => { - const requestedLintVersion = core.getInput(`version`) + let requestedLintVersion = core.getInput(`version`) + + if (requestedLintVersion == "") { + const content = fs.readFileSync('go.mod', 'utf-8') + const match = content.match(modVersionRe) + if (match) { + requestedLintVersion = match[0] + } + } + const parsedRequestedLintVersion = parseVersion(requestedLintVersion) if (parsedRequestedLintVersion == null) { return null