Compare commits

..

10 Commits

10 changed files with 298 additions and 309 deletions

View File

@ -57,8 +57,8 @@ jobs:
version: version:
- "" - ""
- "latest" - "latest"
- "v1.60" # TODO(ldez): it should be updated for v2. - "v1.63" # TODO(ldez): it should be updated for v2.
- "v1.60.1" # TODO(ldez): it should be updated for v2. - "v1.63.4" # TODO(ldez): it should be updated for v2.
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
permissions: permissions:
contents: read contents: read
@ -86,8 +86,8 @@ jobs:
version: version:
- "" - ""
- "latest" - "latest"
- "v1.60.1" # TODO(ldez): it should be updated for v2. - "v1.63.4" # TODO(ldez): it should be updated for v2.
- "adbdfdb288e939a175182b7a12b7555215ce98b2" # TODO(ldez): it should be updated for v2. - "95c39ac1fbaf66475705c06c16259ffd9d6bf9a2" # TODO(ldez): it should be updated for v2.
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
permissions: permissions:
contents: read contents: read

View File

@ -23,3 +23,21 @@
* Ensure the PR description clearly describes the problem and solution. * Ensure the PR description clearly describes the problem and solution.
Include the relevant issue number if applicable. Include the relevant issue number if applicable.
## Development of this action
1. Install [act](https://github.com/nektos/act#installation)
2. Make a symlink for `act` to work properly: `ln -s . golangci-lint-action`
3. Install dependencies: `npm install`
4. Build: `npm run build`
5. Run `npm run local` after any change to test it
### Releases
```bash
npm version <major | minor | patch> -m "Upgrade to %s"
```
- https://docs.npmjs.com/cli/v11/commands/npm-version
The "major tag" (ex: `v6`) should be deleted and then recreated manually.

View File

@ -539,11 +539,3 @@ Inside our action, we perform 3 steps:
GitHub matches keys by prefix if we have no exact match for the primary cache. GitHub matches keys by prefix if we have no exact match for the primary cache.
This scheme is basic and needs improvements. Pull requests and ideas are welcome. This scheme is basic and needs improvements. Pull requests and ideas are welcome.
## Development of this action
1. Install [act](https://github.com/nektos/act#installation)
2. Make a symlink for `act` to work properly: `ln -s . golangci-lint-action`
3. Install dependencies: `npm install`
4. Build: `npm run build`
5. Run `npm run local` after any change to test it

140
dist/post_run/index.js generated vendored
View File

@ -93689,8 +93689,7 @@ const os_1 = __importDefault(__nccwpck_require__(857));
const path_1 = __importDefault(__nccwpck_require__(6928)); const path_1 = __importDefault(__nccwpck_require__(6928));
const util_1 = __nccwpck_require__(9023); const util_1 = __nccwpck_require__(9023);
const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"; const getAssetURL = (versionInfo) => {
const getAssetURL = (versionConfig) => {
let ext = "tar.gz"; let ext = "tar.gz";
let platform = os_1.default.platform().toString(); let platform = os_1.default.platform().toString();
switch (platform) { switch (platform) {
@ -93712,8 +93711,8 @@ const getAssetURL = (versionConfig) => {
arch = "386"; arch = "386";
break; break;
} }
const noPrefix = versionConfig.TargetVersion.slice(1); const noPrefix = versionInfo.TargetVersion.slice(1);
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`; return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
}; };
var InstallMode; var InstallMode;
(function (InstallMode) { (function (InstallMode) {
@ -93732,57 +93731,57 @@ const printOutput = (res) => {
/** /**
* Install golangci-lint. * Install golangci-lint.
* *
* @param versionConfig information about version to install. * @param versionInfo information about version to install.
* @param mode installation mode. * @param mode installation mode.
* @returns path to installed binary of golangci-lint. * @returns path to installed binary of golangci-lint.
*/ */
async function installLint(versionConfig, mode) { async function installLint(versionInfo, mode) {
core.info(`Installation mode: ${mode}`); core.info(`Installation mode: ${mode}`);
switch (mode) { switch (mode) {
case InstallMode.Binary: case InstallMode.Binary:
return installBin(versionConfig); return installBin(versionInfo);
case InstallMode.GoInstall: case InstallMode.GoInstall:
return goInstall(versionConfig); return goInstall(versionInfo);
default: default:
return installBin(versionConfig); return installBin(versionInfo);
} }
} }
/** /**
* Install golangci-lint via `go install`. * 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. * @returns path to installed binary of golangci-lint.
*/ */
async function goInstall(versionConfig) { async function goInstall(versionInfo) {
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`); core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`);
const startedAt = Date.now(); const startedAt = Date.now();
const options = { env: { ...process.env, CGO_ENABLED: "1" } }; const options = { env: { ...process.env, CGO_ENABLED: "1" } };
// TODO(ldez): it should be updated for v2. // TODO(ldez): it should be updated for v2.
const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options); const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
printOutput(exres); printOutput(exres);
// TODO(ldez): it should be updated for v2. // 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}`, options); const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
printOutput(res); printOutput(res);
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`. // The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
const lintPath = res.stderr const binPath = res.stderr
.split(/\r?\n/) .split(/\r?\n/)
.map((v) => v.trimStart().trimEnd()) .map((v) => v.trimStart().trimEnd())
.filter((v) => v.startsWith("touch ")) .filter((v) => v.startsWith("touch "))
.reduce((a, b) => a + b, "") .reduce((a, b) => a + b, "")
.split(` `, 2)[1]; .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. * 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. * @returns path to installed binary of golangci-lint.
*/ */
async function installBin(versionConfig) { async function installBin(versionInfo) {
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`); core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`);
const startedAt = Date.now(); const startedAt = Date.now();
const assetURL = getAssetURL(versionConfig); const assetURL = getAssetURL(versionInfo);
core.info(`Downloading binary ${assetURL} ...`); core.info(`Downloading binary ${assetURL} ...`);
const archivePath = await tc.downloadTool(assetURL); const archivePath = await tc.downloadTool(assetURL);
let extractedDir = ""; let extractedDir = "";
@ -93801,9 +93800,9 @@ async function installBin(versionConfig) {
} }
const urlParts = assetURL.split(`/`); const urlParts = assetURL.split(`/`);
const dirName = urlParts[urlParts.length - 1].replace(repl, ``); const dirName = urlParts[urlParts.length - 1].replace(repl, ``);
const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); const binPath = path_1.default.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;
} }
@ -93874,14 +93873,14 @@ function isOnlyNewIssues() {
async function prepareLint() { async function prepareLint() {
const mode = core.getInput("install-mode").toLowerCase(); const mode = core.getInput("install-mode").toLowerCase();
if (mode === install_1.InstallMode.None) { if (mode === install_1.InstallMode.None) {
const bin = await (0, which_1.default)("golangci-lint", { nothrow: true }); const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
if (!bin) { if (!binPath) {
throw new Error("golangci-lint binary not found in the PATH"); throw new Error("golangci-lint binary not found in the PATH");
} }
return bin; return binPath;
} }
const versionConfig = await (0, version_1.findLintVersion)(mode); const versionInfo = await (0, version_1.getVersion)(mode);
return await (0, install_1.installLint)(versionConfig, mode); return await (0, install_1.installLint)(versionInfo, mode);
} }
async function fetchPatch() { async function fetchPatch() {
if (!isOnlyNewIssues()) { if (!isOnlyNewIssues()) {
@ -93980,10 +93979,10 @@ async function prepareEnv() {
const startedAt = Date.now(); const startedAt = Date.now();
// Prepare cache, lint and go in parallel. // Prepare cache, lint and go in parallel.
await (0, cache_1.restoreCache)(); await (0, cache_1.restoreCache)();
const lintPath = await prepareLint(); const binPath = await prepareLint();
const patchPath = await fetchPatch(); const patchPath = await fetchPatch();
core.info(`Prepared env in ${Date.now() - startedAt}ms`); core.info(`Prepared env in ${Date.now() - startedAt}ms`);
return { lintPath, patchPath }; return { binPath, patchPath };
} }
const printOutput = (res) => { const printOutput = (res) => {
if (res.stdout) { if (res.stdout) {
@ -93993,10 +93992,10 @@ const printOutput = (res) => {
core.info(res.stderr); core.info(res.stderr);
} }
}; };
async function runLint(lintPath, patchPath) { async function runLint(binPath, patchPath) {
const debug = core.getInput(`debug`); const debug = core.getInput(`debug`);
if (debug.split(`,`).includes(`cache`)) { if (debug.split(`,`).includes(`cache`)) {
const res = await execShellCommand(`${lintPath} cache status`); const res = await execShellCommand(`${binPath} cache status`);
printOutput(res); printOutput(res);
} }
let userArgs = core.getInput(`args`); let userArgs = core.getInput(`args`);
@ -94069,7 +94068,7 @@ async function runLint(lintPath, patchPath) {
} }
cmdArgs.cwd = path.resolve(workingDirectory); cmdArgs.cwd = path.resolve(workingDirectory);
} }
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd(); const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`); core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const startedAt = Date.now(); const startedAt = Date.now();
try { try {
@ -94092,9 +94091,9 @@ async function runLint(lintPath, patchPath) {
} }
async function run() { async function run() {
try { try {
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv); const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);
core.addPath(path.dirname(lintPath)); core.addPath(path.dirname(binPath));
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath)); await core.group(`run golangci-lint`, () => runLint(binPath, patchPath));
} }
catch (error) { catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`); core.error(`Failed to run: ${error}, ${error.stack}`);
@ -94320,14 +94319,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.stringifyVersion = void 0; exports.stringifyVersion = void 0;
exports.findLintVersion = findLintVersion; exports.getVersion = getVersion;
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const httpm = __importStar(__nccwpck_require__(4844)); const httpm = __importStar(__nccwpck_require__(4844));
const fs = __importStar(__nccwpck_require__(9896)); const fs = __importStar(__nccwpck_require__(9896));
const os_1 = __importDefault(__nccwpck_require__(857));
const path_1 = __importDefault(__nccwpck_require__(6928)); const path_1 = __importDefault(__nccwpck_require__(6928));
const install_1 = __nccwpck_require__(232); const install_1 = __nccwpck_require__(232);
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; 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 modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => { const parseVersion = (s) => {
if (s == "latest" || s == "") { if (s == "latest" || s == "") {
@ -94371,31 +94370,31 @@ const isLessVersion = (a, b) => {
// then it returns false, since the patch version of requested is always zero // then it returns false, since the patch version of requested is always zero
return a.minor < b.minor; return a.minor < b.minor;
}; };
const getRequestedLintVersion = () => { const getRequestedVersion = () => {
let requestedLintVersion = core.getInput(`version`); let requestedVersion = core.getInput(`version`);
const workingDirectory = core.getInput(`working-directory`); const workingDirectory = core.getInput(`working-directory`);
let goMod = "go.mod"; let goMod = "go.mod";
if (workingDirectory) { if (workingDirectory) {
goMod = path_1.default.join(workingDirectory, goMod); goMod = path_1.default.join(workingDirectory, goMod);
} }
if (requestedLintVersion == "" && fs.existsSync(goMod)) { if (requestedVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8"); const content = fs.readFileSync(goMod, "utf-8");
const match = content.match(modVersionRe); const match = content.match(modVersionRe);
if (match) { if (match) {
requestedLintVersion = match[1]; requestedVersion = match[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`); core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
} }
} }
const parsedRequestedLintVersion = parseVersion(requestedLintVersion); const parsedRequestedVersion = parseVersion(requestedVersion);
if (parsedRequestedLintVersion == null) { if (parsedRequestedVersion == null) {
return 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 ${(0, exports.stringifyVersion)(minVersion)} and later versions`); throw new Error(`requested golangci-lint version '${requestedVersion}' isn't supported: we support only ${(0, exports.stringifyVersion)(minVersion)} and later versions`);
} }
return parsedRequestedLintVersion; return parsedRequestedVersion;
}; };
const getConfig = async () => { const fetchVersionMapping = async () => {
const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], { const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], {
allowRetries: true, allowRetries: true,
maxRetries: 5, maxRetries: 5,
@ -94414,44 +94413,37 @@ const getConfig = async () => {
throw new Error(`failed to get action config: ${exc.message}`); throw new Error(`failed to get action config: ${exc.message}`);
} }
}; };
async function findLintVersion(mode) { async function getVersion(mode) {
core.info(`Finding needed golangci-lint version...`); core.info(`Finding needed golangci-lint version...`);
if (mode == install_1.InstallMode.GoInstall) { if (mode == install_1.InstallMode.GoInstall) {
const v = core.getInput(`version`); const v = core.getInput(`version`);
// TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0). // TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0).
// TODO(ldez): AssetURL should be updated for v2. return { TargetVersion: v ? v : "latest" };
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" };
} }
const reqLintVersion = getRequestedLintVersion(); const reqVersion = getRequestedVersion();
// if the patched version is passed, just use it // 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) => { return new Promise((resolve) => {
let arch = "amd64"; const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`;
if (os_1.default.arch() === "arm64") { resolve({ TargetVersion: `v${versionWithoutV}` });
arch = "arm64";
}
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-${arch}.tar.gz`,
});
}); });
} }
const startedAt = Date.now(); const startedAt = Date.now();
const config = await getConfig(); const mapping = await fetchVersionMapping();
if (!config.MinorVersionToConfig) { if (!mapping.MinorVersionToConfig) {
core.warning(JSON.stringify(config)); core.warning(JSON.stringify(mapping));
throw new Error(`invalid config: no MinorVersionToConfig field`); throw new Error(`invalid config: no MinorVersionToConfig field`);
} }
const versionConfig = config.MinorVersionToConfig[(0, exports.stringifyVersion)(reqLintVersion)]; const versionInfo = mapping.MinorVersionToConfig[(0, exports.stringifyVersion)(reqVersion)];
if (!versionConfig) { if (!versionInfo) {
throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}' doesn't exist`); throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}' doesn't exist`);
} }
if (versionConfig.Error) { if (versionInfo.Error) {
throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}': ${versionConfig.Error}`); throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}': ${versionInfo.Error}`);
} }
core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqLintVersion)}', using '${versionConfig.TargetVersion}', calculation took ${Date.now() - startedAt}ms`); core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${Date.now() - startedAt}ms`);
return versionConfig; return versionInfo;
} }

140
dist/run/index.js generated vendored
View File

@ -93689,8 +93689,7 @@ const os_1 = __importDefault(__nccwpck_require__(857));
const path_1 = __importDefault(__nccwpck_require__(6928)); const path_1 = __importDefault(__nccwpck_require__(6928));
const util_1 = __nccwpck_require__(9023); const util_1 = __nccwpck_require__(9023);
const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"; const getAssetURL = (versionInfo) => {
const getAssetURL = (versionConfig) => {
let ext = "tar.gz"; let ext = "tar.gz";
let platform = os_1.default.platform().toString(); let platform = os_1.default.platform().toString();
switch (platform) { switch (platform) {
@ -93712,8 +93711,8 @@ const getAssetURL = (versionConfig) => {
arch = "386"; arch = "386";
break; break;
} }
const noPrefix = versionConfig.TargetVersion.slice(1); const noPrefix = versionInfo.TargetVersion.slice(1);
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`; return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
}; };
var InstallMode; var InstallMode;
(function (InstallMode) { (function (InstallMode) {
@ -93732,57 +93731,57 @@ const printOutput = (res) => {
/** /**
* Install golangci-lint. * Install golangci-lint.
* *
* @param versionConfig information about version to install. * @param versionInfo information about version to install.
* @param mode installation mode. * @param mode installation mode.
* @returns path to installed binary of golangci-lint. * @returns path to installed binary of golangci-lint.
*/ */
async function installLint(versionConfig, mode) { async function installLint(versionInfo, mode) {
core.info(`Installation mode: ${mode}`); core.info(`Installation mode: ${mode}`);
switch (mode) { switch (mode) {
case InstallMode.Binary: case InstallMode.Binary:
return installBin(versionConfig); return installBin(versionInfo);
case InstallMode.GoInstall: case InstallMode.GoInstall:
return goInstall(versionConfig); return goInstall(versionInfo);
default: default:
return installBin(versionConfig); return installBin(versionInfo);
} }
} }
/** /**
* Install golangci-lint via `go install`. * 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. * @returns path to installed binary of golangci-lint.
*/ */
async function goInstall(versionConfig) { async function goInstall(versionInfo) {
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`); core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`);
const startedAt = Date.now(); const startedAt = Date.now();
const options = { env: { ...process.env, CGO_ENABLED: "1" } }; const options = { env: { ...process.env, CGO_ENABLED: "1" } };
// TODO(ldez): it should be updated for v2. // TODO(ldez): it should be updated for v2.
const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options); const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
printOutput(exres); printOutput(exres);
// TODO(ldez): it should be updated for v2. // 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}`, options); const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
printOutput(res); printOutput(res);
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`. // The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
const lintPath = res.stderr const binPath = res.stderr
.split(/\r?\n/) .split(/\r?\n/)
.map((v) => v.trimStart().trimEnd()) .map((v) => v.trimStart().trimEnd())
.filter((v) => v.startsWith("touch ")) .filter((v) => v.startsWith("touch "))
.reduce((a, b) => a + b, "") .reduce((a, b) => a + b, "")
.split(` `, 2)[1]; .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. * 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. * @returns path to installed binary of golangci-lint.
*/ */
async function installBin(versionConfig) { async function installBin(versionInfo) {
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`); core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`);
const startedAt = Date.now(); const startedAt = Date.now();
const assetURL = getAssetURL(versionConfig); const assetURL = getAssetURL(versionInfo);
core.info(`Downloading binary ${assetURL} ...`); core.info(`Downloading binary ${assetURL} ...`);
const archivePath = await tc.downloadTool(assetURL); const archivePath = await tc.downloadTool(assetURL);
let extractedDir = ""; let extractedDir = "";
@ -93801,9 +93800,9 @@ async function installBin(versionConfig) {
} }
const urlParts = assetURL.split(`/`); const urlParts = assetURL.split(`/`);
const dirName = urlParts[urlParts.length - 1].replace(repl, ``); const dirName = urlParts[urlParts.length - 1].replace(repl, ``);
const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); const binPath = path_1.default.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;
} }
@ -93874,14 +93873,14 @@ function isOnlyNewIssues() {
async function prepareLint() { async function prepareLint() {
const mode = core.getInput("install-mode").toLowerCase(); const mode = core.getInput("install-mode").toLowerCase();
if (mode === install_1.InstallMode.None) { if (mode === install_1.InstallMode.None) {
const bin = await (0, which_1.default)("golangci-lint", { nothrow: true }); const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
if (!bin) { if (!binPath) {
throw new Error("golangci-lint binary not found in the PATH"); throw new Error("golangci-lint binary not found in the PATH");
} }
return bin; return binPath;
} }
const versionConfig = await (0, version_1.findLintVersion)(mode); const versionInfo = await (0, version_1.getVersion)(mode);
return await (0, install_1.installLint)(versionConfig, mode); return await (0, install_1.installLint)(versionInfo, mode);
} }
async function fetchPatch() { async function fetchPatch() {
if (!isOnlyNewIssues()) { if (!isOnlyNewIssues()) {
@ -93980,10 +93979,10 @@ async function prepareEnv() {
const startedAt = Date.now(); const startedAt = Date.now();
// Prepare cache, lint and go in parallel. // Prepare cache, lint and go in parallel.
await (0, cache_1.restoreCache)(); await (0, cache_1.restoreCache)();
const lintPath = await prepareLint(); const binPath = await prepareLint();
const patchPath = await fetchPatch(); const patchPath = await fetchPatch();
core.info(`Prepared env in ${Date.now() - startedAt}ms`); core.info(`Prepared env in ${Date.now() - startedAt}ms`);
return { lintPath, patchPath }; return { binPath, patchPath };
} }
const printOutput = (res) => { const printOutput = (res) => {
if (res.stdout) { if (res.stdout) {
@ -93993,10 +93992,10 @@ const printOutput = (res) => {
core.info(res.stderr); core.info(res.stderr);
} }
}; };
async function runLint(lintPath, patchPath) { async function runLint(binPath, patchPath) {
const debug = core.getInput(`debug`); const debug = core.getInput(`debug`);
if (debug.split(`,`).includes(`cache`)) { if (debug.split(`,`).includes(`cache`)) {
const res = await execShellCommand(`${lintPath} cache status`); const res = await execShellCommand(`${binPath} cache status`);
printOutput(res); printOutput(res);
} }
let userArgs = core.getInput(`args`); let userArgs = core.getInput(`args`);
@ -94069,7 +94068,7 @@ async function runLint(lintPath, patchPath) {
} }
cmdArgs.cwd = path.resolve(workingDirectory); cmdArgs.cwd = path.resolve(workingDirectory);
} }
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd(); const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`); core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
const startedAt = Date.now(); const startedAt = Date.now();
try { try {
@ -94092,9 +94091,9 @@ async function runLint(lintPath, patchPath) {
} }
async function run() { async function run() {
try { try {
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv); const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);
core.addPath(path.dirname(lintPath)); core.addPath(path.dirname(binPath));
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath)); await core.group(`run golangci-lint`, () => runLint(binPath, patchPath));
} }
catch (error) { catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`); core.error(`Failed to run: ${error}, ${error.stack}`);
@ -94320,14 +94319,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.stringifyVersion = void 0; exports.stringifyVersion = void 0;
exports.findLintVersion = findLintVersion; exports.getVersion = getVersion;
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const httpm = __importStar(__nccwpck_require__(4844)); const httpm = __importStar(__nccwpck_require__(4844));
const fs = __importStar(__nccwpck_require__(9896)); const fs = __importStar(__nccwpck_require__(9896));
const os_1 = __importDefault(__nccwpck_require__(857));
const path_1 = __importDefault(__nccwpck_require__(6928)); const path_1 = __importDefault(__nccwpck_require__(6928));
const install_1 = __nccwpck_require__(232); const install_1 = __nccwpck_require__(232);
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; 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 modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => { const parseVersion = (s) => {
if (s == "latest" || s == "") { if (s == "latest" || s == "") {
@ -94371,31 +94370,31 @@ const isLessVersion = (a, b) => {
// then it returns false, since the patch version of requested is always zero // then it returns false, since the patch version of requested is always zero
return a.minor < b.minor; return a.minor < b.minor;
}; };
const getRequestedLintVersion = () => { const getRequestedVersion = () => {
let requestedLintVersion = core.getInput(`version`); let requestedVersion = core.getInput(`version`);
const workingDirectory = core.getInput(`working-directory`); const workingDirectory = core.getInput(`working-directory`);
let goMod = "go.mod"; let goMod = "go.mod";
if (workingDirectory) { if (workingDirectory) {
goMod = path_1.default.join(workingDirectory, goMod); goMod = path_1.default.join(workingDirectory, goMod);
} }
if (requestedLintVersion == "" && fs.existsSync(goMod)) { if (requestedVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8"); const content = fs.readFileSync(goMod, "utf-8");
const match = content.match(modVersionRe); const match = content.match(modVersionRe);
if (match) { if (match) {
requestedLintVersion = match[1]; requestedVersion = match[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`); core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`);
} }
} }
const parsedRequestedLintVersion = parseVersion(requestedLintVersion); const parsedRequestedVersion = parseVersion(requestedVersion);
if (parsedRequestedLintVersion == null) { if (parsedRequestedVersion == null) {
return 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 ${(0, exports.stringifyVersion)(minVersion)} and later versions`); throw new Error(`requested golangci-lint version '${requestedVersion}' isn't supported: we support only ${(0, exports.stringifyVersion)(minVersion)} and later versions`);
} }
return parsedRequestedLintVersion; return parsedRequestedVersion;
}; };
const getConfig = async () => { const fetchVersionMapping = async () => {
const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], { const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], {
allowRetries: true, allowRetries: true,
maxRetries: 5, maxRetries: 5,
@ -94414,44 +94413,37 @@ const getConfig = async () => {
throw new Error(`failed to get action config: ${exc.message}`); throw new Error(`failed to get action config: ${exc.message}`);
} }
}; };
async function findLintVersion(mode) { async function getVersion(mode) {
core.info(`Finding needed golangci-lint version...`); core.info(`Finding needed golangci-lint version...`);
if (mode == install_1.InstallMode.GoInstall) { if (mode == install_1.InstallMode.GoInstall) {
const v = core.getInput(`version`); const v = core.getInput(`version`);
// TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0). // TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0).
// TODO(ldez): AssetURL should be updated for v2. return { TargetVersion: v ? v : "latest" };
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" };
} }
const reqLintVersion = getRequestedLintVersion(); const reqVersion = getRequestedVersion();
// if the patched version is passed, just use it // 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) => { return new Promise((resolve) => {
let arch = "amd64"; const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`;
if (os_1.default.arch() === "arm64") { resolve({ TargetVersion: `v${versionWithoutV}` });
arch = "arm64";
}
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-${arch}.tar.gz`,
});
}); });
} }
const startedAt = Date.now(); const startedAt = Date.now();
const config = await getConfig(); const mapping = await fetchVersionMapping();
if (!config.MinorVersionToConfig) { if (!mapping.MinorVersionToConfig) {
core.warning(JSON.stringify(config)); core.warning(JSON.stringify(mapping));
throw new Error(`invalid config: no MinorVersionToConfig field`); throw new Error(`invalid config: no MinorVersionToConfig field`);
} }
const versionConfig = config.MinorVersionToConfig[(0, exports.stringifyVersion)(reqLintVersion)]; const versionInfo = mapping.MinorVersionToConfig[(0, exports.stringifyVersion)(reqVersion)];
if (!versionConfig) { if (!versionInfo) {
throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}' doesn't exist`); throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}' doesn't exist`);
} }
if (versionConfig.Error) { if (versionInfo.Error) {
throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}': ${versionConfig.Error}`); throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}': ${versionInfo.Error}`);
} }
core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqLintVersion)}', using '${versionConfig.TargetVersion}', calculation took ${Date.now() - startedAt}ms`); core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${Date.now() - startedAt}ms`);
return versionConfig; return versionInfo;
} }

128
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "golanci-lint-action", "name": "golanci-lint-action",
"version": "3.1.0", "version": "6.3.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "golanci-lint-action", "name": "golanci-lint-action",
"version": "3.1.0", "version": "6.3.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^4.0.0", "@actions/cache": "^4.0.0",
@ -15,7 +15,7 @@
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/http-client": "^2.2.3", "@actions/http-client": "^2.2.3",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^2.0.2",
"@types/node": "^22.13.0", "@types/node": "^22.13.1",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6", "@types/tmp": "^0.2.6",
"@types/which": "^3.0.4", "@types/which": "^3.0.4",
@ -23,15 +23,15 @@
"which": "^5.0.0" "which": "^5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.22.0", "@typescript-eslint/eslint-plugin": "^8.23.0",
"@typescript-eslint/parser": "^8.22.0", "@typescript-eslint/parser": "^8.23.0",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3", "eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-simple-import-sort": "^12.1.1",
"prettier": "^3.4.2", "prettier": "^3.5.0",
"typescript": "^5.7.3" "typescript": "^5.7.3"
} }
}, },
@ -706,9 +706,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "22.13.0", "version": "22.13.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.0.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
"integrity": "sha512-ClIbNe36lawluuvq3+YYhnIN2CELi+6q8NpnM7PYp4hBn/TatfboPgVSm2rwKRfnV2M+Ty9GWDFI64KEe+kysA==", "integrity": "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"undici-types": "~6.20.0" "undici-types": "~6.20.0"
@ -760,21 +760,21 @@
"integrity": "sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w==" "integrity": "sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w=="
}, },
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.23.0.tgz",
"integrity": "sha512-4Uta6REnz/xEJMvwf72wdUnC3rr4jAQf5jnTkeRQ9b6soxLxhDEbS/pfMPoJLDfFPNVRdryqWUIV/2GZzDJFZw==", "integrity": "sha512-vBz65tJgRrA1Q5gWlRfvoH+w943dq9K1p1yDBY2pc+a1nbBLZp7fB9+Hk8DaALUbzjqlMfgaqlVPT1REJdkt/w==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@eslint-community/regexpp": "^4.10.0", "@eslint-community/regexpp": "^4.10.0",
"@typescript-eslint/scope-manager": "8.22.0", "@typescript-eslint/scope-manager": "8.23.0",
"@typescript-eslint/type-utils": "8.22.0", "@typescript-eslint/type-utils": "8.23.0",
"@typescript-eslint/utils": "8.22.0", "@typescript-eslint/utils": "8.23.0",
"@typescript-eslint/visitor-keys": "8.22.0", "@typescript-eslint/visitor-keys": "8.23.0",
"graphemer": "^1.4.0", "graphemer": "^1.4.0",
"ignore": "^5.3.1", "ignore": "^5.3.1",
"natural-compare": "^1.4.0", "natural-compare": "^1.4.0",
"ts-api-utils": "^2.0.0" "ts-api-utils": "^2.0.1"
}, },
"engines": { "engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@ -790,16 +790,16 @@
} }
}, },
"node_modules/@typescript-eslint/parser": { "node_modules/@typescript-eslint/parser": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.23.0.tgz",
"integrity": "sha512-MqtmbdNEdoNxTPzpWiWnqNac54h8JDAmkWtJExBVVnSrSmi9z+sZUt0LfKqk9rjqmKOIeRhO4fHHJ1nQIjduIQ==", "integrity": "sha512-h2lUByouOXFAlMec2mILeELUbME5SZRN/7R9Cw2RD2lRQQY08MWMM+PmVVKKJNK1aIwqTo9t/0CvOxwPbRIE2Q==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "8.22.0", "@typescript-eslint/scope-manager": "8.23.0",
"@typescript-eslint/types": "8.22.0", "@typescript-eslint/types": "8.23.0",
"@typescript-eslint/typescript-estree": "8.22.0", "@typescript-eslint/typescript-estree": "8.23.0",
"@typescript-eslint/visitor-keys": "8.22.0", "@typescript-eslint/visitor-keys": "8.23.0",
"debug": "^4.3.4" "debug": "^4.3.4"
}, },
"engines": { "engines": {
@ -815,14 +815,14 @@
} }
}, },
"node_modules/@typescript-eslint/scope-manager": { "node_modules/@typescript-eslint/scope-manager": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.23.0.tgz",
"integrity": "sha512-/lwVV0UYgkj7wPSw0o8URy6YI64QmcOdwHuGuxWIYznO6d45ER0wXUbksr9pYdViAofpUCNJx/tAzNukgvaaiQ==", "integrity": "sha512-OGqo7+dXHqI7Hfm+WqkZjKjsiRtFUQHPdGMXzk5mYXhJUedO7e/Y7i8AK3MyLMgZR93TX4bIzYrfyVjLC+0VSw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@typescript-eslint/types": "8.22.0", "@typescript-eslint/types": "8.23.0",
"@typescript-eslint/visitor-keys": "8.22.0" "@typescript-eslint/visitor-keys": "8.23.0"
}, },
"engines": { "engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@ -833,16 +833,16 @@
} }
}, },
"node_modules/@typescript-eslint/type-utils": { "node_modules/@typescript-eslint/type-utils": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.23.0.tgz",
"integrity": "sha512-NzE3aB62fDEaGjaAYZE4LH7I1MUwHooQ98Byq0G0y3kkibPJQIXVUspzlFOmOfHhiDLwKzMlWxaNv+/qcZurJA==", "integrity": "sha512-iIuLdYpQWZKbiH+RkCGc6iu+VwscP5rCtQ1lyQ7TYuKLrcZoeJVpcLiG8DliXVkUxirW/PWlmS+d6yD51L9jvA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@typescript-eslint/typescript-estree": "8.22.0", "@typescript-eslint/typescript-estree": "8.23.0",
"@typescript-eslint/utils": "8.22.0", "@typescript-eslint/utils": "8.23.0",
"debug": "^4.3.4", "debug": "^4.3.4",
"ts-api-utils": "^2.0.0" "ts-api-utils": "^2.0.1"
}, },
"engines": { "engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@ -857,9 +857,9 @@
} }
}, },
"node_modules/@typescript-eslint/types": { "node_modules/@typescript-eslint/types": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.23.0.tgz",
"integrity": "sha512-0S4M4baNzp612zwpD4YOieP3VowOARgK2EkN/GBn95hpyF8E2fbMT55sRHWBq+Huaqk3b3XK+rxxlM8sPgGM6A==", "integrity": "sha512-1sK4ILJbCmZOTt9k4vkoulT6/y5CHJ1qUYxqpF1K/DBAd8+ZUL4LlSCxOssuH5m4rUaaN0uS0HlVPvd45zjduQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@ -871,20 +871,20 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree": { "node_modules/@typescript-eslint/typescript-estree": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.23.0.tgz",
"integrity": "sha512-SJX99NAS2ugGOzpyhMza/tX+zDwjvwAtQFLsBo3GQxiGcvaKlqGBkmZ+Y1IdiSi9h4Q0Lr5ey+Cp9CGWNY/F/w==", "integrity": "sha512-LcqzfipsB8RTvH8FX24W4UUFk1bl+0yTOf9ZA08XngFwMg4Kj8A+9hwz8Cr/ZS4KwHrmo9PJiLZkOt49vPnuvQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@typescript-eslint/types": "8.22.0", "@typescript-eslint/types": "8.23.0",
"@typescript-eslint/visitor-keys": "8.22.0", "@typescript-eslint/visitor-keys": "8.23.0",
"debug": "^4.3.4", "debug": "^4.3.4",
"fast-glob": "^3.3.2", "fast-glob": "^3.3.2",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
"minimatch": "^9.0.4", "minimatch": "^9.0.4",
"semver": "^7.6.0", "semver": "^7.6.0",
"ts-api-utils": "^2.0.0" "ts-api-utils": "^2.0.1"
}, },
"engines": { "engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@ -924,9 +924,9 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": {
"version": "7.7.0", "version": "7.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
"integrity": "sha512-DrfFnPzblFmNrIZzg5RzHegbiRWg7KMR7btwi2yjHwx06zsUbO5g613sVwEV7FTwmzJu+Io0lJe2GJ3LxqpvBQ==", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {
@ -937,16 +937,16 @@
} }
}, },
"node_modules/@typescript-eslint/utils": { "node_modules/@typescript-eslint/utils": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.23.0.tgz",
"integrity": "sha512-T8oc1MbF8L+Bk2msAvCUzjxVB2Z2f+vXYfcucE2wOmYs7ZUwco5Ep0fYZw8quNwOiw9K8GYVL+Kgc2pETNTLOg==", "integrity": "sha512-uB/+PSo6Exu02b5ZEiVtmY6RVYO7YU5xqgzTIVZwTHvvK3HsL8tZZHFaTLFtRG3CsV4A5mhOv+NZx5BlhXPyIA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@eslint-community/eslint-utils": "^4.4.0", "@eslint-community/eslint-utils": "^4.4.0",
"@typescript-eslint/scope-manager": "8.22.0", "@typescript-eslint/scope-manager": "8.23.0",
"@typescript-eslint/types": "8.22.0", "@typescript-eslint/types": "8.23.0",
"@typescript-eslint/typescript-estree": "8.22.0" "@typescript-eslint/typescript-estree": "8.23.0"
}, },
"engines": { "engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@ -961,13 +961,13 @@
} }
}, },
"node_modules/@typescript-eslint/visitor-keys": { "node_modules/@typescript-eslint/visitor-keys": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.22.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.23.0.tgz",
"integrity": "sha512-AWpYAXnUgvLNabGTy3uBylkgZoosva/miNd1I8Bz3SjotmQPbVqhO4Cczo8AsZ44XVErEBPr/CRSgaj8sG7g0w==", "integrity": "sha512-oWWhcWDLwDfu++BGTZcmXWqpwtkwb5o7fxUIGksMQQDSdPW9prsSnfIOZMlsj4vBOSrcnjIUZMiIjODgGosFhQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@typescript-eslint/types": "8.22.0", "@typescript-eslint/types": "8.23.0",
"eslint-visitor-keys": "^4.2.0" "eslint-visitor-keys": "^4.2.0"
}, },
"engines": { "engines": {
@ -3119,10 +3119,11 @@
} }
}, },
"node_modules/prettier": { "node_modules/prettier": {
"version": "3.4.2", "version": "3.5.0",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.0.tgz",
"integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "integrity": "sha512-quyMrVt6svPS7CjQ9gKb3GLEX/rl3BCL2oa/QkNcXv4YNVBC9olt3s+H7ukto06q7B1Qz46PbrKLO34PR6vXcA==",
"dev": true, "dev": true,
"license": "MIT",
"bin": { "bin": {
"prettier": "bin/prettier.cjs" "prettier": "bin/prettier.cjs"
}, },
@ -3547,10 +3548,11 @@
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
}, },
"node_modules/ts-api-utils": { "node_modules/ts-api-utils": {
"version": "2.0.0", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.0.1.tgz",
"integrity": "sha512-xCt/TOAc+EOHS1XPnijD3/yzpH6qg2xppZO1YDqGoVsNXfQfzHpOdNuXwrwOU8u4ITXJyDCTyt8w5g1sZv9ynQ==", "integrity": "sha512-dnlgjFSVetynI8nzgJ+qF62efpglpWRk8isUEWZGWlJYySCTD6aKvbUDu+zbPeDakk3bg5H4XpitHukgfL1m9w==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=18.12" "node": ">=18.12"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "golanci-lint-action", "name": "golanci-lint-action",
"version": "3.1.0", "version": "6.3.2",
"private": true, "private": true,
"description": "golangci-lint github action", "description": "golangci-lint github action",
"main": "dist/main.js", "main": "dist/main.js",
@ -30,7 +30,7 @@
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/http-client": "^2.2.3", "@actions/http-client": "^2.2.3",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^2.0.2",
"@types/node": "^22.13.0", "@types/node": "^22.13.1",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6", "@types/tmp": "^0.2.6",
"@types/which": "^3.0.4", "@types/which": "^3.0.4",
@ -38,15 +38,15 @@
"which": "^5.0.0" "which": "^5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.22.0", "@typescript-eslint/eslint-plugin": "^8.23.0",
"@typescript-eslint/parser": "^8.22.0", "@typescript-eslint/parser": "^8.23.0",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3", "eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-simple-import-sort": "^12.1.1",
"prettier": "^3.4.2", "prettier": "^3.5.0",
"typescript": "^5.7.3" "typescript": "^5.7.3"
} }
} }

View File

@ -5,14 +5,13 @@ import os from "os"
import path from "path" import path from "path"
import { promisify } from "util" import { promisify } from "util"
import { VersionConfig } from "./version" import { VersionInfo } from "./version"
const execShellCommand = promisify(exec) const execShellCommand = promisify(exec)
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download" const getAssetURL = (versionInfo: VersionInfo): string => {
const getAssetURL = (versionConfig: VersionConfig): string => {
let ext = "tar.gz" let ext = "tar.gz"
let platform = os.platform().toString() let platform = os.platform().toString()
switch (platform) { switch (platform) {
case "win32": case "win32":
@ -20,6 +19,7 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
ext = "zip" ext = "zip"
break break
} }
let arch = os.arch() let arch = os.arch()
switch (arch) { switch (arch) {
case "arm64": case "arm64":
@ -33,9 +33,10 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
arch = "386" arch = "386"
break 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 { export enum InstallMode {
@ -61,31 +62,31 @@ const printOutput = (res: ExecRes): void => {
/** /**
* Install golangci-lint. * Install golangci-lint.
* *
* @param versionConfig information about version to install. * @param versionInfo information about version to install.
* @param mode installation mode. * @param mode installation mode.
* @returns path to installed binary of golangci-lint. * @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}`) core.info(`Installation mode: ${mode}`)
switch (mode) { switch (mode) {
case InstallMode.Binary: case InstallMode.Binary:
return installBin(versionConfig) return installBin(versionInfo)
case InstallMode.GoInstall: case InstallMode.GoInstall:
return goInstall(versionConfig) return goInstall(versionInfo)
default: default:
return installBin(versionConfig) return installBin(versionInfo)
} }
} }
/** /**
* Install golangci-lint via `go install`. * 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. * @returns path to installed binary of golangci-lint.
*/ */
export async function goInstall(versionConfig: VersionConfig): Promise<string> { export async function goInstall(versionInfo: VersionInfo): Promise<string> {
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`) core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`)
const startedAt = Date.now() const startedAt = Date.now()
@ -93,43 +94,43 @@ export async function goInstall(versionConfig: VersionConfig): Promise<string> {
// TODO(ldez): it should be updated for v2. // TODO(ldez): it should be updated for v2.
const exres = await execShellCommand( 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 options
) )
printOutput(exres) printOutput(exres)
// TODO(ldez): it should be updated for v2. // TODO(ldez): it should be updated for v2.
const res = await execShellCommand( 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 options
) )
printOutput(res) printOutput(res)
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`. // The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
const lintPath = res.stderr const binPath = res.stderr
.split(/\r?\n/) .split(/\r?\n/)
.map((v) => v.trimStart().trimEnd()) .map((v) => v.trimStart().trimEnd())
.filter((v) => v.startsWith("touch ")) .filter((v) => v.startsWith("touch "))
.reduce((a, b) => a + b, "") .reduce((a, b) => a + b, "")
.split(` `, 2)[1] .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. * 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. * @returns path to installed binary of golangci-lint.
*/ */
export async function installBin(versionConfig: VersionConfig): Promise<string> { export async function installBin(versionInfo: VersionInfo): Promise<string> {
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`) core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`)
const startedAt = Date.now() const startedAt = Date.now()
const assetURL = getAssetURL(versionConfig) const assetURL = getAssetURL(versionInfo)
core.info(`Downloading binary ${assetURL} ...`) core.info(`Downloading binary ${assetURL} ...`)
@ -151,9 +152,9 @@ export async function installBin(versionConfig: VersionConfig): Promise<string>
const urlParts = assetURL.split(`/`) const urlParts = assetURL.split(`/`)
const dirName = urlParts[urlParts.length - 1].replace(repl, ``) 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 { restoreCache, saveCache } from "./cache"
import { installLint, InstallMode } from "./install" import { installLint, InstallMode } from "./install"
import { alterDiffPatch } from "./utils/diffUtils" import { alterDiffPatch } from "./utils/diffUtils"
import { findLintVersion } from "./version" import { getVersion } from "./version"
const execShellCommand = promisify(exec) const execShellCommand = promisify(exec)
const writeFile = promisify(fs.writeFile) const writeFile = promisify(fs.writeFile)
@ -25,16 +25,16 @@ async function prepareLint(): Promise<string> {
const mode = core.getInput("install-mode").toLowerCase() const mode = core.getInput("install-mode").toLowerCase()
if (mode === InstallMode.None) { if (mode === InstallMode.None) {
const bin = await which("golangci-lint", { nothrow: true }) const binPath = await which("golangci-lint", { nothrow: true })
if (!bin) { if (!binPath) {
throw new Error("golangci-lint binary not found in the PATH") 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> { async function fetchPatch(): Promise<string> {
@ -141,7 +141,7 @@ async function fetchPushPatch(ctx: Context): Promise<string> {
} }
type Env = { type Env = {
lintPath: string binPath: string
patchPath: string patchPath: string
} }
@ -151,12 +151,12 @@ async function prepareEnv(): Promise<Env> {
// Prepare cache, lint and go in parallel. // Prepare cache, lint and go in parallel.
await restoreCache() await restoreCache()
const lintPath = await prepareLint() const binPath = await prepareLint()
const patchPath = await fetchPatch() const patchPath = await fetchPatch()
core.info(`Prepared env in ${Date.now() - startedAt}ms`) core.info(`Prepared env in ${Date.now() - startedAt}ms`)
return { lintPath, patchPath } return { binPath, patchPath }
} }
type ExecRes = { type ExecRes = {
@ -173,10 +173,10 @@ const printOutput = (res: ExecRes): void => {
} }
} }
async function runLint(lintPath: string, patchPath: string): Promise<void> { async function runLint(binPath: string, patchPath: string): Promise<void> {
const debug = core.getInput(`debug`) const debug = core.getInput(`debug`)
if (debug.split(`,`).includes(`cache`)) { if (debug.split(`,`).includes(`cache`)) {
const res = await execShellCommand(`${lintPath} cache status`) const res = await execShellCommand(`${binPath} cache status`)
printOutput(res) printOutput(res)
} }
@ -266,7 +266,7 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
cmdArgs.cwd = path.resolve(workingDirectory) cmdArgs.cwd = path.resolve(workingDirectory)
} }
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd() const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`) core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
@ -292,9 +292,9 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv) const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
core.addPath(path.dirname(lintPath)) core.addPath(path.dirname(binPath))
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath)) await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
} catch (error) { } catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`) core.error(`Failed to run: ${error}, ${error.stack}`)
core.setFailed(error.message) core.setFailed(error.message)

View File

@ -1,7 +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" import * as fs from "fs"
import os from "os"
import path from "path" import path from "path"
import { InstallMode } from "./install" import { InstallMode } from "./install"
@ -14,6 +13,7 @@ export type Version = {
} | null } | null
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/ 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 modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/
const parseVersion = (s: string): Version => { const parseVersion = (s: string): Version => {
@ -64,8 +64,8 @@ const isLessVersion = (a: Version, b: Version): boolean => {
return a.minor < b.minor return a.minor < b.minor
} }
const getRequestedLintVersion = (): Version => { const getRequestedVersion = (): Version => {
let requestedLintVersion = core.getInput(`version`) let requestedVersion = core.getInput(`version`)
const workingDirectory = core.getInput(`working-directory`) const workingDirectory = core.getInput(`working-directory`)
let goMod = "go.mod" let goMod = "go.mod"
@ -73,44 +73,43 @@ const getRequestedLintVersion = (): Version => {
goMod = path.join(workingDirectory, goMod) goMod = path.join(workingDirectory, goMod)
} }
if (requestedLintVersion == "" && fs.existsSync(goMod)) { if (requestedVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8") const content = fs.readFileSync(goMod, "utf-8")
const match = content.match(modVersionRe) const match = content.match(modVersionRe)
if (match) { if (match) {
requestedLintVersion = match[1] requestedVersion = match[1]
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`) core.info(`Found golangci-lint version '${requestedVersion}' in '${goMod}' file`)
} }
} }
const parsedRequestedLintVersion = parseVersion(requestedLintVersion) const parsedRequestedVersion = parseVersion(requestedVersion)
if (parsedRequestedLintVersion == null) { if (parsedRequestedVersion == null) {
return null return null
} }
if (isLessVersion(parsedRequestedLintVersion, minVersion)) { if (isLessVersion(parsedRequestedVersion, minVersion)) {
throw new Error( 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 minVersion
)} and later versions` )} and later versions`
) )
} }
return parsedRequestedLintVersion return parsedRequestedVersion
} }
export type VersionConfig = { export type VersionInfo = {
Error?: string Error?: string
TargetVersion: string TargetVersion: string
AssetURL: string
} }
type Config = { type VersionMapping = {
MinorVersionToConfig: { 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`, [], { const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], {
allowRetries: true, allowRetries: true,
maxRetries: 5, maxRetries: 5,
@ -130,55 +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...`) core.info(`Finding needed golangci-lint version...`)
if (mode == InstallMode.GoInstall) { if (mode == InstallMode.GoInstall) {
const v: string = core.getInput(`version`) const v: string = core.getInput(`version`)
// TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0). // TODO(ldez): latest should be replaced with an explicit version (ex: v1.64.0).
// TODO(ldez): AssetURL should be updated for v2. return { TargetVersion: v ? v : "latest" }
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" }
} }
const reqLintVersion = getRequestedLintVersion() const reqVersion = getRequestedVersion()
// if the patched version is passed, just use it // 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) => { return new Promise((resolve) => {
let arch: string = "amd64" const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`
if (os.arch() === "arm64") { resolve({ TargetVersion: `v${versionWithoutV}` })
arch = "arm64"
}
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-${arch}.tar.gz`,
})
}) })
} }
const startedAt = Date.now() const startedAt = Date.now()
const config = await getConfig() const mapping = await fetchVersionMapping()
if (!config.MinorVersionToConfig) { if (!mapping.MinorVersionToConfig) {
core.warning(JSON.stringify(config)) core.warning(JSON.stringify(mapping))
throw new Error(`invalid config: no MinorVersionToConfig field`) throw new Error(`invalid config: no MinorVersionToConfig field`)
} }
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)] const versionInfo = mapping.MinorVersionToConfig[stringifyVersion(reqVersion)]
if (!versionConfig) { if (!versionInfo) {
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`) throw new Error(`requested golangci-lint version '${stringifyVersion(reqVersion)}' doesn't exist`)
} }
if (versionConfig.Error) { if (versionInfo.Error) {
throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqLintVersion)}': ${versionConfig.Error}`) throw new Error(`failed to use requested golangci-lint version '${stringifyVersion(reqVersion)}': ${versionInfo.Error}`)
} }
core.info( 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 Date.now() - startedAt
}ms` }ms`
) )
return versionConfig return versionInfo
} }