Skip to content

Commit

Permalink
Try to get version from go.mod file (#118)
Browse files Browse the repository at this point in the history
* Try to get version from go.mod file

* re-build

Co-authored-by: Sergey Vilgelm <[email protected]>
  • Loading branch information
lukasmalkmus and Sergey Vilgelm authored Feb 23, 2021
1 parent a12ae43 commit 51485a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
12 changes: 11 additions & 1 deletion dist/post_run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.findLintVersion = exports.stringifyVersion = void 0;
const core = __importStar(__webpack_require__(470));
const httpm = __importStar(__webpack_require__(539));
const fs = __importStar(__webpack_require__(747));
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => {
if (s == "latest" || s == "") {
return null;
Expand Down Expand Up @@ -2279,7 +2281,15 @@ const isLessVersion = (a, b) => {
return a.minor < b.minor;
};
const getRequestedLintVersion = () => {
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[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
}
}
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
if (parsedRequestedLintVersion == null) {
return null;
Expand Down
12 changes: 11 additions & 1 deletion dist/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.findLintVersion = exports.stringifyVersion = void 0;
const core = __importStar(__webpack_require__(470));
const httpm = __importStar(__webpack_require__(539));
const fs = __importStar(__webpack_require__(747));
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => {
if (s == "latest" || s == "") {
return null;
Expand Down Expand Up @@ -2279,7 +2281,15 @@ const isLessVersion = (a, b) => {
return a.minor < b.minor;
};
const getRequestedLintVersion = () => {
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[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
}
}
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
if (parsedRequestedLintVersion == null) {
return null;
Expand Down
14 changes: 13 additions & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -9,6 +10,7 @@ export type Version = {
} | null

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

const parseVersion = (s: string): Version => {
if (s == "latest" || s == "") {
Expand Down Expand Up @@ -56,7 +58,17 @@ 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[1]
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`)
}
}

const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
if (parsedRequestedLintVersion == null) {
return null
Expand Down

0 comments on commit 51485a4

Please sign in to comment.