Skip to content

Commit 51485a4

Browse files
lukasmalkmusSergey Vilgelm
and
Sergey Vilgelm
authored
Try to get version from go.mod file (#118)
* Try to get version from go.mod file * re-build Co-authored-by: Sergey Vilgelm <[email protected]>
1 parent a12ae43 commit 51485a4

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

dist/post_run/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
22372237
exports.findLintVersion = exports.stringifyVersion = void 0;
22382238
const core = __importStar(__webpack_require__(470));
22392239
const httpm = __importStar(__webpack_require__(539));
2240+
const fs = __importStar(__webpack_require__(747));
22402241
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
2242+
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
22412243
const parseVersion = (s) => {
22422244
if (s == "latest" || s == "") {
22432245
return null;
@@ -2279,7 +2281,15 @@ const isLessVersion = (a, b) => {
22792281
return a.minor < b.minor;
22802282
};
22812283
const getRequestedLintVersion = () => {
2282-
const requestedLintVersion = core.getInput(`version`);
2284+
let requestedLintVersion = core.getInput(`version`);
2285+
if (requestedLintVersion == "") {
2286+
const content = fs.readFileSync("go.mod", "utf-8");
2287+
const match = content.match(modVersionRe);
2288+
if (match) {
2289+
requestedLintVersion = match[1];
2290+
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
2291+
}
2292+
}
22832293
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
22842294
if (parsedRequestedLintVersion == null) {
22852295
return null;

dist/run/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
22372237
exports.findLintVersion = exports.stringifyVersion = void 0;
22382238
const core = __importStar(__webpack_require__(470));
22392239
const httpm = __importStar(__webpack_require__(539));
2240+
const fs = __importStar(__webpack_require__(747));
22402241
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
2242+
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
22412243
const parseVersion = (s) => {
22422244
if (s == "latest" || s == "") {
22432245
return null;
@@ -2279,7 +2281,15 @@ const isLessVersion = (a, b) => {
22792281
return a.minor < b.minor;
22802282
};
22812283
const getRequestedLintVersion = () => {
2282-
const requestedLintVersion = core.getInput(`version`);
2284+
let requestedLintVersion = core.getInput(`version`);
2285+
if (requestedLintVersion == "") {
2286+
const content = fs.readFileSync("go.mod", "utf-8");
2287+
const match = content.match(modVersionRe);
2288+
if (match) {
2289+
requestedLintVersion = match[1];
2290+
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
2291+
}
2292+
}
22832293
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
22842294
if (parsedRequestedLintVersion == null) {
22852295
return null;

src/version.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from "@actions/core"
22
import * as httpm from "@actions/http-client"
3+
import * as fs from "fs"
34

45
// TODO: make a class
56
export type Version = {
@@ -9,6 +10,7 @@ export type Version = {
910
} | null
1011

1112
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
13+
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/
1214

1315
const parseVersion = (s: string): Version => {
1416
if (s == "latest" || s == "") {
@@ -56,7 +58,17 @@ const isLessVersion = (a: Version, b: Version): boolean => {
5658
}
5759

5860
const getRequestedLintVersion = (): Version => {
59-
const requestedLintVersion = core.getInput(`version`)
61+
let requestedLintVersion = core.getInput(`version`)
62+
63+
if (requestedLintVersion == "") {
64+
const content = fs.readFileSync("go.mod", "utf-8")
65+
const match = content.match(modVersionRe)
66+
if (match) {
67+
requestedLintVersion = match[1]
68+
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`)
69+
}
70+
}
71+
6072
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
6173
if (parsedRequestedLintVersion == null) {
6274
return null

0 commit comments

Comments
 (0)