Skip to content

Commit f931f44

Browse files
committed
Try to get version from go.mod file
1 parent 44fae30 commit f931f44

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/version.ts

Lines changed: 12 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\sv(.+)/
1214

1315
const parseVersion = (s: string): Version => {
1416
if (s == "latest" || s == "") {
@@ -56,7 +58,16 @@ 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[0]
68+
}
69+
}
70+
6071
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
6172
if (parsedRequestedLintVersion == null) {
6273
return null

0 commit comments

Comments
 (0)