mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-16 15:38:28 +00:00
Try to get version from go.mod file
This commit is contained in:
parent
a12ae43dd8
commit
163fdb033d
3 changed files with 7183 additions and 10497 deletions
8833
dist/post_run/index.js
vendored
8833
dist/post_run/index.js
vendored
File diff suppressed because one or more lines are too long
8833
dist/run/index.js
vendored
8833
dist/run/index.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as httpm from "@actions/http-client"
|
import * as httpm from "@actions/http-client"
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
// TODO: make a class
|
// TODO: make a class
|
||||||
export type Version = {
|
export type Version = {
|
||||||
|
|
@ -9,6 +10,7 @@ export type Version = {
|
||||||
} | null
|
} | null
|
||||||
|
|
||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
|
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
|
||||||
|
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/
|
||||||
|
|
||||||
const parseVersion = (s: string): Version => {
|
const parseVersion = (s: string): Version => {
|
||||||
if (s == "latest" || s == "") {
|
if (s == "latest" || s == "") {
|
||||||
|
|
@ -56,7 +58,17 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRequestedLintVersion = (): Version => {
|
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)
|
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
|
||||||
if (parsedRequestedLintVersion == null) {
|
if (parsedRequestedLintVersion == null) {
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue