Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
639cd343e1 | |||
569abaa281 | |||
c57cc43669 | |||
322510a3ea | |||
185e7a2f8f | |||
5be60c708e | |||
825a50d3a2 | |||
8c13ec4e5d | |||
416b5d0b48 | |||
66a608006f | |||
f0ba586c1f | |||
b8fff06a27 |
37
.github/workflows/test.yml
vendored
37
.github/workflows/test.yml
vendored
@ -52,8 +52,8 @@ jobs:
|
||||
version:
|
||||
- ""
|
||||
- "latest"
|
||||
- "v1.51"
|
||||
- "v1.51.2"
|
||||
- "v1.53"
|
||||
- "v1.53.2"
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: read
|
||||
@ -66,9 +66,38 @@ jobs:
|
||||
- uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
args: --timeout=3m --issues-exit-code=0 ./sample/...
|
||||
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||
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=5m --issues-exit-code=0 ./sample/...
|
||||
only-new-issues: true
|
||||
install-mode: goinstall
|
||||
|
||||
test-go-mod-version:
|
||||
needs: [ build ]
|
||||
strategy:
|
||||
@ -88,4 +117,4 @@ jobs:
|
||||
- uses: ./
|
||||
with:
|
||||
working-directory: sample-go-mod
|
||||
args: --timeout=3m --issues-exit-code=0 ./...
|
||||
args: --timeout=5m --issues-exit-code=0 ./...
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -97,3 +97,6 @@ typings/
|
||||
|
||||
# Text editor files
|
||||
.vscode/
|
||||
|
||||
# IntelliJ/WebStorm files
|
||||
.idea
|
||||
|
39
README.md
39
README.md
@ -23,37 +23,40 @@ Add `.github/workflows/golangci-lint.yml` with the following contents:
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||
# pull-requests: read
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.17'
|
||||
go-version: '1.20'
|
||||
cache: false
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.29
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
#
|
||||
# Note: by default the `.golangci.yml` file should be at the root of the repository.
|
||||
# The location of the configuration file can be changed by using `--config=`
|
||||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
@ -67,6 +70,9 @@ jobs:
|
||||
|
||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||
# 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)
|
||||
@ -80,21 +86,21 @@ If you need to run linters for specific operating systems, you will need to use
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||
# pull-requests: read
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go: [1.17]
|
||||
go: ['1.20']
|
||||
os: [macos-latest, windows-latest]
|
||||
name: lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
@ -107,16 +113,23 @@ jobs:
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.29
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
#
|
||||
# Note: by default the `.golangci.yml` file should be at the root of the repository.
|
||||
# The location of the configuration file can be changed by using `--config=`
|
||||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# 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:
|
||||
|
@ -34,6 +34,10 @@ inputs:
|
||||
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
|
||||
default: false
|
||||
required: false
|
||||
install-mode:
|
||||
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
|
||||
default: "binary"
|
||||
required: false
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "dist/run/index.js"
|
||||
|
121
dist/post_run/index.js
vendored
121
dist/post_run/index.js
vendored
@ -66312,18 +66312,18 @@ var Inputs;
|
||||
Inputs["Key"] = "key";
|
||||
Inputs["Path"] = "path";
|
||||
Inputs["RestoreKeys"] = "restore-keys";
|
||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||
})(Inputs || (exports.Inputs = Inputs = {}));
|
||||
var State;
|
||||
(function (State) {
|
||||
State["CachePrimaryKey"] = "CACHE_KEY";
|
||||
State["CacheMatchedKey"] = "CACHE_RESULT";
|
||||
})(State = exports.State || (exports.State = {}));
|
||||
})(State || (exports.State = State = {}));
|
||||
var Events;
|
||||
(function (Events) {
|
||||
Events["Key"] = "GITHUB_EVENT_NAME";
|
||||
Events["Push"] = "push";
|
||||
Events["PullRequest"] = "pull_request";
|
||||
})(Events = exports.Events || (exports.Events = {}));
|
||||
})(Events || (exports.Events = Events = {}));
|
||||
exports.RefKey = "GITHUB_REF";
|
||||
|
||||
|
||||
@ -66370,11 +66370,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
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 tc = __importStar(__nccwpck_require__(7784));
|
||||
const child_process_1 = __nccwpck_require__(2081);
|
||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||
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 getAssetURL = (versionConfig) => {
|
||||
let ext = "tar.gz";
|
||||
@ -66398,13 +66401,74 @@ const getAssetURL = (versionConfig) => {
|
||||
const noPrefix = versionConfig.TargetVersion.slice(1);
|
||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||
};
|
||||
// The installLint returns path to installed binary of golangci-lint.
|
||||
function installLint(versionConfig) {
|
||||
var InstallMode;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
InstallMode["GoInstall"] = "goinstall";
|
||||
})(InstallMode || (exports.InstallMode = 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* () {
|
||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
||||
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);
|
||||
core.info(`Downloading ${assetURL} ...`);
|
||||
core.info(`Downloading binary ${assetURL} ...`);
|
||||
const archivePath = yield tc.downloadTool(assetURL);
|
||||
let extractedDir = "";
|
||||
let repl = /\.tar\.gz$/;
|
||||
@ -66427,7 +66491,7 @@ function installLint(versionConfig) {
|
||||
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);
|
||||
function prepareLint() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const versionConfig = yield (0, version_1.findLintVersion)();
|
||||
return yield (0, install_1.installLint)(versionConfig);
|
||||
const mode = core.getInput("install-mode").toLowerCase();
|
||||
const versionConfig = yield (0, version_1.findLintVersion)(mode);
|
||||
return yield (0, install_1.installLint)(versionConfig, mode);
|
||||
});
|
||||
}
|
||||
function fetchPatch() {
|
||||
@ -66548,11 +66613,10 @@ function prepareEnv() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
const restoreCachePromise = (0, cache_1.restoreCache)();
|
||||
yield (0, cache_1.restoreCache)();
|
||||
const prepareLintPromise = prepareLint();
|
||||
const patchPromise = fetchPatch();
|
||||
const lintPath = yield prepareLintPromise;
|
||||
yield restoreCachePromise;
|
||||
const patchPath = yield patchPromise;
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
return { lintPath, patchPath };
|
||||
@ -66573,18 +66637,26 @@ function runLint(lintPath, patchPath) {
|
||||
const res = yield execShellCommand(`${lintPath} cache status`);
|
||||
printOutput(res);
|
||||
}
|
||||
const userArgs = core.getInput(`args`);
|
||||
let userArgs = core.getInput(`args`);
|
||||
const addedArgs = [];
|
||||
const userArgNames = new Set(userArgs
|
||||
const userArgsList = userArgs
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map((arg) => arg.split(`=`)[0])
|
||||
.filter((arg) => arg.startsWith(`-`))
|
||||
.map((arg) => arg.replace(/^-+/, ``)));
|
||||
if (userArgNames.has(`out-format`)) {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
|
||||
}
|
||||
addedArgs.push(`--out-format=github-actions`);
|
||||
.map((arg) => arg.replace(/^-+/, ``))
|
||||
.map((arg) => arg.split(/=(.*)/, 2))
|
||||
.map(([key, value]) => [key.toLowerCase(), value !== null && value !== void 0 ? value : ""]);
|
||||
const userArgsMap = new Map(userArgsList);
|
||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||
const formats = (userArgsMap.get("out-format") || "")
|
||||
.trim()
|
||||
.split(",")
|
||||
.filter((f) => f.length > 0)
|
||||
.filter((f) => !f.startsWith(`github-actions`))
|
||||
.concat("github-actions")
|
||||
.join(",");
|
||||
addedArgs.push(`--out-format=${formats}`);
|
||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||
if (patchPath) {
|
||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
@ -66609,7 +66681,7 @@ function runLint(lintPath, patchPath) {
|
||||
}
|
||||
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 || ``}] ...`);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
@ -66774,6 +66846,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||
const httpm = __importStar(__nccwpck_require__(6255));
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const install_1 = __nccwpck_require__(1649);
|
||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
||||
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
||||
const parseVersion = (s) => {
|
||||
@ -66858,9 +66931,13 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
throw new Error(`failed to get action config: ${exc.message}`);
|
||||
}
|
||||
});
|
||||
function findLintVersion() {
|
||||
function findLintVersion(mode) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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();
|
||||
// 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) {
|
||||
|
121
dist/run/index.js
vendored
121
dist/run/index.js
vendored
@ -66312,18 +66312,18 @@ var Inputs;
|
||||
Inputs["Key"] = "key";
|
||||
Inputs["Path"] = "path";
|
||||
Inputs["RestoreKeys"] = "restore-keys";
|
||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||
})(Inputs || (exports.Inputs = Inputs = {}));
|
||||
var State;
|
||||
(function (State) {
|
||||
State["CachePrimaryKey"] = "CACHE_KEY";
|
||||
State["CacheMatchedKey"] = "CACHE_RESULT";
|
||||
})(State = exports.State || (exports.State = {}));
|
||||
})(State || (exports.State = State = {}));
|
||||
var Events;
|
||||
(function (Events) {
|
||||
Events["Key"] = "GITHUB_EVENT_NAME";
|
||||
Events["Push"] = "push";
|
||||
Events["PullRequest"] = "pull_request";
|
||||
})(Events = exports.Events || (exports.Events = {}));
|
||||
})(Events || (exports.Events = Events = {}));
|
||||
exports.RefKey = "GITHUB_REF";
|
||||
|
||||
|
||||
@ -66370,11 +66370,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
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 tc = __importStar(__nccwpck_require__(7784));
|
||||
const child_process_1 = __nccwpck_require__(2081);
|
||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||
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 getAssetURL = (versionConfig) => {
|
||||
let ext = "tar.gz";
|
||||
@ -66398,13 +66401,74 @@ const getAssetURL = (versionConfig) => {
|
||||
const noPrefix = versionConfig.TargetVersion.slice(1);
|
||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||
};
|
||||
// The installLint returns path to installed binary of golangci-lint.
|
||||
function installLint(versionConfig) {
|
||||
var InstallMode;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
InstallMode["GoInstall"] = "goinstall";
|
||||
})(InstallMode || (exports.InstallMode = 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* () {
|
||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`);
|
||||
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);
|
||||
core.info(`Downloading ${assetURL} ...`);
|
||||
core.info(`Downloading binary ${assetURL} ...`);
|
||||
const archivePath = yield tc.downloadTool(assetURL);
|
||||
let extractedDir = "";
|
||||
let repl = /\.tar\.gz$/;
|
||||
@ -66427,7 +66491,7 @@ function installLint(versionConfig) {
|
||||
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);
|
||||
function prepareLint() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const versionConfig = yield (0, version_1.findLintVersion)();
|
||||
return yield (0, install_1.installLint)(versionConfig);
|
||||
const mode = core.getInput("install-mode").toLowerCase();
|
||||
const versionConfig = yield (0, version_1.findLintVersion)(mode);
|
||||
return yield (0, install_1.installLint)(versionConfig, mode);
|
||||
});
|
||||
}
|
||||
function fetchPatch() {
|
||||
@ -66548,11 +66613,10 @@ function prepareEnv() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
const restoreCachePromise = (0, cache_1.restoreCache)();
|
||||
yield (0, cache_1.restoreCache)();
|
||||
const prepareLintPromise = prepareLint();
|
||||
const patchPromise = fetchPatch();
|
||||
const lintPath = yield prepareLintPromise;
|
||||
yield restoreCachePromise;
|
||||
const patchPath = yield patchPromise;
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
return { lintPath, patchPath };
|
||||
@ -66573,18 +66637,26 @@ function runLint(lintPath, patchPath) {
|
||||
const res = yield execShellCommand(`${lintPath} cache status`);
|
||||
printOutput(res);
|
||||
}
|
||||
const userArgs = core.getInput(`args`);
|
||||
let userArgs = core.getInput(`args`);
|
||||
const addedArgs = [];
|
||||
const userArgNames = new Set(userArgs
|
||||
const userArgsList = userArgs
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map((arg) => arg.split(`=`)[0])
|
||||
.filter((arg) => arg.startsWith(`-`))
|
||||
.map((arg) => arg.replace(/^-+/, ``)));
|
||||
if (userArgNames.has(`out-format`)) {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
|
||||
}
|
||||
addedArgs.push(`--out-format=github-actions`);
|
||||
.map((arg) => arg.replace(/^-+/, ``))
|
||||
.map((arg) => arg.split(/=(.*)/, 2))
|
||||
.map(([key, value]) => [key.toLowerCase(), value !== null && value !== void 0 ? value : ""]);
|
||||
const userArgsMap = new Map(userArgsList);
|
||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||
const formats = (userArgsMap.get("out-format") || "")
|
||||
.trim()
|
||||
.split(",")
|
||||
.filter((f) => f.length > 0)
|
||||
.filter((f) => !f.startsWith(`github-actions`))
|
||||
.concat("github-actions")
|
||||
.join(",");
|
||||
addedArgs.push(`--out-format=${formats}`);
|
||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||
if (patchPath) {
|
||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
@ -66609,7 +66681,7 @@ function runLint(lintPath, patchPath) {
|
||||
}
|
||||
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 || ``}] ...`);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
@ -66774,6 +66846,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||
const httpm = __importStar(__nccwpck_require__(6255));
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const install_1 = __nccwpck_require__(1649);
|
||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
|
||||
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
|
||||
const parseVersion = (s) => {
|
||||
@ -66858,9 +66931,13 @@ const getConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
throw new Error(`failed to get action config: ${exc.message}`);
|
||||
}
|
||||
});
|
||||
function findLintVersion() {
|
||||
function findLintVersion(mode) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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();
|
||||
// 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) {
|
||||
|
226
package-lock.json
generated
226
package-lock.json
generated
@ -21,16 +21,16 @@
|
||||
"tmp": "^0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
||||
"@typescript-eslint/parser": "^5.59.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.41.0",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/cache": {
|
||||
@ -383,18 +383,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/js": {
|
||||
"version": "8.41.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.41.0.tgz",
|
||||
"integrity": "sha512-LxcyMGxwmTh2lY9FwHPGWOHmYFCZvbrFCBZL4FzSSsxsRPuhrYUg/49/0KDfW8tnIEaEHtfmn6+NPN+1DqaNmA==",
|
||||
"version": "8.42.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.42.0.tgz",
|
||||
"integrity": "sha512-6SWlXpWU5AvId8Ac7zjzmIOqMOba/JWY8XZ4A7q7Gn1Vlfg/SFFIlrtHXt9nPn4op9ZPAkl91Jao+QQv3r/ukw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array": {
|
||||
"version": "0.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
|
||||
"integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==",
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz",
|
||||
"integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@humanwhocodes/object-schema": "^1.2.1",
|
||||
@ -626,15 +626,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.7.tgz",
|
||||
"integrity": "sha512-BL+jYxUFIbuYwy+4fF86k5vdT9lT0CNJ6HtwrIvGh0PhH8s0yy5rjaKH2fDCrz5ITHy07WCzVGNvAmjJh4IJFA==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.8.tgz",
|
||||
"integrity": "sha512-JDMOmhXteJ4WVKOiHXGCoB96ADWg9q7efPWHRViT/f09bA8XOMLAVHHju3l0MkZnG1izaWXYmgvQcUjTRcpShQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/regexpp": "^4.4.0",
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/type-utils": "5.59.7",
|
||||
"@typescript-eslint/utils": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/type-utils": "5.59.8",
|
||||
"@typescript-eslint/utils": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"grapheme-splitter": "^1.0.4",
|
||||
"ignore": "^5.2.0",
|
||||
@ -675,14 +675,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.7.tgz",
|
||||
"integrity": "sha512-VhpsIEuq/8i5SF+mPg9jSdIwgMBBp0z9XqjiEay+81PYLJuroN+ET1hM5IhkiYMJd9MkTz8iJLt7aaGAgzWUbQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.8.tgz",
|
||||
"integrity": "sha512-AnR19RjJcpjoeGojmwZtCwBX/RidqDZtzcbG3xHrmz0aHHoOcbWnpDllenRDmDvsV0RQ6+tbb09/kyc+UT9Orw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@ -702,13 +702,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.7.tgz",
|
||||
"integrity": "sha512-FL6hkYWK9zBGdxT2wWEd2W8ocXMu3K94i3gvMrjXpx+koFYdYV7KprKfirpgY34vTGzEPPuKoERpP8kD5h7vZQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.8.tgz",
|
||||
"integrity": "sha512-/w08ndCYI8gxGf+9zKf1vtx/16y8MHrZs5/tnjHhMLNSixuNcJavSX4wAiPf4aS5x41Es9YPCn44MIe4cxIlig==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/visitor-keys": "5.59.7"
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/visitor-keys": "5.59.8"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@ -719,13 +719,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/type-utils": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.7.tgz",
|
||||
"integrity": "sha512-ozuz/GILuYG7osdY5O5yg0QxXUAEoI4Go3Do5xeu+ERH9PorHBPSdvD3Tjp2NN2bNLh1NJQSsQu2TPu/Ly+HaQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.8.tgz",
|
||||
"integrity": "sha512-+5M518uEIHFBy3FnyqZUF3BMP+AXnYn4oyH8RF012+e7/msMY98FhGL5SrN29NQ9xDgvqCgYnsOiKp1VjZ/fpA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/utils": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"@typescript-eslint/utils": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"tsutils": "^3.21.0"
|
||||
},
|
||||
@ -746,9 +746,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/types": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.7.tgz",
|
||||
"integrity": "sha512-UnVS2MRRg6p7xOSATscWkKjlf/NDKuqo5TdbWck6rIRZbmKpVNTLALzNvcjIfHBE7736kZOFc/4Z3VcZwuOM/A==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.8.tgz",
|
||||
"integrity": "sha512-+uWuOhBTj/L6awoWIg0BlWy0u9TyFpCHrAuQ5bNfxDaZ1Ppb3mx6tUigc74LHcbHpOHuOTOJrBoAnhdHdaea1w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@ -759,13 +759,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.7.tgz",
|
||||
"integrity": "sha512-4A1NtZ1I3wMN2UGDkU9HMBL+TIQfbrh4uS0WDMMpf3xMRursDbqEf1ahh6vAAe3mObt8k3ZATnezwG4pdtWuUQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.8.tgz",
|
||||
"integrity": "sha512-Jy/lPSDJGNow14vYu6IrW790p7HIf/SOV1Bb6lZ7NUkLc2iB2Z9elESmsaUtLw8kVqogSbtLH9tut5GCX1RLDg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/visitor-keys": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/visitor-keys": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
@ -801,17 +801,17 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.7.tgz",
|
||||
"integrity": "sha512-yCX9WpdQKaLufz5luG4aJbOpdXf/fjwGMcLFXZVPUz3QqLirG5QcwwnIHNf8cjLjxK4qtzTO8udUtMQSAToQnQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.8.tgz",
|
||||
"integrity": "sha512-Tr65630KysnNn9f9G7ROF3w1b5/7f6QVCJ+WK9nhIocWmx9F+TmCAcglF26Vm7z8KCTwoKcNEBZrhlklla3CKg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@types/json-schema": "^7.0.9",
|
||||
"@types/semver": "^7.3.12",
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"eslint-scope": "^5.1.1",
|
||||
"semver": "^7.3.7"
|
||||
},
|
||||
@ -842,12 +842,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.7.tgz",
|
||||
"integrity": "sha512-tyN+X2jvMslUszIiYbF0ZleP+RqQsFVpGrKI6e0Eet1w8WmhsAtmzaqm8oM8WJQ1ysLwhnsK/4hYHJjOgJVfQQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.8.tgz",
|
||||
"integrity": "sha512-pJhi2ms0x0xgloT7xYabil3SGGlojNNKjK/q6dB3Ey0uJLMjK2UDGJvHieiyJVW/7C3KI+Z4Q3pEHkm4ejA+xQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
@ -1319,16 +1319,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint": {
|
||||
"version": "8.41.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.41.0.tgz",
|
||||
"integrity": "sha512-WQDQpzGBOP5IrXPo4Hc0814r4/v2rrIsB0rhT7jtunIalgg6gYXWhRMOejVO8yH21T/FGaxjmFjBMNqcIlmH1Q==",
|
||||
"version": "8.42.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.42.0.tgz",
|
||||
"integrity": "sha512-ulg9Ms6E1WPf67PHaEY4/6E2tEn5/f7FXGzr3t9cBMugOmf1INYvuUwwh1aXQN4MfJ6a5K2iNwP3w4AColvI9A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.4.0",
|
||||
"@eslint/eslintrc": "^2.0.3",
|
||||
"@eslint/js": "8.41.0",
|
||||
"@humanwhocodes/config-array": "^0.11.8",
|
||||
"@eslint/js": "8.42.0",
|
||||
"@humanwhocodes/config-array": "^0.11.10",
|
||||
"@humanwhocodes/module-importer": "^1.0.1",
|
||||
"@nodelib/fs.walk": "^1.2.8",
|
||||
"ajv": "^6.10.0",
|
||||
@ -3170,16 +3170,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
|
||||
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz",
|
||||
"integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.20"
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/unbox-primitive": {
|
||||
@ -3657,15 +3657,15 @@
|
||||
}
|
||||
},
|
||||
"@eslint/js": {
|
||||
"version": "8.41.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.41.0.tgz",
|
||||
"integrity": "sha512-LxcyMGxwmTh2lY9FwHPGWOHmYFCZvbrFCBZL4FzSSsxsRPuhrYUg/49/0KDfW8tnIEaEHtfmn6+NPN+1DqaNmA==",
|
||||
"version": "8.42.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.42.0.tgz",
|
||||
"integrity": "sha512-6SWlXpWU5AvId8Ac7zjzmIOqMOba/JWY8XZ4A7q7Gn1Vlfg/SFFIlrtHXt9nPn4op9ZPAkl91Jao+QQv3r/ukw==",
|
||||
"dev": true
|
||||
},
|
||||
"@humanwhocodes/config-array": {
|
||||
"version": "0.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
|
||||
"integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==",
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz",
|
||||
"integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@humanwhocodes/object-schema": "^1.2.1",
|
||||
@ -3868,15 +3868,15 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.7.tgz",
|
||||
"integrity": "sha512-BL+jYxUFIbuYwy+4fF86k5vdT9lT0CNJ6HtwrIvGh0PhH8s0yy5rjaKH2fDCrz5ITHy07WCzVGNvAmjJh4IJFA==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.8.tgz",
|
||||
"integrity": "sha512-JDMOmhXteJ4WVKOiHXGCoB96ADWg9q7efPWHRViT/f09bA8XOMLAVHHju3l0MkZnG1izaWXYmgvQcUjTRcpShQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@eslint-community/regexpp": "^4.4.0",
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/type-utils": "5.59.7",
|
||||
"@typescript-eslint/utils": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/type-utils": "5.59.8",
|
||||
"@typescript-eslint/utils": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"grapheme-splitter": "^1.0.4",
|
||||
"ignore": "^5.2.0",
|
||||
@ -3897,53 +3897,53 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/parser": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.7.tgz",
|
||||
"integrity": "sha512-VhpsIEuq/8i5SF+mPg9jSdIwgMBBp0z9XqjiEay+81PYLJuroN+ET1hM5IhkiYMJd9MkTz8iJLt7aaGAgzWUbQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.8.tgz",
|
||||
"integrity": "sha512-AnR19RjJcpjoeGojmwZtCwBX/RidqDZtzcbG3xHrmz0aHHoOcbWnpDllenRDmDvsV0RQ6+tbb09/kyc+UT9Orw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"debug": "^4.3.4"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/scope-manager": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.7.tgz",
|
||||
"integrity": "sha512-FL6hkYWK9zBGdxT2wWEd2W8ocXMu3K94i3gvMrjXpx+koFYdYV7KprKfirpgY34vTGzEPPuKoERpP8kD5h7vZQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.8.tgz",
|
||||
"integrity": "sha512-/w08ndCYI8gxGf+9zKf1vtx/16y8MHrZs5/tnjHhMLNSixuNcJavSX4wAiPf4aS5x41Es9YPCn44MIe4cxIlig==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/visitor-keys": "5.59.7"
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/visitor-keys": "5.59.8"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/type-utils": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.7.tgz",
|
||||
"integrity": "sha512-ozuz/GILuYG7osdY5O5yg0QxXUAEoI4Go3Do5xeu+ERH9PorHBPSdvD3Tjp2NN2bNLh1NJQSsQu2TPu/Ly+HaQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.8.tgz",
|
||||
"integrity": "sha512-+5M518uEIHFBy3FnyqZUF3BMP+AXnYn4oyH8RF012+e7/msMY98FhGL5SrN29NQ9xDgvqCgYnsOiKp1VjZ/fpA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/utils": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"@typescript-eslint/utils": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"tsutils": "^3.21.0"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/types": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.7.tgz",
|
||||
"integrity": "sha512-UnVS2MRRg6p7xOSATscWkKjlf/NDKuqo5TdbWck6rIRZbmKpVNTLALzNvcjIfHBE7736kZOFc/4Z3VcZwuOM/A==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.8.tgz",
|
||||
"integrity": "sha512-+uWuOhBTj/L6awoWIg0BlWy0u9TyFpCHrAuQ5bNfxDaZ1Ppb3mx6tUigc74LHcbHpOHuOTOJrBoAnhdHdaea1w==",
|
||||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/typescript-estree": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.7.tgz",
|
||||
"integrity": "sha512-4A1NtZ1I3wMN2UGDkU9HMBL+TIQfbrh4uS0WDMMpf3xMRursDbqEf1ahh6vAAe3mObt8k3ZATnezwG4pdtWuUQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.8.tgz",
|
||||
"integrity": "sha512-Jy/lPSDJGNow14vYu6IrW790p7HIf/SOV1Bb6lZ7NUkLc2iB2Z9elESmsaUtLw8kVqogSbtLH9tut5GCX1RLDg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/visitor-keys": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/visitor-keys": "5.59.8",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
@ -3963,17 +3963,17 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/utils": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.7.tgz",
|
||||
"integrity": "sha512-yCX9WpdQKaLufz5luG4aJbOpdXf/fjwGMcLFXZVPUz3QqLirG5QcwwnIHNf8cjLjxK4qtzTO8udUtMQSAToQnQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.8.tgz",
|
||||
"integrity": "sha512-Tr65630KysnNn9f9G7ROF3w1b5/7f6QVCJ+WK9nhIocWmx9F+TmCAcglF26Vm7z8KCTwoKcNEBZrhlklla3CKg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@types/json-schema": "^7.0.9",
|
||||
"@types/semver": "^7.3.12",
|
||||
"@typescript-eslint/scope-manager": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/typescript-estree": "5.59.7",
|
||||
"@typescript-eslint/scope-manager": "5.59.8",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"@typescript-eslint/typescript-estree": "5.59.8",
|
||||
"eslint-scope": "^5.1.1",
|
||||
"semver": "^7.3.7"
|
||||
},
|
||||
@ -3990,12 +3990,12 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/visitor-keys": {
|
||||
"version": "5.59.7",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.7.tgz",
|
||||
"integrity": "sha512-tyN+X2jvMslUszIiYbF0ZleP+RqQsFVpGrKI6e0Eet1w8WmhsAtmzaqm8oM8WJQ1ysLwhnsK/4hYHJjOgJVfQQ==",
|
||||
"version": "5.59.8",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.8.tgz",
|
||||
"integrity": "sha512-pJhi2ms0x0xgloT7xYabil3SGGlojNNKjK/q6dB3Ey0uJLMjK2UDGJvHieiyJVW/7C3KI+Z4Q3pEHkm4ejA+xQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.59.7",
|
||||
"@typescript-eslint/types": "5.59.8",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
}
|
||||
},
|
||||
@ -4338,16 +4338,16 @@
|
||||
"dev": true
|
||||
},
|
||||
"eslint": {
|
||||
"version": "8.41.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.41.0.tgz",
|
||||
"integrity": "sha512-WQDQpzGBOP5IrXPo4Hc0814r4/v2rrIsB0rhT7jtunIalgg6gYXWhRMOejVO8yH21T/FGaxjmFjBMNqcIlmH1Q==",
|
||||
"version": "8.42.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.42.0.tgz",
|
||||
"integrity": "sha512-ulg9Ms6E1WPf67PHaEY4/6E2tEn5/f7FXGzr3t9cBMugOmf1INYvuUwwh1aXQN4MfJ6a5K2iNwP3w4AColvI9A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.4.0",
|
||||
"@eslint/eslintrc": "^2.0.3",
|
||||
"@eslint/js": "8.41.0",
|
||||
"@humanwhocodes/config-array": "^0.11.8",
|
||||
"@eslint/js": "8.42.0",
|
||||
"@humanwhocodes/config-array": "^0.11.10",
|
||||
"@humanwhocodes/module-importer": "^1.0.1",
|
||||
"@nodelib/fs.walk": "^1.2.8",
|
||||
"ajv": "^6.10.0",
|
||||
@ -5659,9 +5659,9 @@
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
|
||||
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz",
|
||||
"integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==",
|
||||
"dev": true
|
||||
},
|
||||
"unbox-primitive": {
|
||||
|
@ -36,15 +36,15 @@
|
||||
"tmp": "^0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
||||
"@typescript-eslint/parser": "^5.59.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.41.0",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.1.3"
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as tc from "@actions/tool-cache"
|
||||
import { exec, ExecOptions } from "child_process"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { promisify } from "util"
|
||||
|
||||
import { VersionConfig } from "./version"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
|
||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
||||
|
||||
const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||
@ -31,13 +35,95 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
||||
}
|
||||
|
||||
// The installLint returns path to installed binary of golangci-lint.
|
||||
export async function installLint(versionConfig: VersionConfig): Promise<string> {
|
||||
export enum InstallMode {
|
||||
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}...`)
|
||||
|
||||
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)
|
||||
core.info(`Downloading ${assetURL} ...`)
|
||||
|
||||
core.info(`Downloading binary ${assetURL} ...`)
|
||||
|
||||
const archivePath = await tc.downloadTool(assetURL)
|
||||
|
||||
let extractedDir = ""
|
||||
let repl = /\.tar\.gz$/
|
||||
if (assetURL.endsWith("zip")) {
|
||||
@ -55,6 +141,8 @@ export async function installLint(versionConfig: VersionConfig): Promise<string>
|
||||
const urlParts = assetURL.split(`/`)
|
||||
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
|
||||
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
|
||||
|
||||
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||
|
||||
return lintPath
|
||||
}
|
||||
|
51
src/run.ts
51
src/run.ts
@ -7,7 +7,7 @@ import { dir } from "tmp"
|
||||
import { promisify } from "util"
|
||||
|
||||
import { restoreCache, saveCache } from "./cache"
|
||||
import { installLint } from "./install"
|
||||
import { installLint, InstallMode } from "./install"
|
||||
import { findLintVersion } from "./version"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
@ -15,8 +15,10 @@ const writeFile = promisify(fs.writeFile)
|
||||
const createTempDir = promisify(dir)
|
||||
|
||||
async function prepareLint(): Promise<string> {
|
||||
const versionConfig = await findLintVersion()
|
||||
return await installLint(versionConfig)
|
||||
const mode = core.getInput("install-mode").toLowerCase()
|
||||
const versionConfig = await findLintVersion(<InstallMode>mode)
|
||||
|
||||
return await installLint(versionConfig, <InstallMode>mode)
|
||||
}
|
||||
|
||||
async function fetchPatch(): Promise<string> {
|
||||
@ -83,15 +85,15 @@ async function prepareEnv(): Promise<Env> {
|
||||
const startedAt = Date.now()
|
||||
|
||||
// Prepare cache, lint and go in parallel.
|
||||
const restoreCachePromise = restoreCache()
|
||||
await restoreCache()
|
||||
const prepareLintPromise = prepareLint()
|
||||
const patchPromise = fetchPatch()
|
||||
|
||||
const lintPath = await prepareLintPromise
|
||||
await restoreCachePromise
|
||||
const patchPath = await patchPromise
|
||||
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||
|
||||
return { lintPath, patchPath }
|
||||
}
|
||||
|
||||
@ -116,21 +118,30 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
||||
printOutput(res)
|
||||
}
|
||||
|
||||
const userArgs = core.getInput(`args`)
|
||||
let userArgs = core.getInput(`args`)
|
||||
const addedArgs: string[] = []
|
||||
|
||||
const userArgNames = new Set<string>(
|
||||
userArgs
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map((arg) => arg.split(`=`)[0])
|
||||
.filter((arg) => arg.startsWith(`-`))
|
||||
.map((arg) => arg.replace(/^-+/, ``))
|
||||
)
|
||||
if (userArgNames.has(`out-format`)) {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`)
|
||||
}
|
||||
addedArgs.push(`--out-format=github-actions`)
|
||||
const userArgsList = userArgs
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.filter((arg) => arg.startsWith(`-`))
|
||||
.map((arg) => arg.replace(/^-+/, ``))
|
||||
.map((arg) => arg.split(/=(.*)/, 2))
|
||||
.map<[string, string]>(([key, value]) => [key.toLowerCase(), value ?? ""])
|
||||
|
||||
const userArgsMap = new Map<string, string>(userArgsList)
|
||||
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
||||
|
||||
const formats = (userArgsMap.get("out-format") || "")
|
||||
.trim()
|
||||
.split(",")
|
||||
.filter((f) => f.length > 0)
|
||||
.filter((f) => !f.startsWith(`github-actions`))
|
||||
.concat("github-actions")
|
||||
.join(",")
|
||||
|
||||
addedArgs.push(`--out-format=${formats}`)
|
||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
||||
|
||||
if (patchPath) {
|
||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
||||
@ -159,8 +170,10 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
||||
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 || ``}] ...`)
|
||||
|
||||
const startedAt = Date.now()
|
||||
try {
|
||||
const res = await execShellCommand(cmd, cmdArgs)
|
||||
|
@ -3,6 +3,8 @@ import * as httpm from "@actions/http-client"
|
||||
import * as fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
import { InstallMode } from "./install"
|
||||
|
||||
// TODO: make a class
|
||||
export type Version = {
|
||||
major: number
|
||||
@ -17,6 +19,7 @@ const parseVersion = (s: string): Version => {
|
||||
if (s == "latest" || s == "") {
|
||||
return null
|
||||
}
|
||||
|
||||
const match = s.match(versionRe)
|
||||
if (!match) {
|
||||
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 => {
|
||||
let requestedLintVersion = core.getInput(`version`)
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
|
||||
let goMod = "go.mod"
|
||||
if (workingDirectory) {
|
||||
goMod = path.join(workingDirectory, goMod)
|
||||
@ -79,6 +83,7 @@ const getRequestedLintVersion = (): Version => {
|
||||
if (parsedRequestedLintVersion == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
|
||||
throw new Error(
|
||||
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
|
||||
@ -86,6 +91,7 @@ const getRequestedLintVersion = (): Version => {
|
||||
)} and later versions`
|
||||
)
|
||||
}
|
||||
|
||||
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...`)
|
||||
|
||||
if (mode == InstallMode.GoInstall) {
|
||||
const v: string = core.getInput(`version`)
|
||||
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" }
|
||||
}
|
||||
|
||||
const reqLintVersion = getRequestedLintVersion()
|
||||
|
||||
// if the patched version is passed, just use it
|
||||
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
|
||||
return new Promise((resolve) => {
|
||||
@ -133,6 +146,7 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const startedAt = Date.now()
|
||||
|
||||
const config = await getConfig()
|
||||
@ -155,5 +169,6 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
||||
Date.now() - startedAt
|
||||
}ms`
|
||||
)
|
||||
|
||||
return versionConfig
|
||||
}
|
||||
|
Reference in New Issue
Block a user