feat: golangci-lint v2 support (#1198)
This commit is contained in:
committed by
GitHub
parent
1f07148fa0
commit
dec74fa030
@@ -84,16 +84,14 @@ async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
||||
|
||||
const options: ExecOptions = { env: { ...process.env, CGO_ENABLED: "1" } }
|
||||
|
||||
// TODO(ldez): it should be updated for v2.
|
||||
const exres = await execShellCommand(
|
||||
`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
options
|
||||
)
|
||||
printOutput(exres)
|
||||
|
||||
// TODO(ldez): it should be updated for v2.
|
||||
const res = await execShellCommand(
|
||||
`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
options
|
||||
)
|
||||
printOutput(res)
|
||||
|
27
src/run.ts
27
src/run.ts
@@ -51,7 +51,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
printOutput(res)
|
||||
}
|
||||
|
||||
let userArgs = core.getInput(`args`)
|
||||
const userArgs = core.getInput(`args`)
|
||||
const addedArgs: string[] = []
|
||||
|
||||
const userArgsList = userArgs
|
||||
@@ -76,23 +76,13 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const formats = (userArgsMap.get("out-format") || "")
|
||||
.trim()
|
||||
.split(",")
|
||||
.filter((f) => f.length > 0)
|
||||
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
|
||||
.join(",")
|
||||
|
||||
if (formats) {
|
||||
// Adds formats but without `github-actions` format.
|
||||
addedArgs.push(`--out-format=${formats}`)
|
||||
}
|
||||
|
||||
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
||||
|
||||
if (isOnlyNewIssues()) {
|
||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
||||
if (
|
||||
userArgNames.has(`new`) ||
|
||||
userArgNames.has(`new-from-rev`) ||
|
||||
userArgNames.has(`new-from-patch`) ||
|
||||
userArgNames.has(`new-from-merge-base`)
|
||||
) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
|
||||
}
|
||||
|
||||
@@ -110,6 +100,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
// Override config values.
|
||||
addedArgs.push(`--new=false`)
|
||||
addedArgs.push(`--new-from-rev=`)
|
||||
addedArgs.push(`--new-from-merge-base=`)
|
||||
}
|
||||
break
|
||||
case `merge_group`:
|
||||
@@ -118,6 +109,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
// Override config values.
|
||||
addedArgs.push(`--new=false`)
|
||||
addedArgs.push(`--new-from-patch=`)
|
||||
addedArgs.push(`--new-from-merge-base=`)
|
||||
break
|
||||
default:
|
||||
break
|
||||
@@ -150,7 +142,6 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
core.info(`golangci-lint found no issues`)
|
||||
} catch (exc) {
|
||||
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
|
||||
// TODO: support reviewdog or leaving comments by GitHub API.
|
||||
printOutput(exc)
|
||||
|
||||
if (exc.code === 1) {
|
||||
|
@@ -13,13 +13,11 @@ export type Version = {
|
||||
} | null
|
||||
|
||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
|
||||
// TODO(ldez): it should be updated to match v2 module name.
|
||||
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v\S+)/
|
||||
const modVersionRe = /github.com\/golangci\/golangci-lint\/v2\s(v\S+)/
|
||||
|
||||
const parseVersion = (s: string): Version => {
|
||||
if (s == "latest" || s == "") {
|
||||
// TODO(ldez): v2: it should be replaced with "return null"
|
||||
return { major: 1, minor: 64, patch: 8 }
|
||||
return null
|
||||
}
|
||||
|
||||
const match = s.match(versionRe)
|
||||
@@ -27,11 +25,8 @@ const parseVersion = (s: string): Version => {
|
||||
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
||||
}
|
||||
|
||||
// TODO(ldez): v2: to remove.
|
||||
if (parseInt(match[1]) > 1) {
|
||||
throw new Error(
|
||||
`invalid version string '${s}', golangci-lint v2 is not supported by golangci-lint-action v6, you must update to golangci-lint-action v7.`
|
||||
)
|
||||
if (parseInt(match[1]) !== 2) {
|
||||
throw new Error(`invalid version string '${s}', golangci-lint v${match[1]} is not supported by golangci-lint-action v7.`)
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -48,11 +43,10 @@ export const stringifyVersion = (v: Version): string => {
|
||||
return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
|
||||
}
|
||||
|
||||
// TODO(ldez): it should be updated to v2.0.0.
|
||||
const minVersion = {
|
||||
major: 1,
|
||||
minor: 28,
|
||||
patch: 3,
|
||||
major: 2,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
}
|
||||
|
||||
const isLessVersion = (a: Version, b: Version): boolean => {
|
||||
@@ -122,7 +116,7 @@ const fetchVersionMapping = async (): Promise<VersionMapping> => {
|
||||
maxRetries: 5,
|
||||
})
|
||||
try {
|
||||
const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v1.json`
|
||||
const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v2.json`
|
||||
const response: httpm.HttpClientResponse = await http.get(url)
|
||||
if (response.message.statusCode !== 200) {
|
||||
throw new Error(`failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`)
|
||||
@@ -140,20 +134,14 @@ export async function getVersion(mode: InstallMode): Promise<VersionInfo> {
|
||||
|
||||
if (mode == InstallMode.GoInstall) {
|
||||
const v: string = core.getInput(`version`)
|
||||
// TODO(ldez): v2: to remove.
|
||||
if (v == "latest") {
|
||||
return { TargetVersion: "v1.64.8" }
|
||||
}
|
||||
|
||||
// TODO(ldez): v2: "v1.64.8" should be replaced with "latest".
|
||||
return { TargetVersion: v ? v : "v1.64.8" }
|
||||
return { TargetVersion: v ? v : "latest" }
|
||||
}
|
||||
|
||||
const reqVersion = getRequestedVersion()
|
||||
|
||||
// if the patched version is passed, just use it
|
||||
// TODO(ldez): should be updated to `reqVersion?.major === 2`.
|
||||
if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) {
|
||||
if (reqVersion?.major === 2 && reqVersion?.minor != null && reqVersion?.patch !== null) {
|
||||
return new Promise((resolve) => {
|
||||
const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`
|
||||
resolve({ TargetVersion: `v${versionWithoutV}` })
|
||||
|
Reference in New Issue
Block a user