Skip to content

Commit

Permalink
Try to get version from go.mod file
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Nov 27, 2020
1 parent 44fae30 commit f931f44
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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 = {
Expand All @@ -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 == "") {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f931f44

Please sign in to comment.