Check that go.mod exists in reading the version (#173)

Add additional tests in github actions
Support working directory for reading the version from go.mod
This commit is contained in:
Sergey Vilgelm
2021-02-23 23:51:00 -06:00
committed by GitHub
parent 51485a4001
commit d9f0e73c04
8 changed files with 744 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import * as core from "@actions/core"
import * as httpm from "@actions/http-client"
import * as fs from "fs"
import path from "path"
// TODO: make a class
export type Version = {
@ -59,13 +60,18 @@ const isLessVersion = (a: Version, b: Version): boolean => {
const getRequestedLintVersion = (): Version => {
let requestedLintVersion = core.getInput(`version`)
const workingDirectory = core.getInput(`working-directory`)
let goMod = "go.mod"
if (workingDirectory) {
goMod = path.join(workingDirectory, goMod)
}
if (requestedLintVersion == "") {
const content = fs.readFileSync("go.mod", "utf-8")
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8")
const match = content.match(modVersionRe)
if (match) {
requestedLintVersion = match[1]
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`)
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`)
}
}