feat: add install-mode (#768)
This commit is contained in:
parent
5be60c708e
commit
185e7a2f8f
29
.github/workflows/test.yml
vendored
29
.github/workflows/test.yml
vendored
@ -69,6 +69,35 @@ jobs:
|
|||||||
args: --timeout=3m --issues-exit-code=0 ./sample/...
|
args: --timeout=3m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
|
||||||
|
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
|
||||||
|
needs: [ build ]
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
|
version:
|
||||||
|
- ""
|
||||||
|
- "latest"
|
||||||
|
- "v1.53.2"
|
||||||
|
- "b5093688c0d3008eaacd6066773a1a52e689252f"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
cache: false # setup-go v4 caches by default
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ matrix.version }}
|
||||||
|
args: --timeout=3m --issues-exit-code=0 ./sample/...
|
||||||
|
only-new-issues: true
|
||||||
|
install-mode: goinstall
|
||||||
|
|
||||||
test-go-mod-version:
|
test-go-mod-version:
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -70,6 +70,9 @@ jobs:
|
|||||||
|
|
||||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||||
# skip-build-cache: true
|
# skip-build-cache: true
|
||||||
|
|
||||||
|
# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
|
||||||
|
# install-mode: "goinstall"
|
||||||
```
|
```
|
||||||
|
|
||||||
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
||||||
@ -124,6 +127,9 @@ jobs:
|
|||||||
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
# only-new-issues: true
|
# only-new-issues: true
|
||||||
|
|
||||||
|
# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
|
||||||
|
# install-mode: "goinstall"
|
||||||
```
|
```
|
||||||
|
|
||||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for windows builds are properly formatted:
|
You will also likely need to add the following `.gitattributes` file to ensure that line endings for windows builds are properly formatted:
|
||||||
|
@ -34,6 +34,10 @@ inputs:
|
|||||||
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
|
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
|
||||||
default: false
|
default: false
|
||||||
required: false
|
required: false
|
||||||
|
install-mode:
|
||||||
|
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
|
||||||
|
default: "binary"
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
main: "dist/run/index.js"
|
main: "dist/run/index.js"
|
||||||
|
91
dist/post_run/index.js
vendored
91
dist/post_run/index.js
vendored
@ -66370,11 +66370,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.installLint = void 0;
|
exports.installBin = exports.goInstall = exports.installLint = exports.InstallMode = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const tc = __importStar(__nccwpck_require__(7784));
|
const tc = __importStar(__nccwpck_require__(7784));
|
||||||
|
const child_process_1 = __nccwpck_require__(2081);
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const util_1 = __nccwpck_require__(3837);
|
||||||
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
|
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
|
||||||
const getAssetURL = (versionConfig) => {
|
const getAssetURL = (versionConfig) => {
|
||||||
let ext = "tar.gz";
|
let ext = "tar.gz";
|
||||||
@ -66398,13 +66401,74 @@ const getAssetURL = (versionConfig) => {
|
|||||||
const noPrefix = versionConfig.TargetVersion.slice(1);
|
const noPrefix = versionConfig.TargetVersion.slice(1);
|
||||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||||
};
|
};
|
||||||
// The installLint returns path to installed binary of golangci-lint.
|
var InstallMode;
|
||||||
function installLint(versionConfig) {
|
(function (InstallMode) {
|
||||||
|
InstallMode["Binary"] = "binary";
|
||||||
|
InstallMode["GoInstall"] = "goinstall";
|
||||||
|
})(InstallMode = exports.InstallMode || (exports.InstallMode = {}));
|
||||||
|
const printOutput = (res) => {
|
||||||
|
if (res.stdout) {
|
||||||
|
core.info(res.stdout);
|
||||||
|
}
|
||||||
|
if (res.stderr) {
|
||||||
|
core.info(res.stderr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @param mode installation mode.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function installLint(versionConfig, mode) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Installation mode: ${mode}`);
|
||||||
|
switch (mode) {
|
||||||
|
case InstallMode.Binary:
|
||||||
|
return installBin(versionConfig);
|
||||||
|
case InstallMode.GoInstall:
|
||||||
|
return goInstall(versionConfig);
|
||||||
|
default:
|
||||||
|
return installBin(versionConfig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.installLint = installLint;
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via `go install`.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function goInstall(versionConfig) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
const options = { env: Object.assign(Object.assign({}, process.env), { CGO_ENABLED: "1" }) };
|
||||||
|
const exres = yield execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
|
||||||
|
printOutput(exres);
|
||||||
|
const res = yield execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
|
||||||
|
printOutput(res);
|
||||||
|
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||||
|
const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1];
|
||||||
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`);
|
||||||
|
return lintPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.goInstall = goInstall;
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via the precompiled binary.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function installBin(versionConfig) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`);
|
||||||
|
const startedAt = Date.now();
|
||||||
const assetURL = getAssetURL(versionConfig);
|
const assetURL = getAssetURL(versionConfig);
|
||||||
core.info(`Downloading ${assetURL} ...`);
|
core.info(`Downloading binary ${assetURL} ...`);
|
||||||
const archivePath = yield tc.downloadTool(assetURL);
|
const archivePath = yield tc.downloadTool(assetURL);
|
||||||
let extractedDir = "";
|
let extractedDir = "";
|
||||||
let repl = /\.tar\.gz$/;
|
let repl = /\.tar\.gz$/;
|
||||||
@ -66427,7 +66491,7 @@ function installLint(versionConfig) {
|
|||||||
return lintPath;
|
return lintPath;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.installLint = installLint;
|
exports.installBin = installBin;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -66486,8 +66550,9 @@ const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|||||||
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
||||||
function prepareLint() {
|
function prepareLint() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const versionConfig = yield (0, version_1.findLintVersion)();
|
const mode = core.getInput("install-mode").toLowerCase();
|
||||||
return yield (0, install_1.installLint)(versionConfig);
|
const versionConfig = yield (0, version_1.findLintVersion)(mode);
|
||||||
|
return yield (0, install_1.installLint)(versionConfig, mode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function fetchPatch() {
|
function fetchPatch() {
|
||||||
@ -66548,11 +66613,10 @@ function prepareEnv() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
const restoreCachePromise = (0, cache_1.restoreCache)();
|
yield (0, cache_1.restoreCache)();
|
||||||
const prepareLintPromise = prepareLint();
|
const prepareLintPromise = prepareLint();
|
||||||
const patchPromise = fetchPatch();
|
const patchPromise = fetchPatch();
|
||||||
const lintPath = yield prepareLintPromise;
|
const lintPath = yield prepareLintPromise;
|
||||||
yield restoreCachePromise;
|
|
||||||
const patchPath = yield patchPromise;
|
const patchPath = yield patchPromise;
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||||
return { lintPath, patchPath };
|
return { lintPath, patchPath };
|
||||||
@ -66609,7 +66673,7 @@ function runLint(lintPath, patchPath) {
|
|||||||
}
|
}
|
||||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||||
}
|
}
|
||||||
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimRight();
|
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`);
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
try {
|
try {
|
||||||
@ -66774,6 +66838,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const httpm = __importStar(__nccwpck_require__(6255));
|
const httpm = __importStar(__nccwpck_require__(6255));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const install_1 = __nccwpck_require__(1649);
|
||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
||||||
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
||||||
const parseVersion = (s) => {
|
const parseVersion = (s) => {
|
||||||
@ -66858,9 +66923,13 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|||||||
throw new Error(`failed to get action config: ${exc.message}`);
|
throw new Error(`failed to get action config: ${exc.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function findLintVersion() {
|
function findLintVersion(mode) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Finding needed golangci-lint version...`);
|
core.info(`Finding needed golangci-lint version...`);
|
||||||
|
if (mode == install_1.InstallMode.GoInstall) {
|
||||||
|
const v = core.getInput(`version`);
|
||||||
|
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" };
|
||||||
|
}
|
||||||
const reqLintVersion = getRequestedLintVersion();
|
const reqLintVersion = getRequestedLintVersion();
|
||||||
// if the patched version is passed, just use it
|
// if the patched version is passed, just use it
|
||||||
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) {
|
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) {
|
||||||
|
91
dist/run/index.js
vendored
91
dist/run/index.js
vendored
@ -66370,11 +66370,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.installLint = void 0;
|
exports.installBin = exports.goInstall = exports.installLint = exports.InstallMode = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const tc = __importStar(__nccwpck_require__(7784));
|
const tc = __importStar(__nccwpck_require__(7784));
|
||||||
|
const child_process_1 = __nccwpck_require__(2081);
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const util_1 = __nccwpck_require__(3837);
|
||||||
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
|
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download";
|
||||||
const getAssetURL = (versionConfig) => {
|
const getAssetURL = (versionConfig) => {
|
||||||
let ext = "tar.gz";
|
let ext = "tar.gz";
|
||||||
@ -66398,13 +66401,74 @@ const getAssetURL = (versionConfig) => {
|
|||||||
const noPrefix = versionConfig.TargetVersion.slice(1);
|
const noPrefix = versionConfig.TargetVersion.slice(1);
|
||||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||||
};
|
};
|
||||||
// The installLint returns path to installed binary of golangci-lint.
|
var InstallMode;
|
||||||
function installLint(versionConfig) {
|
(function (InstallMode) {
|
||||||
|
InstallMode["Binary"] = "binary";
|
||||||
|
InstallMode["GoInstall"] = "goinstall";
|
||||||
|
})(InstallMode = exports.InstallMode || (exports.InstallMode = {}));
|
||||||
|
const printOutput = (res) => {
|
||||||
|
if (res.stdout) {
|
||||||
|
core.info(res.stdout);
|
||||||
|
}
|
||||||
|
if (res.stderr) {
|
||||||
|
core.info(res.stderr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @param mode installation mode.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function installLint(versionConfig, mode) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Installation mode: ${mode}`);
|
||||||
|
switch (mode) {
|
||||||
|
case InstallMode.Binary:
|
||||||
|
return installBin(versionConfig);
|
||||||
|
case InstallMode.GoInstall:
|
||||||
|
return goInstall(versionConfig);
|
||||||
|
default:
|
||||||
|
return installBin(versionConfig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.installLint = installLint;
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via `go install`.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function goInstall(versionConfig) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
const options = { env: Object.assign(Object.assign({}, process.env), { CGO_ENABLED: "1" }) };
|
||||||
|
const exres = yield execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
|
||||||
|
printOutput(exres);
|
||||||
|
const res = yield execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`, options);
|
||||||
|
printOutput(res);
|
||||||
|
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||||
|
const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1];
|
||||||
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`);
|
||||||
|
return lintPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.goInstall = goInstall;
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via the precompiled binary.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
function installBin(versionConfig) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`);
|
||||||
|
const startedAt = Date.now();
|
||||||
const assetURL = getAssetURL(versionConfig);
|
const assetURL = getAssetURL(versionConfig);
|
||||||
core.info(`Downloading ${assetURL} ...`);
|
core.info(`Downloading binary ${assetURL} ...`);
|
||||||
const archivePath = yield tc.downloadTool(assetURL);
|
const archivePath = yield tc.downloadTool(assetURL);
|
||||||
let extractedDir = "";
|
let extractedDir = "";
|
||||||
let repl = /\.tar\.gz$/;
|
let repl = /\.tar\.gz$/;
|
||||||
@ -66427,7 +66491,7 @@ function installLint(versionConfig) {
|
|||||||
return lintPath;
|
return lintPath;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.installLint = installLint;
|
exports.installBin = installBin;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -66486,8 +66550,9 @@ const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|||||||
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
||||||
function prepareLint() {
|
function prepareLint() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const versionConfig = yield (0, version_1.findLintVersion)();
|
const mode = core.getInput("install-mode").toLowerCase();
|
||||||
return yield (0, install_1.installLint)(versionConfig);
|
const versionConfig = yield (0, version_1.findLintVersion)(mode);
|
||||||
|
return yield (0, install_1.installLint)(versionConfig, mode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function fetchPatch() {
|
function fetchPatch() {
|
||||||
@ -66548,11 +66613,10 @@ function prepareEnv() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
const restoreCachePromise = (0, cache_1.restoreCache)();
|
yield (0, cache_1.restoreCache)();
|
||||||
const prepareLintPromise = prepareLint();
|
const prepareLintPromise = prepareLint();
|
||||||
const patchPromise = fetchPatch();
|
const patchPromise = fetchPatch();
|
||||||
const lintPath = yield prepareLintPromise;
|
const lintPath = yield prepareLintPromise;
|
||||||
yield restoreCachePromise;
|
|
||||||
const patchPath = yield patchPromise;
|
const patchPath = yield patchPromise;
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||||
return { lintPath, patchPath };
|
return { lintPath, patchPath };
|
||||||
@ -66609,7 +66673,7 @@ function runLint(lintPath, patchPath) {
|
|||||||
}
|
}
|
||||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||||
}
|
}
|
||||||
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimRight();
|
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`);
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
try {
|
try {
|
||||||
@ -66774,6 +66838,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const httpm = __importStar(__nccwpck_require__(6255));
|
const httpm = __importStar(__nccwpck_require__(6255));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const install_1 = __nccwpck_require__(1649);
|
||||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
||||||
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
||||||
const parseVersion = (s) => {
|
const parseVersion = (s) => {
|
||||||
@ -66858,9 +66923,13 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|||||||
throw new Error(`failed to get action config: ${exc.message}`);
|
throw new Error(`failed to get action config: ${exc.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function findLintVersion() {
|
function findLintVersion(mode) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Finding needed golangci-lint version...`);
|
core.info(`Finding needed golangci-lint version...`);
|
||||||
|
if (mode == install_1.InstallMode.GoInstall) {
|
||||||
|
const v = core.getInput(`version`);
|
||||||
|
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" };
|
||||||
|
}
|
||||||
const reqLintVersion = getRequestedLintVersion();
|
const reqLintVersion = getRequestedLintVersion();
|
||||||
// if the patched version is passed, just use it
|
// if the patched version is passed, just use it
|
||||||
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) {
|
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) {
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as tc from "@actions/tool-cache"
|
import * as tc from "@actions/tool-cache"
|
||||||
|
import { exec, ExecOptions } from "child_process"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { promisify } from "util"
|
||||||
|
|
||||||
import { VersionConfig } from "./version"
|
import { VersionConfig } from "./version"
|
||||||
|
|
||||||
|
const execShellCommand = promisify(exec)
|
||||||
|
|
||||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
||||||
|
|
||||||
const getAssetURL = (versionConfig: VersionConfig): string => {
|
const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||||
@ -31,13 +35,95 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
|
|||||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// The installLint returns path to installed binary of golangci-lint.
|
export enum InstallMode {
|
||||||
export async function installLint(versionConfig: VersionConfig): Promise<string> {
|
Binary = "binary",
|
||||||
|
GoInstall = "goinstall",
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExecRes = {
|
||||||
|
stdout: string
|
||||||
|
stderr: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const printOutput = (res: ExecRes): void => {
|
||||||
|
if (res.stdout) {
|
||||||
|
core.info(res.stdout)
|
||||||
|
}
|
||||||
|
if (res.stderr) {
|
||||||
|
core.info(res.stderr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @param mode installation mode.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function installLint(versionConfig: VersionConfig, mode: InstallMode): Promise<string> {
|
||||||
|
core.info(`Installation mode: ${mode}`)
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case InstallMode.Binary:
|
||||||
|
return installBin(versionConfig)
|
||||||
|
case InstallMode.GoInstall:
|
||||||
|
return goInstall(versionConfig)
|
||||||
|
default:
|
||||||
|
return installBin(versionConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via `go install`.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function goInstall(versionConfig: VersionConfig): Promise<string> {
|
||||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
|
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
|
const options: ExecOptions = { env: { ...process.env, CGO_ENABLED: "1" } }
|
||||||
|
|
||||||
|
const exres = await execShellCommand(
|
||||||
|
`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
printOutput(exres)
|
||||||
|
|
||||||
|
const res = await execShellCommand(
|
||||||
|
`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
printOutput(res)
|
||||||
|
|
||||||
|
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||||
|
const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1]
|
||||||
|
|
||||||
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
|
return lintPath
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via the precompiled binary.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function installBin(versionConfig: VersionConfig): Promise<string> {
|
||||||
|
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`)
|
||||||
|
|
||||||
|
const startedAt = Date.now()
|
||||||
|
|
||||||
const assetURL = getAssetURL(versionConfig)
|
const assetURL = getAssetURL(versionConfig)
|
||||||
core.info(`Downloading ${assetURL} ...`)
|
|
||||||
|
core.info(`Downloading binary ${assetURL} ...`)
|
||||||
|
|
||||||
const archivePath = await tc.downloadTool(assetURL)
|
const archivePath = await tc.downloadTool(assetURL)
|
||||||
|
|
||||||
let extractedDir = ""
|
let extractedDir = ""
|
||||||
let repl = /\.tar\.gz$/
|
let repl = /\.tar\.gz$/
|
||||||
if (assetURL.endsWith("zip")) {
|
if (assetURL.endsWith("zip")) {
|
||||||
@ -55,6 +141,8 @@ export async function installLint(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 lintPath = path.join(extractedDir, dirName, `golangci-lint`)
|
||||||
|
|
||||||
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
return lintPath
|
return lintPath
|
||||||
}
|
}
|
||||||
|
16
src/run.ts
16
src/run.ts
@ -7,7 +7,7 @@ import { dir } from "tmp"
|
|||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
|
|
||||||
import { restoreCache, saveCache } from "./cache"
|
import { restoreCache, saveCache } from "./cache"
|
||||||
import { installLint } from "./install"
|
import { installLint, InstallMode } from "./install"
|
||||||
import { findLintVersion } from "./version"
|
import { findLintVersion } from "./version"
|
||||||
|
|
||||||
const execShellCommand = promisify(exec)
|
const execShellCommand = promisify(exec)
|
||||||
@ -15,8 +15,10 @@ const writeFile = promisify(fs.writeFile)
|
|||||||
const createTempDir = promisify(dir)
|
const createTempDir = promisify(dir)
|
||||||
|
|
||||||
async function prepareLint(): Promise<string> {
|
async function prepareLint(): Promise<string> {
|
||||||
const versionConfig = await findLintVersion()
|
const mode = core.getInput("install-mode").toLowerCase()
|
||||||
return await installLint(versionConfig)
|
const versionConfig = await findLintVersion(<InstallMode>mode)
|
||||||
|
|
||||||
|
return await installLint(versionConfig, <InstallMode>mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchPatch(): Promise<string> {
|
async function fetchPatch(): Promise<string> {
|
||||||
@ -83,15 +85,15 @@ async function prepareEnv(): Promise<Env> {
|
|||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
const restoreCachePromise = restoreCache()
|
await restoreCache()
|
||||||
const prepareLintPromise = prepareLint()
|
const prepareLintPromise = prepareLint()
|
||||||
const patchPromise = fetchPatch()
|
const patchPromise = fetchPatch()
|
||||||
|
|
||||||
const lintPath = await prepareLintPromise
|
const lintPath = await prepareLintPromise
|
||||||
await restoreCachePromise
|
|
||||||
const patchPath = await patchPromise
|
const patchPath = await patchPromise
|
||||||
|
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
return { lintPath, patchPath }
|
return { lintPath, patchPath }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +161,10 @@ 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}`.trimRight()
|
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
||||||
|
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`)
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
try {
|
try {
|
||||||
const res = await execShellCommand(cmd, cmdArgs)
|
const res = await execShellCommand(cmd, cmdArgs)
|
||||||
|
@ -3,6 +3,8 @@ import * as httpm from "@actions/http-client"
|
|||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
|
||||||
|
import { InstallMode } from "./install"
|
||||||
|
|
||||||
// TODO: make a class
|
// TODO: make a class
|
||||||
export type Version = {
|
export type Version = {
|
||||||
major: number
|
major: number
|
||||||
@ -17,6 +19,7 @@ const parseVersion = (s: string): Version => {
|
|||||||
if (s == "latest" || s == "") {
|
if (s == "latest" || s == "") {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = s.match(versionRe)
|
const match = s.match(versionRe)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
||||||
@ -61,6 +64,7 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
|||||||
const getRequestedLintVersion = (): Version => {
|
const getRequestedLintVersion = (): Version => {
|
||||||
let requestedLintVersion = core.getInput(`version`)
|
let requestedLintVersion = 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.join(workingDirectory, goMod)
|
goMod = path.join(workingDirectory, goMod)
|
||||||
@ -79,6 +83,7 @@ const getRequestedLintVersion = (): Version => {
|
|||||||
if (parsedRequestedLintVersion == null) {
|
if (parsedRequestedLintVersion == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
|
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
|
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
|
||||||
@ -86,6 +91,7 @@ const getRequestedLintVersion = (): Version => {
|
|||||||
)} and later versions`
|
)} and later versions`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedRequestedLintVersion
|
return parsedRequestedLintVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,9 +126,16 @@ const getConfig = async (): Promise<Config> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findLintVersion(): Promise<VersionConfig> {
|
export async function findLintVersion(mode: InstallMode): Promise<VersionConfig> {
|
||||||
core.info(`Finding needed golangci-lint version...`)
|
core.info(`Finding needed golangci-lint version...`)
|
||||||
|
|
||||||
|
if (mode == InstallMode.GoInstall) {
|
||||||
|
const v: string = core.getInput(`version`)
|
||||||
|
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" }
|
||||||
|
}
|
||||||
|
|
||||||
const reqLintVersion = getRequestedLintVersion()
|
const reqLintVersion = getRequestedLintVersion()
|
||||||
|
|
||||||
// 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) {
|
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -133,6 +146,7 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
const config = await getConfig()
|
const config = await getConfig()
|
||||||
@ -155,5 +169,6 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
|||||||
Date.now() - startedAt
|
Date.now() - startedAt
|
||||||
}ms`
|
}ms`
|
||||||
)
|
)
|
||||||
|
|
||||||
return versionConfig
|
return versionConfig
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user