@@ -66370,11 +66370,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
66370
66370
return (mod && mod.__esModule) ? mod : { "default": mod };
66371
66371
};
66372
66372
Object.defineProperty(exports, "__esModule", ({ value: true }));
66373
- exports.installLint = void 0;
66373
+ exports.installBin = exports.goInstall = exports. installLint = exports.InstallMode = void 0;
66374
66374
const core = __importStar(__nccwpck_require__(2186));
66375
66375
const tc = __importStar(__nccwpck_require__(7784));
66376
+ const child_process_1 = __nccwpck_require__(2081);
66376
66377
const os_1 = __importDefault(__nccwpck_require__(2037));
66377
66378
const path_1 = __importDefault(__nccwpck_require__(1017));
66379
+ const util_1 = __nccwpck_require__(3837);
66380
+ const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
66378
66381
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
66379
66382
const getAssetURL = (versionConfig) => {
66380
66383
let ext = "tar.gz";
@@ -66398,13 +66401,74 @@ const getAssetURL = (versionConfig) => {
66398
66401
const noPrefix = versionConfig.TargetVersion.slice(1);
66399
66402
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
66400
66403
};
66401
- // The installLint returns path to installed binary of golangci-lint.
66402
- function installLint(versionConfig) {
66404
+ var InstallMode;
66405
+ (function (InstallMode) {
66406
+ InstallMode["Binary"] = "binary";
66407
+ InstallMode["GoInstall"] = "goinstall";
66408
+ })(InstallMode = exports.InstallMode || (exports.InstallMode = {}));
66409
+ const printOutput = (res) => {
66410
+ if (res.stdout) {
66411
+ core.info(res.stdout);
66412
+ }
66413
+ if (res.stderr) {
66414
+ core.info(res.stderr);
66415
+ }
66416
+ };
66417
+ /**
66418
+ * Install golangci-lint.
66419
+ *
66420
+ * @param versionConfig information about version to install.
66421
+ * @param mode installation mode.
66422
+ * @returns path to installed binary of golangci-lint.
66423
+ */
66424
+ function installLint(versionConfig, mode) {
66425
+ return __awaiter(this, void 0, void 0, function* () {
66426
+ core.info(`Installation mode: ${mode}`);
66427
+ switch (mode) {
66428
+ case InstallMode.Binary:
66429
+ return installBin(versionConfig);
66430
+ case InstallMode.GoInstall:
66431
+ return goInstall(versionConfig);
66432
+ default:
66433
+ return installBin(versionConfig);
66434
+ }
66435
+ });
66436
+ }
66437
+ exports.installLint = installLint;
66438
+ /**
66439
+ * Install golangci-lint via `go install`.
66440
+ *
66441
+ * @param versionConfig information about version to install.
66442
+ * @returns path to installed binary of golangci-lint.
66443
+ */
66444
+ function goInstall(versionConfig) {
66403
66445
return __awaiter(this, void 0, void 0, function* () {
66404
66446
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
66405
66447
const startedAt = Date.now();
66448
+ const options = { env: Object.assign(Object.assign({}, process.env), { CGO_ENABLED: "1" }) };
66449
+ const exres = yield execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
66450
+ printOutput(exres);
66451
+ const res = yield execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
66452
+ printOutput(res);
66453
+ // The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
66454
+ const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1];
66455
+ core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`);
66456
+ return lintPath;
66457
+ });
66458
+ }
66459
+ exports.goInstall = goInstall;
66460
+ /**
66461
+ * Install golangci-lint via the precompiled binary.
66462
+ *
66463
+ * @param versionConfig information about version to install.
66464
+ * @returns path to installed binary of golangci-lint.
66465
+ */
66466
+ function installBin(versionConfig) {
66467
+ return __awaiter(this, void 0, void 0, function* () {
66468
+ core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`);
66469
+ const startedAt = Date.now();
66406
66470
const assetURL = getAssetURL(versionConfig);
66407
- core.info(`Downloading ${assetURL} ...`);
66471
+ core.info(`Downloading binary ${assetURL} ...`);
66408
66472
const archivePath = yield tc.downloadTool(assetURL);
66409
66473
let extractedDir = "";
66410
66474
let repl = /\.tar\.gz$/;
@@ -66427,7 +66491,7 @@ function installLint(versionConfig) {
66427
66491
return lintPath;
66428
66492
});
66429
66493
}
66430
- exports.installLint = installLint ;
66494
+ exports.installBin = installBin ;
66431
66495
66432
66496
66433
66497
/***/ }),
@@ -66486,8 +66550,9 @@ const writeFile = (0, util_1.promisify)(fs.writeFile);
66486
66550
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
66487
66551
function prepareLint() {
66488
66552
return __awaiter(this, void 0, void 0, function* () {
66489
- const versionConfig = yield (0, version_1.findLintVersion)();
66490
- return yield (0, install_1.installLint)(versionConfig);
66553
+ const mode = core.getInput("install-mode").toLowerCase();
66554
+ const versionConfig = yield (0, version_1.findLintVersion)(mode);
66555
+ return yield (0, install_1.installLint)(versionConfig, mode);
66491
66556
});
66492
66557
}
66493
66558
function fetchPatch() {
@@ -66548,11 +66613,10 @@ function prepareEnv() {
66548
66613
return __awaiter(this, void 0, void 0, function* () {
66549
66614
const startedAt = Date.now();
66550
66615
// Prepare cache, lint and go in parallel.
66551
- const restoreCachePromise = (0, cache_1.restoreCache)();
66616
+ yield (0, cache_1.restoreCache)();
66552
66617
const prepareLintPromise = prepareLint();
66553
66618
const patchPromise = fetchPatch();
66554
66619
const lintPath = yield prepareLintPromise;
66555
- yield restoreCachePromise;
66556
66620
const patchPath = yield patchPromise;
66557
66621
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
66558
66622
return { lintPath, patchPath };
@@ -66609,7 +66673,7 @@ function runLint(lintPath, patchPath) {
66609
66673
}
66610
66674
cmdArgs.cwd = path.resolve(workingDirectory);
66611
66675
}
66612
- const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimRight ();
66676
+ const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd ();
66613
66677
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`);
66614
66678
const startedAt = Date.now();
66615
66679
try {
@@ -66774,6 +66838,7 @@ const core = __importStar(__nccwpck_require__(2186));
66774
66838
const httpm = __importStar(__nccwpck_require__(6255));
66775
66839
const fs = __importStar(__nccwpck_require__(7147));
66776
66840
const path_1 = __importDefault(__nccwpck_require__(1017));
66841
+ const install_1 = __nccwpck_require__(1649);
66777
66842
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
66778
66843
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
66779
66844
const parseVersion = (s) => {
@@ -66858,9 +66923,13 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
66858
66923
throw new Error(`failed to get action config: ${exc.message}`);
66859
66924
}
66860
66925
});
66861
- function findLintVersion() {
66926
+ function findLintVersion(mode ) {
66862
66927
return __awaiter(this, void 0, void 0, function* () {
66863
66928
core.info(`Finding needed golangci-lint version...`);
66929
+ if (mode == install_1.InstallMode.GoInstall) {
66930
+ const v = core.getInput(`version`);
66931
+ return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" };
66932
+ }
66864
66933
const reqLintVersion = getRequestedLintVersion();
66865
66934
// if the patched version is passed, just use it
66866
66935
if ((reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.major) !== null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.minor) != null && (reqLintVersion === null || reqLintVersion === void 0 ? void 0 : reqLintVersion.patch) !== null) {
0 commit comments