Compare commits

...

56 Commits

Author SHA1 Message Date
Fernandez Ludovic
2e788936b0 6.3.1 2025-02-09 02:26:54 +01:00
Ludovic Fernandez
aa1e0941ed chore: update golangci-lint versions (#1159) 2025-02-09 02:22:47 +01:00
Ludovic Fernandez
3e6beafdff fix: restrict patched version to v1 (#1158) 2025-02-09 02:03:24 +01:00
dependabot[bot]
1cc4e007f0 build(deps): bump @types/node from 22.13.0 to 22.13.1 in the dependencies group (#1156) 2025-02-04 16:56:20 +01:00
dependabot[bot]
bbe109d3f8 build(deps-dev): bump the dev-dependencies group with 2 updates (#1155) 2025-02-04 16:55:56 +01:00
Fernandez Ludovic
e60da84bfa chore: update branch references 2025-02-04 15:39:52 +01:00
Ludovic Fernandez
1dd93d052e chore: use new assets file (#1154) 2025-02-04 15:15:08 +01:00
dependabot[bot]
5421a116d2 build(deps): bump @types/node from 22.10.10 to 22.13.0 in the dependencies group (#1153) 2025-02-03 12:48:00 +01:00
dependabot[bot]
260e8cefdb build(deps-dev): bump the dev-dependencies group with 2 updates (#1152) 2025-02-03 12:47:31 +01:00
dependabot[bot]
9665fb5353 build(deps): bump undici from 5.28.4 to 5.28.5 (#1150)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2025-01-27 12:12:42 +00:00
dependabot[bot]
62530743f6 build(deps): bump @types/node from 22.10.7 to 22.10.10 in the dependencies group (#1149) 2025-01-27 12:43:58 +01:00
dependabot[bot]
f71f362e47 build(deps-dev): bump the dev-dependencies group with 2 updates (#1148) 2025-01-27 12:43:11 +01:00
dependabot[bot]
7ec71f69b1 build(deps): bump the dependencies group with 2 updates (#1147)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2025-01-20 18:21:27 +01:00
dependabot[bot]
60c0fc4730 build(deps-dev): bump the dev-dependencies group with 4 updates (#1146) 2025-01-20 16:19:41 +01:00
Kotaro Otaka
a7b658d295 docs: update README options version from required to optional (#1145) 2025-01-17 12:24:51 +01:00
Ludovic Fernandez
ec5d18412c feat: support linux arm64 public preview (#1144) 2025-01-16 21:40:47 +01:00
dependabot[bot]
a0297a1378 build(deps-dev): bump the dev-dependencies group with 3 updates (#1143) 2025-01-13 12:28:21 +01:00
dependabot[bot]
58eda26a51 build(deps): bump @types/node from 22.10.2 to 22.10.5 in the dependencies group (#1142) 2025-01-06 12:56:48 +01:00
dependabot[bot]
44c2434506 build(deps-dev): bump the dev-dependencies group with 2 updates (#1141) 2025-01-06 12:56:21 +01:00
dependabot[bot]
2f13b8027d build(deps-dev): bump the dev-dependencies group with 2 updates (#1139) 2024-12-30 16:15:31 +01:00
dependabot[bot]
1ac36865a6 build(deps-dev): bump the dev-dependencies group with 2 updates (#1138) 2024-12-23 13:54:34 +01:00
dependabot[bot]
9937fdf718 build(deps): bump @types/node from 22.10.1 to 22.10.2 in the dependencies group (#1137) 2024-12-16 15:55:46 +01:00
dependabot[bot]
cb60b26e7a build(deps-dev): bump the dev-dependencies group with 2 updates (#1136) 2024-12-16 15:55:21 +01:00
dependabot[bot]
774c35bccc build(deps): bump @actions/cache from 3.3.0 to 4.0.0 in the dependencies group (#1135)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-12-09 14:21:16 +01:00
dependabot[bot]
7ce548721e build(deps-dev): bump the dev-dependencies group with 3 updates (#1134) 2024-12-09 14:06:45 +01:00
Oleksandr Redko
0e1fd32b0c chore: use new build tag syntax (#1133) 2024-12-04 18:03:01 +01:00
dependabot[bot]
9e66d46e22 build(deps-dev): bump the dev-dependencies group across 1 directory with 4 updates (#1132)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-12-02 12:54:29 +01:00
dependabot[bot]
1720a0ed2a build(deps): bump @types/node from 22.9.3 to 22.10.1 in the dependencies group (#1131) 2024-12-02 12:43:56 +01:00
dependabot[bot]
eab1d2f3d7 build(deps): bump @types/node from 22.9.0 to 22.9.3 in the dependencies group (#1130) 2024-11-25 12:53:46 +01:00
dependabot[bot]
160a1d779c build(deps-dev): bump the dev-dependencies group with 3 updates (#1128) 2024-11-18 14:11:50 +01:00
dependabot[bot]
02ee5067dc build(deps): bump @types/node from 22.8.7 to 22.9.0 in the dependencies group (#1127) 2024-11-11 11:37:34 +01:00
dependabot[bot]
311e61576a build(deps-dev): bump the dev-dependencies group with 2 updates (#1126) 2024-11-11 11:37:09 +01:00
Dmitry Savintsev
363026db34 docs: update local development instructions (#1125)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-11-08 21:40:36 +01:00
dependabot[bot]
ea0c88120e build(deps): bump the dependencies group with 2 updates (#1123)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-11-04 12:52:08 +01:00
dependabot[bot]
968ad765a9 build(deps-dev): bump the dev-dependencies group with 2 updates (#1122) 2024-11-04 11:09:49 +01:00
dependabot[bot]
82fb3f49c2 build(deps): bump @types/node from 22.7.7 to 22.8.1 in the dependencies group (#1120) 2024-10-28 11:02:46 +01:00
dependabot[bot]
10480e9d12 build(deps-dev): bump the dev-dependencies group with 2 updates (#1119) 2024-10-28 11:02:23 +01:00
dependabot[bot]
523baec228 build(deps): bump @types/node from 22.7.5 to 22.7.7 in the dependencies group (#1118) 2024-10-21 13:35:58 +02:00
dependabot[bot]
8e06968c92 build(deps-dev): bump the dev-dependencies group with 2 updates (#1117) 2024-10-21 13:35:36 +02:00
dependabot[bot]
79a180da27 build(deps): bump @types/node from 22.7.4 to 22.7.5 in the dependencies group (#1115) 2024-10-14 13:18:25 +02:00
dependabot[bot]
b92645ea9c build(deps-dev): bump the dev-dependencies group with 3 updates (#1114) 2024-10-14 13:18:08 +02:00
dependabot[bot]
3d4174dbf5 build(deps): bump the dependencies group with 2 updates (#1113)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-10-07 17:31:44 +02:00
dependabot[bot]
0ddaf3ca3f build(deps-dev): bump the dev-dependencies group with 3 updates (#1112) 2024-10-07 16:09:16 +02:00
dependabot[bot]
971e284b60 build(deps-dev): bump the dev-dependencies group with 3 updates (#1108)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-09-30 15:40:11 +02:00
dependabot[bot]
bbe7eb52aa build(deps): bump @types/node from 22.5.5 to 22.7.4 in the dependencies group (#1109) 2024-09-30 14:07:00 +02:00
dependabot[bot]
ebae5cee81 build(deps-dev): bump the dev-dependencies group with 3 updates (#1105) 2024-09-23 13:24:35 +02:00
dependabot[bot]
06c3f3a551 build(deps): bump @types/node from 22.5.4 to 22.5.5 in the dependencies group (#1104) 2024-09-16 13:51:57 +02:00
dependabot[bot]
56689d8f71 build(deps-dev): bump the dev-dependencies group with 3 updates (#1103) 2024-09-16 13:51:34 +02:00
Ludovic Fernandez
c7bab6f874 fix: clean go install output (#1102) 2024-09-13 00:04:49 +02:00
dependabot[bot]
33f56cc1ef build(deps-dev): bump the dev-dependencies group with 3 updates (#1099) 2024-09-09 14:48:59 +02:00
dependabot[bot]
e9542245b2 build(deps): bump @types/node from 22.5.2 to 22.5.4 in the dependencies group (#1100) 2024-09-09 14:48:37 +02:00
dependabot[bot]
68de804037 build(deps): bump @types/node from 22.5.1 to 22.5.2 in the dependencies group (#1098) 2024-09-02 14:02:11 +02:00
dependabot[bot]
22a37566e1 build(deps-dev): bump the dev-dependencies group with 2 updates (#1097) 2024-09-02 14:01:40 +02:00
dependabot[bot]
cb36b7b064 build(deps): bump the dependencies group across 1 directory with 2 updates (#1096)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-08-29 21:53:11 +02:00
dependabot[bot]
acfc9fc846 build(deps): bump the dependencies group with 2 updates (#1089)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-08-29 20:33:04 +02:00
dependabot[bot]
1b319a7ae6 build(deps-dev): bump the dev-dependencies group with 2 updates (#1093) 2024-08-29 20:32:40 +02:00
12 changed files with 22506 additions and 5301 deletions

View File

@@ -2,10 +2,14 @@ name: "Code Scanning - Action"
on:
push:
branches: [ master ]
branches:
- master
- main
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches:
- master
- main
schedule:
- cron: '0 17 * * 5'

View File

@@ -1,9 +1,13 @@
name: "build-and-test"
on: # rebuild any PRs and main branch changes
pull_request:
branches:
- master
- main
push:
branches:
- master
- main
- "releases/*"
jobs:
@@ -47,13 +51,14 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- windows-latest
version:
- ""
- "latest"
- "v1.60"
- "v1.60.1"
- "v1.63" # TODO(ldez): it should be updated for v2.
- "v1.63.4" # TODO(ldez): it should be updated for v2.
runs-on: ${{ matrix.os }}
permissions:
contents: read
@@ -75,13 +80,14 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- windows-latest
version:
- ""
- "latest"
- "v1.60.1"
- "adbdfdb288e939a175182b7a12b7555215ce98b2"
- "v1.63.4" # TODO(ldez): it should be updated for v2.
- "95c39ac1fbaf66475705c06c16259ffd9d6bf9a2" # TODO(ldez): it should be updated for v2.
runs-on: ${{ matrix.os }}
permissions:
contents: read
@@ -104,6 +110,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}

2
.gitignore vendored
View File

@@ -6,7 +6,7 @@ __tests__/runner/*
node_modules/
lib/
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Rest pulled from https://github.com/github/gitignore/blob/HEAD/Node.gitignore
# Logs
logs
*.log

View File

@@ -115,8 +115,8 @@ on:
pull_request:
push:
branches:
- "main"
- "master"
- main
- master
env:
GO_VERSION: stable
@@ -166,8 +166,8 @@ on:
pull_request:
push:
branches:
- "main"
- "master"
- main
- master
jobs:
golangci-lint:
@@ -257,7 +257,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t
### `version`
(required)
(optional)
The version of golangci-lint to use.
@@ -498,7 +498,7 @@ permissions:
The action was implemented with performance in mind:
1. We cache data from golangci-lint analysis between builds by using [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache).
1. We cache data from golangci-lint analysis between builds by using [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache).
2. We don't use Docker because image pulling is slow.
3. We do as much as we can in parallel, e.g. we download cache, and golangci-lint binary in parallel.
@@ -514,7 +514,7 @@ We use JavaScript-based action.
We don't use Docker-based action because:
1. Docker pulling is slow currently
2. it's easier to use caching from [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache)
2. it's easier to use caching from [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache)
We support different platforms, such as `ubuntu`, `macos`, and `windows` with `x32` and `x64` archs.
@@ -522,9 +522,9 @@ Inside our action, we perform 3 steps:
1. Setup environment running in parallel:
* restore [cache](https://github.com/actions/cache) of previous analyses
* fetch [action config](https://github.com/golangci/golangci-lint/blob/master/assets/github-action-config.json) and find the latest `golangci-lint` patch version for needed version
* fetch [action config](https://github.com/golangci/golangci-lint/blob/HEAD/assets/github-action-config.json) and find the latest `golangci-lint` patch version for needed version
(users of this action can specify only minor version of `golangci-lint`).
After that install [golangci-lint](https://github.com/golangci/golangci-lint) using [@actions/tool-cache](https://github.com/actions/toolkit/tree/master/packages/tool-cache)
After that install [golangci-lint](https://github.com/golangci/golangci-lint) using [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache)
2. Run `golangci-lint` with specified by user `args`
3. Save cache for later builds
@@ -544,5 +544,6 @@ This scheme is basic and needs improvements. Pull requests and ideas are welcome
1. Install [act](https://github.com/nektos/act#installation)
2. Make a symlink for `act` to work properly: `ln -s . golangci-lint-action`
3. Prepare deps once: `npm run prepare-deps`
4. Run `npm run local` after any change to test it
3. Install dependencies: `npm install`
4. Build: `npm run build`
5. Run `npm run local` after any change to test it

13456
dist/post_run/index.js generated vendored

File diff suppressed because one or more lines are too long

13456
dist/run/index.js generated vendored

File diff suppressed because one or more lines are too long

654
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "golanci-lint-action",
"version": "3.1.0",
"version": "6.3.1",
"private": true,
"description": "golangci-lint github action",
"main": "dist/main.js",
@@ -24,29 +24,29 @@
"author": "golangci",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.2.4",
"@actions/core": "^1.10.1",
"@actions/cache": "^4.0.0",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/http-client": "^2.2.1",
"@actions/tool-cache": "^2.0.1",
"@types/node": "^22.2.0",
"@actions/http-client": "^2.2.3",
"@actions/tool-cache": "^2.0.2",
"@types/node": "^22.13.1",
"@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6",
"@types/which": "^3.0.4",
"tmp": "^0.2.3",
"which": "^4.0.0"
"which": "^5.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.2.1",
"@typescript-eslint/eslint-plugin": "^8.23.0",
"@typescript-eslint/parser": "^8.23.0",
"@vercel/ncc": "^0.38.3",
"eslint": "^8.57.1",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-simple-import-sort": "^12.1.1",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
"prettier": "^3.4.2",
"typescript": "^5.7.3"
}
}

View File

@@ -1,4 +1,4 @@
// +build tools
//go:build tools
package main

View File

@@ -5,14 +5,13 @@ import os from "os"
import path from "path"
import { promisify } from "util"
import { VersionConfig } from "./version"
import { VersionInfo } from "./version"
const execShellCommand = promisify(exec)
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
const getAssetURL = (versionConfig: VersionConfig): string => {
const getAssetURL = (versionInfo: VersionInfo): string => {
let ext = "tar.gz"
let platform = os.platform().toString()
switch (platform) {
case "win32":
@@ -20,8 +19,12 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
ext = "zip"
break
}
let arch = os.arch()
switch (arch) {
case "arm64":
arch = "arm64"
break
case "x64":
arch = "amd64"
break
@@ -30,9 +33,10 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
arch = "386"
break
}
const noPrefix = versionConfig.TargetVersion.slice(1)
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
const noPrefix = versionInfo.TargetVersion.slice(1)
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
}
export enum InstallMode {
@@ -58,68 +62,75 @@ const printOutput = (res: ExecRes): void => {
/**
* Install golangci-lint.
*
* @param versionConfig information about version to install.
* @param versionInfo information about version to install.
* @param mode installation mode.
* @returns path to installed binary of golangci-lint.
*/
export async function installLint(versionConfig: VersionConfig, mode: InstallMode): Promise<string> {
export async function installLint(versionInfo: VersionInfo, mode: InstallMode): Promise<string> {
core.info(`Installation mode: ${mode}`)
switch (mode) {
case InstallMode.Binary:
return installBin(versionConfig)
return installBin(versionInfo)
case InstallMode.GoInstall:
return goInstall(versionConfig)
return goInstall(versionInfo)
default:
return installBin(versionConfig)
return installBin(versionInfo)
}
}
/**
* Install golangci-lint via `go install`.
*
* @param versionConfig information about version to install.
* @param versionInfo information about version to install.
* @returns path to installed binary of golangci-lint.
*/
export async function goInstall(versionConfig: VersionConfig): Promise<string> {
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
export async function goInstall(versionInfo: VersionInfo): Promise<string> {
core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`)
const startedAt = Date.now()
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@${versionConfig.TargetVersion}`,
`go install github.com/golangci/golangci-lint/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@${versionConfig.TargetVersion}`,
`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`,
options
)
printOutput(res)
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1]
const binPath = res.stderr
.split(/\r?\n/)
.map((v) => v.trimStart().trimEnd())
.filter((v) => v.startsWith("touch "))
.reduce((a, b) => a + b, "")
.split(` `, 2)[1]
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`)
return lintPath
return binPath
}
/**
* Install golangci-lint via the precompiled binary.
*
* @param versionConfig information about version to install.
* @param versionInfo information about version to install.
* @returns path to installed binary of golangci-lint.
*/
export async function installBin(versionConfig: VersionConfig): Promise<string> {
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`)
export async function installBin(versionInfo: VersionInfo): Promise<string> {
core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`)
const startedAt = Date.now()
const assetURL = getAssetURL(versionConfig)
const assetURL = getAssetURL(versionInfo)
core.info(`Downloading binary ${assetURL} ...`)
@@ -141,9 +152,9 @@ export async function installBin(versionConfig: VersionConfig): Promise<string>
const urlParts = assetURL.split(`/`)
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
const binPath = path.join(extractedDir, dirName, `golangci-lint`)
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`)
return lintPath
return binPath
}

View File

@@ -11,7 +11,7 @@ import which from "which"
import { restoreCache, saveCache } from "./cache"
import { installLint, InstallMode } from "./install"
import { alterDiffPatch } from "./utils/diffUtils"
import { findLintVersion } from "./version"
import { getVersion } from "./version"
const execShellCommand = promisify(exec)
const writeFile = promisify(fs.writeFile)
@@ -25,16 +25,16 @@ async function prepareLint(): Promise<string> {
const mode = core.getInput("install-mode").toLowerCase()
if (mode === InstallMode.None) {
const bin = await which("golangci-lint", { nothrow: true })
if (!bin) {
const binPath = await which("golangci-lint", { nothrow: true })
if (!binPath) {
throw new Error("golangci-lint binary not found in the PATH")
}
return bin
return binPath
}
const versionConfig = await findLintVersion(<InstallMode>mode)
const versionInfo = await getVersion(<InstallMode>mode)
return await installLint(versionConfig, <InstallMode>mode)
return await installLint(versionInfo, <InstallMode>mode)
}
async function fetchPatch(): Promise<string> {
@@ -141,7 +141,7 @@ async function fetchPushPatch(ctx: Context): Promise<string> {
}
type Env = {
lintPath: string
binPath: string
patchPath: string
}
@@ -151,12 +151,12 @@ async function prepareEnv(): Promise<Env> {
// Prepare cache, lint and go in parallel.
await restoreCache()
const lintPath = await prepareLint()
const binPath = await prepareLint()
const patchPath = await fetchPatch()
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
return { lintPath, patchPath }
return { binPath: binPath, patchPath }
}
type ExecRes = {
@@ -292,9 +292,9 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
export async function run(): Promise<void> {
try {
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
core.addPath(path.dirname(lintPath))
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath))
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
core.addPath(path.dirname(binPath))
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
} catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`)
core.setFailed(error.message)

View File

@@ -13,10 +13,12 @@ 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.+)/
const parseVersion = (s: string): Version => {
if (s == "latest" || s == "") {
// TODO(ldez): it should be replaced with an explicit version (ex: v1.64.0)
return null
}
@@ -39,6 +41,7 @@ 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,
@@ -61,8 +64,8 @@ const isLessVersion = (a: Version, b: Version): boolean => {
return a.minor < b.minor
}
const getRequestedLintVersion = (): Version => {
let requestedLintVersion = core.getInput(`version`)
const getRequestedVersion = (): Version => {
let requestedVersion = core.getInput(`version`)
const workingDirectory = core.getInput(`working-directory`)
let goMod = "go.mod"
@@ -70,50 +73,50 @@ const getRequestedLintVersion = (): Version => {
goMod = path.join(workingDirectory, goMod)
}
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
if (requestedVersion == "" && 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 '${goMod}' file`)
requestedVersion = match[1]
core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`)
}
}
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
if (parsedRequestedLintVersion == null) {
const parsedRequestedVersion = parseVersion(requestedVersion)
if (parsedRequestedVersion == null) {
return null
}
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
if (isLessVersion(parsedRequestedVersion, minVersion)) {
throw new Error(
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
`requested golangci-lint version '${requestedVersion}' isn't supported: we support only ${stringifyVersion(
minVersion
)} and later versions`
)
}
return parsedRequestedLintVersion
return parsedRequestedVersion
}
export type VersionConfig = {
export type VersionInfo = {
Error?: string
TargetVersion: string
AssetURL: string
}
type Config = {
type VersionMapping = {
MinorVersionToConfig: {
[minorVersion: string]: VersionConfig
[minorVersion: string]: VersionInfo
}
}
const getConfig = async (): Promise<Config> => {
const fetchVersionMapping = async (): Promise<VersionMapping> => {
const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], {
allowRetries: true,
maxRetries: 5,
})
try {
const url = `https://raw.githubusercontent.com/golangci/golangci-lint/master/assets/github-action-config.json`
// TODO(ldez): HEAD should be replaced with an explicit version (ex: v1.64.0).
const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v1.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})`)
@@ -126,49 +129,48 @@ const getConfig = async (): Promise<Config> => {
}
}
export async function findLintVersion(mode: InstallMode): Promise<VersionConfig> {
export async function getVersion(mode: InstallMode): Promise<VersionInfo> {
core.info(`Finding needed golangci-lint version...`)
if (mode == InstallMode.GoInstall) {
const v: string = core.getInput(`version`)
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" }
// TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0).
return { TargetVersion: v ? v : "latest" }
}
const reqLintVersion = getRequestedLintVersion()
const reqVersion = getRequestedVersion()
// if the patched version is passed, just use it
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
// TODO(ldez): should be updated to `reqVersion?.major === 2`.
if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) {
return new Promise((resolve) => {
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`
resolve({
TargetVersion: `v${versionWithoutV}`,
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
})
const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`
resolve({ TargetVersion: `v${versionWithoutV}` })
})
}
const startedAt = Date.now()
const config = await getConfig()
if (!config.MinorVersionToConfig) {
core.warning(JSON.stringify(config))
const mapping = await fetchVersionMapping()
if (!mapping.MinorVersionToConfig) {
core.warning(JSON.stringify(mapping))
throw new Error(`invalid config: no MinorVersionToConfig field`)
}
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
if (!versionConfig) {
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
const versionInfo = mapping.MinorVersionToConfig[stringifyVersion(reqVersion)]
if (!versionInfo) {
throw new Error(`requested golangci-lint version '${stringifyVersion(reqVersion)}' doesn't exist`)
}
if (versionConfig.Error) {
throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqLintVersion)}': ${versionConfig.Error}`)
if (versionInfo.Error) {
throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqVersion)}': ${versionInfo.Error}`)
}
core.info(
`Requested golangci-lint '${stringifyVersion(reqLintVersion)}', using '${versionConfig.TargetVersion}', calculation took ${
`Requested golangci-lint '${stringifyVersion(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${
Date.now() - startedAt
}ms`
)
return versionConfig
return versionInfo
}