diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 811715bf90..e77a41cfff 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -93689,8 +93689,7 @@ const os_1 = __importDefault(__nccwpck_require__(857)); const path_1 = __importDefault(__nccwpck_require__(6928)); const util_1 = __nccwpck_require__(9023); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); -const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"; -const getAssetURL = (versionConfig) => { +const getAssetURL = (versionInfo) => { let ext = "tar.gz"; let platform = os_1.default.platform().toString(); switch (platform) { @@ -93712,8 +93711,8 @@ const getAssetURL = (versionConfig) => { 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}`; }; var InstallMode; (function (InstallMode) { @@ -93732,57 +93731,57 @@ const printOutput = (res) => { /** * 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. */ -async function installLint(versionConfig, mode) { +async function installLint(versionInfo, mode) { 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. */ -async function goInstall(versionConfig) { - core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`); +async function goInstall(versionInfo) { + core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`); const startedAt = Date.now(); const options = { 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}`, options); + const exres = await execShellCommand(`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}`, options); + const res = await execShellCommand(`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 `. - const lintPath = res.stderr + 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`); - return lintPath; + core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`); + 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. */ -async function installBin(versionConfig) { - core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`); +async function installBin(versionInfo) { + 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} ...`); const archivePath = await tc.downloadTool(assetURL); let extractedDir = ""; @@ -93801,9 +93800,9 @@ async function installBin(versionConfig) { } const urlParts = assetURL.split(`/`); const dirName = urlParts[urlParts.length - 1].replace(repl, ``); - const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); - core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`); - return lintPath; + const binPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); + core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`); + return binPath; } @@ -93874,14 +93873,14 @@ function isOnlyNewIssues() { async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); if (mode === install_1.InstallMode.None) { - const bin = await (0, which_1.default)("golangci-lint", { nothrow: true }); - if (!bin) { + const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true }); + if (!binPath) { throw new Error("golangci-lint binary not found in the PATH"); } - return bin; + return binPath; } - const versionConfig = await (0, version_1.findLintVersion)(mode); - return await (0, install_1.installLint)(versionConfig, mode); + const versionInfo = await (0, version_1.getVersion)(mode); + return await (0, install_1.installLint)(versionInfo, mode); } async function fetchPatch() { if (!isOnlyNewIssues()) { @@ -93980,10 +93979,10 @@ async function prepareEnv() { const startedAt = Date.now(); // Prepare cache, lint and go in parallel. await (0, cache_1.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 }; } const printOutput = (res) => { if (res.stdout) { @@ -94092,9 +94091,9 @@ async function runLint(lintPath, patchPath) { } async function run() { 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}`); @@ -94320,14 +94319,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.stringifyVersion = void 0; -exports.findLintVersion = findLintVersion; +exports.getVersion = getVersion; const core = __importStar(__nccwpck_require__(7484)); const httpm = __importStar(__nccwpck_require__(4844)); const fs = __importStar(__nccwpck_require__(9896)); -const os_1 = __importDefault(__nccwpck_require__(857)); const path_1 = __importDefault(__nccwpck_require__(6928)); const install_1 = __nccwpck_require__(232); 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) => { 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 return a.minor < b.minor; }; -const getRequestedLintVersion = () => { - let requestedLintVersion = core.getInput(`version`); +const getRequestedVersion = () => { + let requestedVersion = core.getInput(`version`); const workingDirectory = core.getInput(`working-directory`); let goMod = "go.mod"; if (workingDirectory) { 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 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)) { - throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${(0, exports.stringifyVersion)(minVersion)} and later versions`); + if (isLessVersion(parsedRequestedVersion, minVersion)) { + 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`, [], { allowRetries: true, maxRetries: 5, @@ -94414,44 +94413,37 @@ const getConfig = async () => { 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...`); if (mode == install_1.InstallMode.GoInstall) { const v = core.getInput(`version`); // 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", AssetURL: "github.com/golangci/golangci-lint" }; + 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) => { - let arch = "amd64"; - if (os_1.default.arch() === "arm64") { - 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 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[(0, exports.stringifyVersion)(reqLintVersion)]; - if (!versionConfig) { - throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}' doesn't exist`); + const versionInfo = mapping.MinorVersionToConfig[(0, exports.stringifyVersion)(reqVersion)]; + if (!versionInfo) { + throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}' doesn't exist`); } - if (versionConfig.Error) { - throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}': ${versionConfig.Error}`); + if (versionInfo.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`); - return versionConfig; + core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${Date.now() - startedAt}ms`); + return versionInfo; } diff --git a/dist/run/index.js b/dist/run/index.js index c0b48f8b9d..e32f5883d5 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -93689,8 +93689,7 @@ const os_1 = __importDefault(__nccwpck_require__(857)); const path_1 = __importDefault(__nccwpck_require__(6928)); const util_1 = __nccwpck_require__(9023); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); -const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"; -const getAssetURL = (versionConfig) => { +const getAssetURL = (versionInfo) => { let ext = "tar.gz"; let platform = os_1.default.platform().toString(); switch (platform) { @@ -93712,8 +93711,8 @@ const getAssetURL = (versionConfig) => { 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}`; }; var InstallMode; (function (InstallMode) { @@ -93732,57 +93731,57 @@ const printOutput = (res) => { /** * 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. */ -async function installLint(versionConfig, mode) { +async function installLint(versionInfo, mode) { 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. */ -async function goInstall(versionConfig) { - core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`); +async function goInstall(versionInfo) { + core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`); const startedAt = Date.now(); const options = { 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}`, options); + const exres = await execShellCommand(`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}`, options); + const res = await execShellCommand(`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 `. - const lintPath = res.stderr + 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`); - return lintPath; + core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`); + 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. */ -async function installBin(versionConfig) { - core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`); +async function installBin(versionInfo) { + 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} ...`); const archivePath = await tc.downloadTool(assetURL); let extractedDir = ""; @@ -93801,9 +93800,9 @@ async function installBin(versionConfig) { } const urlParts = assetURL.split(`/`); const dirName = urlParts[urlParts.length - 1].replace(repl, ``); - const lintPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); - core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`); - return lintPath; + const binPath = path_1.default.join(extractedDir, dirName, `golangci-lint`); + core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`); + return binPath; } @@ -93874,14 +93873,14 @@ function isOnlyNewIssues() { async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); if (mode === install_1.InstallMode.None) { - const bin = await (0, which_1.default)("golangci-lint", { nothrow: true }); - if (!bin) { + const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true }); + if (!binPath) { throw new Error("golangci-lint binary not found in the PATH"); } - return bin; + return binPath; } - const versionConfig = await (0, version_1.findLintVersion)(mode); - return await (0, install_1.installLint)(versionConfig, mode); + const versionInfo = await (0, version_1.getVersion)(mode); + return await (0, install_1.installLint)(versionInfo, mode); } async function fetchPatch() { if (!isOnlyNewIssues()) { @@ -93980,10 +93979,10 @@ async function prepareEnv() { const startedAt = Date.now(); // Prepare cache, lint and go in parallel. await (0, cache_1.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 }; } const printOutput = (res) => { if (res.stdout) { @@ -94092,9 +94091,9 @@ async function runLint(lintPath, patchPath) { } async function run() { 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}`); @@ -94320,14 +94319,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.stringifyVersion = void 0; -exports.findLintVersion = findLintVersion; +exports.getVersion = getVersion; const core = __importStar(__nccwpck_require__(7484)); const httpm = __importStar(__nccwpck_require__(4844)); const fs = __importStar(__nccwpck_require__(9896)); -const os_1 = __importDefault(__nccwpck_require__(857)); const path_1 = __importDefault(__nccwpck_require__(6928)); const install_1 = __nccwpck_require__(232); 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) => { 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 return a.minor < b.minor; }; -const getRequestedLintVersion = () => { - let requestedLintVersion = core.getInput(`version`); +const getRequestedVersion = () => { + let requestedVersion = core.getInput(`version`); const workingDirectory = core.getInput(`working-directory`); let goMod = "go.mod"; if (workingDirectory) { 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 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)) { - throw new Error(`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${(0, exports.stringifyVersion)(minVersion)} and later versions`); + if (isLessVersion(parsedRequestedVersion, minVersion)) { + 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`, [], { allowRetries: true, maxRetries: 5, @@ -94414,44 +94413,37 @@ const getConfig = async () => { 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...`); if (mode == install_1.InstallMode.GoInstall) { const v = core.getInput(`version`); // 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", AssetURL: "github.com/golangci/golangci-lint" }; + 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) => { - let arch = "amd64"; - if (os_1.default.arch() === "arm64") { - 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 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[(0, exports.stringifyVersion)(reqLintVersion)]; - if (!versionConfig) { - throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}' doesn't exist`); + const versionInfo = mapping.MinorVersionToConfig[(0, exports.stringifyVersion)(reqVersion)]; + if (!versionInfo) { + throw new Error(`requested golangci-lint version '${(0, exports.stringifyVersion)(reqVersion)}' doesn't exist`); } - if (versionConfig.Error) { - throw new Error(`failed to use requested golangci-lint version '${(0, exports.stringifyVersion)(reqLintVersion)}': ${versionConfig.Error}`); + if (versionInfo.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`); - return versionConfig; + core.info(`Requested golangci-lint '${(0, exports.stringifyVersion)(reqVersion)}', using '${versionInfo.TargetVersion}', calculation took ${Date.now() - startedAt}ms`); + return versionInfo; } diff --git a/package-lock.json b/package-lock.json index e36768b02e..aa6ac06f35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "golanci-lint-action", - "version": "3.1.0", + "version": "6.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "golanci-lint-action", - "version": "3.1.0", + "version": "6.3.0", "license": "MIT", "dependencies": { "@actions/cache": "^4.0.0", diff --git a/package.json b/package.json index 678f78b09c..d6dcd8e2bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "golanci-lint-action", - "version": "3.1.0", + "version": "6.3.0", "private": true, "description": "golangci-lint github action", "main": "dist/main.js", diff --git a/src/install.ts b/src/install.ts index 22935082e5..75cb75af77 100644 --- a/src/install.ts +++ b/src/install.ts @@ -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,6 +19,7 @@ const getAssetURL = (versionConfig: VersionConfig): string => { ext = "zip" break } + let arch = os.arch() switch (arch) { case "arm64": @@ -33,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 { @@ -61,31 +62,31 @@ 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 { +export async function installLint(versionInfo: VersionInfo, mode: InstallMode): Promise { 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 { - core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`) +export async function goInstall(versionInfo: VersionInfo): Promise { + core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`) const startedAt = Date.now() @@ -93,43 +94,43 @@ export async function goInstall(versionConfig: VersionConfig): Promise { // 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 `. - const lintPath = res.stderr + 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 { - core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`) +export async function installBin(versionInfo: VersionInfo): Promise { + 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} ...`) @@ -151,9 +152,9 @@ export async function installBin(versionConfig: VersionConfig): Promise 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 } diff --git a/src/run.ts b/src/run.ts index b60ed9bf88..fb39467b2f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -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 { 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(mode) + const versionInfo = await getVersion(mode) - return await installLint(versionConfig, mode) + return await installLint(versionInfo, mode) } async function fetchPatch(): Promise { @@ -141,7 +141,7 @@ async function fetchPushPatch(ctx: Context): Promise { } type Env = { - lintPath: string + binPath: string patchPath: string } @@ -151,12 +151,12 @@ async function prepareEnv(): Promise { // 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 { export async function run(): Promise { 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) diff --git a/src/version.ts b/src/version.ts index 03e1a6d8bf..ceaf685190 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,7 +1,6 @@ import * as core from "@actions/core" import * as httpm from "@actions/http-client" import * as fs from "fs" -import os from "os" import path from "path" import { InstallMode } from "./install" @@ -14,6 +13,7 @@ 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 => { @@ -64,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" @@ -73,44 +73,43 @@ 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 => { +const fetchVersionMapping = async (): Promise => { const http = new httpm.HttpClient(`golangci/golangci-lint-action`, [], { allowRetries: true, maxRetries: 5, @@ -130,55 +129,48 @@ const getConfig = async (): Promise => { } } -export async function findLintVersion(mode: InstallMode): Promise { +export async function getVersion(mode: InstallMode): Promise { core.info(`Finding needed golangci-lint version...`) if (mode == InstallMode.GoInstall) { const v: string = core.getInput(`version`) // 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", AssetURL: "github.com/golangci/golangci-lint" } + 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) => { - let arch: string = "amd64" - if (os.arch() === "arm64") { - 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 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 }