Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
0adbc47a59 | |||
f7463c56f6 | |||
32f961426b |
32
.github/workflows/test.yml
vendored
32
.github/workflows/test.yml
vendored
@ -73,6 +73,7 @@ jobs:
|
|||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
verify: true
|
||||||
|
|
||||||
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
|
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
@ -103,8 +104,9 @@ jobs:
|
|||||||
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
install-mode: goinstall
|
install-mode: goinstall
|
||||||
|
verify: true
|
||||||
|
|
||||||
test-go-mod-version:
|
test-go-mod:
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@ -113,6 +115,9 @@ jobs:
|
|||||||
- ubuntu-24.04-arm
|
- ubuntu-24.04-arm
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
wd:
|
||||||
|
- sample-go-mod
|
||||||
|
- sample-go-tool
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@ -123,27 +128,6 @@ jobs:
|
|||||||
go-version: oldstable
|
go-version: oldstable
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
working-directory: sample-go-mod
|
working-directory: ${{ matrix.wd }}
|
||||||
args: --timeout=5m --issues-exit-code=0 ./...
|
|
||||||
|
|
||||||
test-go-tool-version:
|
|
||||||
needs: [ build ]
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- ubuntu-24.04-arm
|
|
||||||
- macos-latest
|
|
||||||
- windows-latest
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: stable
|
|
||||||
- uses: ./
|
|
||||||
with:
|
|
||||||
working-directory: sample-go-tool
|
|
||||||
args: --timeout=5m --issues-exit-code=0 ./...
|
args: --timeout=5m --issues-exit-code=0 ./...
|
||||||
|
verify: true
|
||||||
|
6
.golangci.yml
Normal file
6
.golangci.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
output:
|
||||||
|
show-stats: true
|
||||||
|
sort-results: true
|
||||||
|
sort-order:
|
||||||
|
- linter
|
||||||
|
- file
|
18
README.md
18
README.md
@ -318,6 +318,24 @@ with:
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
### `verify`
|
||||||
|
|
||||||
|
(optional)
|
||||||
|
|
||||||
|
If set to true and the action verify the configuration file against the JSONSchema.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Example</summary>
|
||||||
|
|
||||||
|
```yml
|
||||||
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
verify: true
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### `only-new-issues`
|
### `only-new-issues`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
@ -22,6 +22,10 @@ inputs:
|
|||||||
description: "the token is used for fetching patch of a pull request to show only new issues"
|
description: "the token is used for fetching patch of a pull request to show only new issues"
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
required: false
|
required: false
|
||||||
|
verify:
|
||||||
|
description: "if set to true and the action verify the configuration file against the JSONSchema"
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
only-new-issues:
|
only-new-issues:
|
||||||
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
|
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
|
||||||
default: 'false'
|
default: 'false'
|
||||||
|
177
dist/post_run/index.js
generated
vendored
177
dist/post_run/index.js
generated
vendored
@ -93679,41 +93679,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.InstallMode = void 0;
|
exports.InstallMode = void 0;
|
||||||
exports.installLint = installLint;
|
exports.install = install;
|
||||||
exports.goInstall = goInstall;
|
exports.installBinary = installBinary;
|
||||||
exports.installBin = installBin;
|
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const tc = __importStar(__nccwpck_require__(3472));
|
const tc = __importStar(__nccwpck_require__(3472));
|
||||||
const child_process_1 = __nccwpck_require__(5317);
|
const child_process_1 = __nccwpck_require__(5317);
|
||||||
const os_1 = __importDefault(__nccwpck_require__(857));
|
const os_1 = __importDefault(__nccwpck_require__(857));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||||
const util_1 = __nccwpck_require__(9023);
|
const util_1 = __nccwpck_require__(9023);
|
||||||
|
const which_1 = __importDefault(__nccwpck_require__(1189));
|
||||||
|
const version_1 = __nccwpck_require__(311);
|
||||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
const getAssetURL = (versionInfo) => {
|
|
||||||
let ext = "tar.gz";
|
|
||||||
let platform = os_1.default.platform().toString();
|
|
||||||
switch (platform) {
|
|
||||||
case "win32":
|
|
||||||
platform = "windows";
|
|
||||||
ext = "zip";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let arch = os_1.default.arch();
|
|
||||||
switch (arch) {
|
|
||||||
case "arm64":
|
|
||||||
arch = "arm64";
|
|
||||||
break;
|
|
||||||
case "x64":
|
|
||||||
arch = "amd64";
|
|
||||||
break;
|
|
||||||
case "x32":
|
|
||||||
case "ia32":
|
|
||||||
arch = "386";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const noPrefix = versionInfo.TargetVersion.slice(1);
|
|
||||||
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
|
||||||
};
|
|
||||||
var InstallMode;
|
var InstallMode;
|
||||||
(function (InstallMode) {
|
(function (InstallMode) {
|
||||||
InstallMode["Binary"] = "binary";
|
InstallMode["Binary"] = "binary";
|
||||||
@ -93728,6 +93704,23 @@ const printOutput = (res) => {
|
|||||||
core.info(res.stderr);
|
core.info(res.stderr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
async function install() {
|
||||||
|
const mode = core.getInput("install-mode").toLowerCase();
|
||||||
|
if (mode === InstallMode.None) {
|
||||||
|
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
||||||
|
if (!binPath) {
|
||||||
|
throw new Error("golangci-lint binary not found in the PATH");
|
||||||
|
}
|
||||||
|
return binPath;
|
||||||
|
}
|
||||||
|
const versionInfo = await (0, version_1.getVersion)(mode);
|
||||||
|
return await installBinary(versionInfo, mode);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Install golangci-lint.
|
* Install golangci-lint.
|
||||||
*
|
*
|
||||||
@ -93735,7 +93728,7 @@ const printOutput = (res) => {
|
|||||||
* @param mode installation mode.
|
* @param mode installation mode.
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
async function installLint(versionInfo, mode) {
|
async function installBinary(versionInfo, mode) {
|
||||||
core.info(`Installation mode: ${mode}`);
|
core.info(`Installation mode: ${mode}`);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case InstallMode.Binary:
|
case InstallMode.Binary:
|
||||||
@ -93804,11 +93797,36 @@ async function installBin(versionInfo) {
|
|||||||
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
||||||
return binPath;
|
return binPath;
|
||||||
}
|
}
|
||||||
|
function getAssetURL(versionInfo) {
|
||||||
|
let ext = "tar.gz";
|
||||||
|
let platform = os_1.default.platform().toString();
|
||||||
|
switch (platform) {
|
||||||
|
case "win32":
|
||||||
|
platform = "windows";
|
||||||
|
ext = "zip";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let arch = os_1.default.arch();
|
||||||
|
switch (arch) {
|
||||||
|
case "arm64":
|
||||||
|
arch = "arm64";
|
||||||
|
break;
|
||||||
|
case "x64":
|
||||||
|
arch = "amd64";
|
||||||
|
break;
|
||||||
|
case "x32":
|
||||||
|
case "ia32":
|
||||||
|
arch = "386";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const noPrefix = versionInfo.TargetVersion.slice(1);
|
||||||
|
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 9786:
|
/***/ 7161:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -93850,38 +93868,20 @@ 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.run = run;
|
exports.isOnlyNewIssues = isOnlyNewIssues;
|
||||||
exports.postRun = postRun;
|
exports.fetchPatch = fetchPatch;
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const github = __importStar(__nccwpck_require__(3228));
|
const github = __importStar(__nccwpck_require__(3228));
|
||||||
const child_process_1 = __nccwpck_require__(5317);
|
const fs_1 = __importDefault(__nccwpck_require__(9896));
|
||||||
const fs = __importStar(__nccwpck_require__(9896));
|
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||||
const path = __importStar(__nccwpck_require__(6928));
|
|
||||||
const tmp_1 = __nccwpck_require__(1288);
|
const tmp_1 = __nccwpck_require__(1288);
|
||||||
const util_1 = __nccwpck_require__(9023);
|
const util_1 = __nccwpck_require__(9023);
|
||||||
const which_1 = __importDefault(__nccwpck_require__(1189));
|
|
||||||
const cache_1 = __nccwpck_require__(7377);
|
|
||||||
const install_1 = __nccwpck_require__(232);
|
|
||||||
const diffUtils_1 = __nccwpck_require__(3441);
|
const diffUtils_1 = __nccwpck_require__(3441);
|
||||||
const version_1 = __nccwpck_require__(311);
|
const writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
||||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
|
||||||
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 isOnlyNewIssues() {
|
function isOnlyNewIssues() {
|
||||||
return core.getBooleanInput(`only-new-issues`, { required: true });
|
return core.getBooleanInput(`only-new-issues`, { required: true });
|
||||||
}
|
}
|
||||||
async function prepareLint() {
|
|
||||||
const mode = core.getInput("install-mode").toLowerCase();
|
|
||||||
if (mode === install_1.InstallMode.None) {
|
|
||||||
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
|
||||||
if (!binPath) {
|
|
||||||
throw new Error("golangci-lint binary not found in the PATH");
|
|
||||||
}
|
|
||||||
return binPath;
|
|
||||||
}
|
|
||||||
const versionInfo = await (0, version_1.getVersion)(mode);
|
|
||||||
return await (0, install_1.installLint)(versionInfo, mode);
|
|
||||||
}
|
|
||||||
async function fetchPatch() {
|
async function fetchPatch() {
|
||||||
if (!isOnlyNewIssues()) {
|
if (!isOnlyNewIssues()) {
|
||||||
return ``;
|
return ``;
|
||||||
@ -93930,7 +93930,7 @@ async function fetchPullRequestPatch(ctx) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const tempDir = await createTempDir();
|
const tempDir = await createTempDir();
|
||||||
const patchPath = path.join(tempDir, "pull.patch");
|
const patchPath = path_1.default.join(tempDir, "pull.patch");
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||||
return patchPath;
|
return patchPath;
|
||||||
@ -93965,7 +93965,7 @@ async function fetchPushPatch(ctx) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const tempDir = await createTempDir();
|
const tempDir = await createTempDir();
|
||||||
const patchPath = path.join(tempDir, "push.patch");
|
const patchPath = path_1.default.join(tempDir, "push.patch");
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||||
return patchPath;
|
return patchPath;
|
||||||
@ -93975,12 +93975,67 @@ async function fetchPushPatch(ctx) {
|
|||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 9786:
|
||||||
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.run = run;
|
||||||
|
exports.postRun = postRun;
|
||||||
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
|
const github = __importStar(__nccwpck_require__(3228));
|
||||||
|
const child_process_1 = __nccwpck_require__(5317);
|
||||||
|
const fs = __importStar(__nccwpck_require__(9896));
|
||||||
|
const path = __importStar(__nccwpck_require__(6928));
|
||||||
|
const util_1 = __nccwpck_require__(9023);
|
||||||
|
const cache_1 = __nccwpck_require__(7377);
|
||||||
|
const install_1 = __nccwpck_require__(232);
|
||||||
|
const patch_1 = __nccwpck_require__(7161);
|
||||||
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
async function prepareEnv() {
|
async function prepareEnv() {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
await (0, cache_1.restoreCache)();
|
await (0, cache_1.restoreCache)();
|
||||||
const binPath = await prepareLint();
|
const binPath = await (0, install_1.install)();
|
||||||
const patchPath = await fetchPatch();
|
const patchPath = await (0, patch_1.fetchPatch)();
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||||
return { binPath, patchPath };
|
return { binPath, patchPath };
|
||||||
}
|
}
|
||||||
@ -94030,7 +94085,7 @@ async function runLint(binPath, patchPath) {
|
|||||||
}
|
}
|
||||||
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||||
if (isOnlyNewIssues()) {
|
if ((0, patch_1.isOnlyNewIssues)()) {
|
||||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
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`);
|
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||||
}
|
}
|
||||||
@ -94068,6 +94123,12 @@ async function runLint(binPath, patchPath) {
|
|||||||
}
|
}
|
||||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||||
}
|
}
|
||||||
|
if (core.getBooleanInput(`verify`, { required: true })) {
|
||||||
|
const cmdVerify = `${binPath} config verify`;
|
||||||
|
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||||
|
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||||
|
printOutput(res);
|
||||||
|
}
|
||||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
177
dist/run/index.js
generated
vendored
177
dist/run/index.js
generated
vendored
@ -93679,41 +93679,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.InstallMode = void 0;
|
exports.InstallMode = void 0;
|
||||||
exports.installLint = installLint;
|
exports.install = install;
|
||||||
exports.goInstall = goInstall;
|
exports.installBinary = installBinary;
|
||||||
exports.installBin = installBin;
|
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const tc = __importStar(__nccwpck_require__(3472));
|
const tc = __importStar(__nccwpck_require__(3472));
|
||||||
const child_process_1 = __nccwpck_require__(5317);
|
const child_process_1 = __nccwpck_require__(5317);
|
||||||
const os_1 = __importDefault(__nccwpck_require__(857));
|
const os_1 = __importDefault(__nccwpck_require__(857));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||||
const util_1 = __nccwpck_require__(9023);
|
const util_1 = __nccwpck_require__(9023);
|
||||||
|
const which_1 = __importDefault(__nccwpck_require__(1189));
|
||||||
|
const version_1 = __nccwpck_require__(311);
|
||||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
const getAssetURL = (versionInfo) => {
|
|
||||||
let ext = "tar.gz";
|
|
||||||
let platform = os_1.default.platform().toString();
|
|
||||||
switch (platform) {
|
|
||||||
case "win32":
|
|
||||||
platform = "windows";
|
|
||||||
ext = "zip";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let arch = os_1.default.arch();
|
|
||||||
switch (arch) {
|
|
||||||
case "arm64":
|
|
||||||
arch = "arm64";
|
|
||||||
break;
|
|
||||||
case "x64":
|
|
||||||
arch = "amd64";
|
|
||||||
break;
|
|
||||||
case "x32":
|
|
||||||
case "ia32":
|
|
||||||
arch = "386";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const noPrefix = versionInfo.TargetVersion.slice(1);
|
|
||||||
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
|
||||||
};
|
|
||||||
var InstallMode;
|
var InstallMode;
|
||||||
(function (InstallMode) {
|
(function (InstallMode) {
|
||||||
InstallMode["Binary"] = "binary";
|
InstallMode["Binary"] = "binary";
|
||||||
@ -93728,6 +93704,23 @@ const printOutput = (res) => {
|
|||||||
core.info(res.stderr);
|
core.info(res.stderr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
async function install() {
|
||||||
|
const mode = core.getInput("install-mode").toLowerCase();
|
||||||
|
if (mode === InstallMode.None) {
|
||||||
|
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
||||||
|
if (!binPath) {
|
||||||
|
throw new Error("golangci-lint binary not found in the PATH");
|
||||||
|
}
|
||||||
|
return binPath;
|
||||||
|
}
|
||||||
|
const versionInfo = await (0, version_1.getVersion)(mode);
|
||||||
|
return await installBinary(versionInfo, mode);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Install golangci-lint.
|
* Install golangci-lint.
|
||||||
*
|
*
|
||||||
@ -93735,7 +93728,7 @@ const printOutput = (res) => {
|
|||||||
* @param mode installation mode.
|
* @param mode installation mode.
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
async function installLint(versionInfo, mode) {
|
async function installBinary(versionInfo, mode) {
|
||||||
core.info(`Installation mode: ${mode}`);
|
core.info(`Installation mode: ${mode}`);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case InstallMode.Binary:
|
case InstallMode.Binary:
|
||||||
@ -93804,11 +93797,36 @@ async function installBin(versionInfo) {
|
|||||||
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
||||||
return binPath;
|
return binPath;
|
||||||
}
|
}
|
||||||
|
function getAssetURL(versionInfo) {
|
||||||
|
let ext = "tar.gz";
|
||||||
|
let platform = os_1.default.platform().toString();
|
||||||
|
switch (platform) {
|
||||||
|
case "win32":
|
||||||
|
platform = "windows";
|
||||||
|
ext = "zip";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let arch = os_1.default.arch();
|
||||||
|
switch (arch) {
|
||||||
|
case "arm64":
|
||||||
|
arch = "arm64";
|
||||||
|
break;
|
||||||
|
case "x64":
|
||||||
|
arch = "amd64";
|
||||||
|
break;
|
||||||
|
case "x32":
|
||||||
|
case "ia32":
|
||||||
|
arch = "386";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const noPrefix = versionInfo.TargetVersion.slice(1);
|
||||||
|
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 9786:
|
/***/ 7161:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -93850,38 +93868,20 @@ 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.run = run;
|
exports.isOnlyNewIssues = isOnlyNewIssues;
|
||||||
exports.postRun = postRun;
|
exports.fetchPatch = fetchPatch;
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const github = __importStar(__nccwpck_require__(3228));
|
const github = __importStar(__nccwpck_require__(3228));
|
||||||
const child_process_1 = __nccwpck_require__(5317);
|
const fs_1 = __importDefault(__nccwpck_require__(9896));
|
||||||
const fs = __importStar(__nccwpck_require__(9896));
|
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||||
const path = __importStar(__nccwpck_require__(6928));
|
|
||||||
const tmp_1 = __nccwpck_require__(1288);
|
const tmp_1 = __nccwpck_require__(1288);
|
||||||
const util_1 = __nccwpck_require__(9023);
|
const util_1 = __nccwpck_require__(9023);
|
||||||
const which_1 = __importDefault(__nccwpck_require__(1189));
|
|
||||||
const cache_1 = __nccwpck_require__(7377);
|
|
||||||
const install_1 = __nccwpck_require__(232);
|
|
||||||
const diffUtils_1 = __nccwpck_require__(3441);
|
const diffUtils_1 = __nccwpck_require__(3441);
|
||||||
const version_1 = __nccwpck_require__(311);
|
const writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
||||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
|
||||||
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 isOnlyNewIssues() {
|
function isOnlyNewIssues() {
|
||||||
return core.getBooleanInput(`only-new-issues`, { required: true });
|
return core.getBooleanInput(`only-new-issues`, { required: true });
|
||||||
}
|
}
|
||||||
async function prepareLint() {
|
|
||||||
const mode = core.getInput("install-mode").toLowerCase();
|
|
||||||
if (mode === install_1.InstallMode.None) {
|
|
||||||
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
|
||||||
if (!binPath) {
|
|
||||||
throw new Error("golangci-lint binary not found in the PATH");
|
|
||||||
}
|
|
||||||
return binPath;
|
|
||||||
}
|
|
||||||
const versionInfo = await (0, version_1.getVersion)(mode);
|
|
||||||
return await (0, install_1.installLint)(versionInfo, mode);
|
|
||||||
}
|
|
||||||
async function fetchPatch() {
|
async function fetchPatch() {
|
||||||
if (!isOnlyNewIssues()) {
|
if (!isOnlyNewIssues()) {
|
||||||
return ``;
|
return ``;
|
||||||
@ -93930,7 +93930,7 @@ async function fetchPullRequestPatch(ctx) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const tempDir = await createTempDir();
|
const tempDir = await createTempDir();
|
||||||
const patchPath = path.join(tempDir, "pull.patch");
|
const patchPath = path_1.default.join(tempDir, "pull.patch");
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||||
return patchPath;
|
return patchPath;
|
||||||
@ -93965,7 +93965,7 @@ async function fetchPushPatch(ctx) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const tempDir = await createTempDir();
|
const tempDir = await createTempDir();
|
||||||
const patchPath = path.join(tempDir, "push.patch");
|
const patchPath = path_1.default.join(tempDir, "push.patch");
|
||||||
core.info(`Writing patch to ${patchPath}`);
|
core.info(`Writing patch to ${patchPath}`);
|
||||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||||
return patchPath;
|
return patchPath;
|
||||||
@ -93975,12 +93975,67 @@ async function fetchPushPatch(ctx) {
|
|||||||
return ``; // don't fail the action, but analyze without patch
|
return ``; // don't fail the action, but analyze without patch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 9786:
|
||||||
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.run = run;
|
||||||
|
exports.postRun = postRun;
|
||||||
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
|
const github = __importStar(__nccwpck_require__(3228));
|
||||||
|
const child_process_1 = __nccwpck_require__(5317);
|
||||||
|
const fs = __importStar(__nccwpck_require__(9896));
|
||||||
|
const path = __importStar(__nccwpck_require__(6928));
|
||||||
|
const util_1 = __nccwpck_require__(9023);
|
||||||
|
const cache_1 = __nccwpck_require__(7377);
|
||||||
|
const install_1 = __nccwpck_require__(232);
|
||||||
|
const patch_1 = __nccwpck_require__(7161);
|
||||||
|
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||||
async function prepareEnv() {
|
async function prepareEnv() {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
await (0, cache_1.restoreCache)();
|
await (0, cache_1.restoreCache)();
|
||||||
const binPath = await prepareLint();
|
const binPath = await (0, install_1.install)();
|
||||||
const patchPath = await fetchPatch();
|
const patchPath = await (0, patch_1.fetchPatch)();
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||||
return { binPath, patchPath };
|
return { binPath, patchPath };
|
||||||
}
|
}
|
||||||
@ -94030,7 +94085,7 @@ async function runLint(binPath, patchPath) {
|
|||||||
}
|
}
|
||||||
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim();
|
||||||
if (isOnlyNewIssues()) {
|
if ((0, patch_1.isOnlyNewIssues)()) {
|
||||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
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`);
|
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||||
}
|
}
|
||||||
@ -94068,6 +94123,12 @@ async function runLint(binPath, patchPath) {
|
|||||||
}
|
}
|
||||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||||
}
|
}
|
||||||
|
if (core.getBooleanInput(`verify`, { required: true })) {
|
||||||
|
const cmdVerify = `${binPath} config verify`;
|
||||||
|
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||||
|
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||||
|
printOutput(res);
|
||||||
|
}
|
||||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "golanci-lint-action",
|
"name": "golanci-lint-action",
|
||||||
"version": "6.3.3",
|
"version": "6.4.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "golanci-lint-action",
|
"name": "golanci-lint-action",
|
||||||
"version": "6.3.3",
|
"version": "6.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.0.0",
|
"@actions/cache": "^4.0.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "golanci-lint-action",
|
"name": "golanci-lint-action",
|
||||||
"version": "6.3.3",
|
"version": "6.4.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "golangci-lint github action",
|
"description": "golangci-lint github action",
|
||||||
"main": "dist/main.js",
|
"main": "dist/main.js",
|
||||||
|
6
sample-go-mod/.golangci.yml
Normal file
6
sample-go-mod/.golangci.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
output:
|
||||||
|
show-stats: true
|
||||||
|
sort-results: true
|
||||||
|
sort-order:
|
||||||
|
- linter
|
||||||
|
- file
|
6
sample-go-tool/.golangci.yml
Normal file
6
sample-go-tool/.golangci.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
output:
|
||||||
|
show-stats: true
|
||||||
|
sort-results: true
|
||||||
|
sort-order:
|
||||||
|
- linter
|
||||||
|
- file
|
@ -4,41 +4,12 @@ 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 { promisify } from "util"
|
||||||
|
import which from "which"
|
||||||
|
|
||||||
import { VersionInfo } from "./version"
|
import { getVersion, VersionInfo } from "./version"
|
||||||
|
|
||||||
const execShellCommand = promisify(exec)
|
const execShellCommand = promisify(exec)
|
||||||
|
|
||||||
const getAssetURL = (versionInfo: VersionInfo): string => {
|
|
||||||
let ext = "tar.gz"
|
|
||||||
|
|
||||||
let platform = os.platform().toString()
|
|
||||||
switch (platform) {
|
|
||||||
case "win32":
|
|
||||||
platform = "windows"
|
|
||||||
ext = "zip"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
let arch = os.arch()
|
|
||||||
switch (arch) {
|
|
||||||
case "arm64":
|
|
||||||
arch = "arm64"
|
|
||||||
break
|
|
||||||
case "x64":
|
|
||||||
arch = "amd64"
|
|
||||||
break
|
|
||||||
case "x32":
|
|
||||||
case "ia32":
|
|
||||||
arch = "386"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
const noPrefix = versionInfo.TargetVersion.slice(1)
|
|
||||||
|
|
||||||
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum InstallMode {
|
export enum InstallMode {
|
||||||
Binary = "binary",
|
Binary = "binary",
|
||||||
GoInstall = "goinstall",
|
GoInstall = "goinstall",
|
||||||
@ -59,6 +30,27 @@ const printOutput = (res: ExecRes): void => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function install(): Promise<string> {
|
||||||
|
const mode = core.getInput("install-mode").toLowerCase()
|
||||||
|
|
||||||
|
if (mode === InstallMode.None) {
|
||||||
|
const binPath = await which("golangci-lint", { nothrow: true })
|
||||||
|
if (!binPath) {
|
||||||
|
throw new Error("golangci-lint binary not found in the PATH")
|
||||||
|
}
|
||||||
|
return binPath
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionInfo = await getVersion(<InstallMode>mode)
|
||||||
|
|
||||||
|
return await installBinary(versionInfo, <InstallMode>mode)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install golangci-lint.
|
* Install golangci-lint.
|
||||||
*
|
*
|
||||||
@ -66,7 +58,7 @@ const printOutput = (res: ExecRes): void => {
|
|||||||
* @param mode installation mode.
|
* @param mode installation mode.
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
export async function installLint(versionInfo: VersionInfo, mode: InstallMode): Promise<string> {
|
export async function installBinary(versionInfo: VersionInfo, mode: InstallMode): Promise<string> {
|
||||||
core.info(`Installation mode: ${mode}`)
|
core.info(`Installation mode: ${mode}`)
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@ -85,7 +77,7 @@ export async function installLint(versionInfo: VersionInfo, mode: InstallMode):
|
|||||||
* @param versionInfo information about version to install.
|
* @param versionInfo information about version to install.
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
export async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
||||||
core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`)
|
core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
@ -125,7 +117,7 @@ export async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
|||||||
* @param versionInfo information about version to install.
|
* @param versionInfo information about version to install.
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
export async function installBin(versionInfo: VersionInfo): Promise<string> {
|
async function installBin(versionInfo: VersionInfo): Promise<string> {
|
||||||
core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`)
|
core.info(`Installing golangci-lint binary ${versionInfo.TargetVersion}...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
@ -158,3 +150,33 @@ export async function installBin(versionInfo: VersionInfo): Promise<string> {
|
|||||||
|
|
||||||
return binPath
|
return binPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAssetURL(versionInfo: VersionInfo): string {
|
||||||
|
let ext = "tar.gz"
|
||||||
|
|
||||||
|
let platform = os.platform().toString()
|
||||||
|
switch (platform) {
|
||||||
|
case "win32":
|
||||||
|
platform = "windows"
|
||||||
|
ext = "zip"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
let arch = os.arch()
|
||||||
|
switch (arch) {
|
||||||
|
case "arm64":
|
||||||
|
arch = "arm64"
|
||||||
|
break
|
||||||
|
case "x64":
|
||||||
|
arch = "amd64"
|
||||||
|
break
|
||||||
|
case "x32":
|
||||||
|
case "ia32":
|
||||||
|
arch = "386"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
const noPrefix = versionInfo.TargetVersion.slice(1)
|
||||||
|
|
||||||
|
return `https://github.com/golangci/golangci-lint/releases/download/${versionInfo.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
||||||
|
}
|
||||||
|
119
src/patch.ts
Normal file
119
src/patch.ts
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
import * as core from "@actions/core"
|
||||||
|
import * as github from "@actions/github"
|
||||||
|
import { Context } from "@actions/github/lib/context"
|
||||||
|
import fs from "fs"
|
||||||
|
import path from "path"
|
||||||
|
import { dir } from "tmp"
|
||||||
|
import { promisify } from "util"
|
||||||
|
|
||||||
|
import { alterDiffPatch } from "./utils/diffUtils"
|
||||||
|
|
||||||
|
const writeFile = promisify(fs.writeFile)
|
||||||
|
const createTempDir = promisify(dir)
|
||||||
|
|
||||||
|
export function isOnlyNewIssues(): boolean {
|
||||||
|
return core.getBooleanInput(`only-new-issues`, { required: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchPatch(): Promise<string> {
|
||||||
|
if (!isOnlyNewIssues()) {
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
|
||||||
|
const ctx = github.context
|
||||||
|
|
||||||
|
switch (ctx.eventName) {
|
||||||
|
case `pull_request`:
|
||||||
|
case `pull_request_target`:
|
||||||
|
return await fetchPullRequestPatch(ctx)
|
||||||
|
case `push`:
|
||||||
|
return await fetchPushPatch(ctx)
|
||||||
|
case `merge_group`:
|
||||||
|
return ``
|
||||||
|
default:
|
||||||
|
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`)
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchPullRequestPatch(ctx: Context): Promise<string> {
|
||||||
|
const pr = ctx.payload.pull_request
|
||||||
|
if (!pr) {
|
||||||
|
core.warning(`No pull request in context`)
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
|
||||||
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||||
|
|
||||||
|
let patch: string
|
||||||
|
try {
|
||||||
|
const patchResp = await octokit.rest.pulls.get({
|
||||||
|
owner: ctx.repo.owner,
|
||||||
|
repo: ctx.repo.repo,
|
||||||
|
[`pull_number`]: pr.number,
|
||||||
|
mediaType: {
|
||||||
|
format: `diff`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (patchResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch pull request patch: response status is ${patchResp.status}`)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
patch = patchResp.data as any
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`failed to fetch pull request patch:`, err)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tempDir = await createTempDir()
|
||||||
|
const patchPath = path.join(tempDir, "pull.patch")
|
||||||
|
core.info(`Writing patch to ${patchPath}`)
|
||||||
|
await writeFile(patchPath, alterDiffPatch(patch))
|
||||||
|
return patchPath
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`failed to save pull request patch:`, err)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchPushPatch(ctx: Context): Promise<string> {
|
||||||
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||||
|
|
||||||
|
let patch: string
|
||||||
|
try {
|
||||||
|
const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({
|
||||||
|
owner: ctx.repo.owner,
|
||||||
|
repo: ctx.repo.repo,
|
||||||
|
basehead: `${ctx.payload.before}...${ctx.payload.after}`,
|
||||||
|
mediaType: {
|
||||||
|
format: `diff`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (patchResp.status !== 200) {
|
||||||
|
core.warning(`failed to fetch push patch: response status is ${patchResp.status}`)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
patch = patchResp.data as any
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`failed to fetch push patch:`, err)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tempDir = await createTempDir()
|
||||||
|
const patchPath = path.join(tempDir, "push.patch")
|
||||||
|
core.info(`Writing patch to ${patchPath}`)
|
||||||
|
await writeFile(patchPath, alterDiffPatch(patch))
|
||||||
|
return patchPath
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`failed to save pull request patch:`, err)
|
||||||
|
return `` // don't fail the action, but analyze without patch
|
||||||
|
}
|
||||||
|
}
|
144
src/run.ts
144
src/run.ts
@ -1,144 +1,15 @@
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as github from "@actions/github"
|
import * as github from "@actions/github"
|
||||||
import { Context } from "@actions/github/lib/context"
|
|
||||||
import { exec, ExecOptions } from "child_process"
|
import { exec, ExecOptions } from "child_process"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { dir } from "tmp"
|
|
||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
import which from "which"
|
|
||||||
|
|
||||||
import { restoreCache, saveCache } from "./cache"
|
import { restoreCache, saveCache } from "./cache"
|
||||||
import { installLint, InstallMode } from "./install"
|
import { install } from "./install"
|
||||||
import { alterDiffPatch } from "./utils/diffUtils"
|
import { fetchPatch, isOnlyNewIssues } from "./patch"
|
||||||
import { getVersion } from "./version"
|
|
||||||
|
|
||||||
const execShellCommand = promisify(exec)
|
const execShellCommand = promisify(exec)
|
||||||
const writeFile = promisify(fs.writeFile)
|
|
||||||
const createTempDir = promisify(dir)
|
|
||||||
|
|
||||||
function isOnlyNewIssues(): boolean {
|
|
||||||
return core.getBooleanInput(`only-new-issues`, { required: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function prepareLint(): Promise<string> {
|
|
||||||
const mode = core.getInput("install-mode").toLowerCase()
|
|
||||||
|
|
||||||
if (mode === InstallMode.None) {
|
|
||||||
const binPath = await which("golangci-lint", { nothrow: true })
|
|
||||||
if (!binPath) {
|
|
||||||
throw new Error("golangci-lint binary not found in the PATH")
|
|
||||||
}
|
|
||||||
return binPath
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionInfo = await getVersion(<InstallMode>mode)
|
|
||||||
|
|
||||||
return await installLint(versionInfo, <InstallMode>mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchPatch(): Promise<string> {
|
|
||||||
if (!isOnlyNewIssues()) {
|
|
||||||
return ``
|
|
||||||
}
|
|
||||||
|
|
||||||
const ctx = github.context
|
|
||||||
|
|
||||||
switch (ctx.eventName) {
|
|
||||||
case `pull_request`:
|
|
||||||
case `pull_request_target`:
|
|
||||||
return await fetchPullRequestPatch(ctx)
|
|
||||||
case `push`:
|
|
||||||
return await fetchPushPatch(ctx)
|
|
||||||
case `merge_group`:
|
|
||||||
return ``
|
|
||||||
default:
|
|
||||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`)
|
|
||||||
return ``
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchPullRequestPatch(ctx: Context): Promise<string> {
|
|
||||||
const pr = ctx.payload.pull_request
|
|
||||||
if (!pr) {
|
|
||||||
core.warning(`No pull request in context`)
|
|
||||||
return ``
|
|
||||||
}
|
|
||||||
|
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
|
||||||
|
|
||||||
let patch: string
|
|
||||||
try {
|
|
||||||
const patchResp = await octokit.rest.pulls.get({
|
|
||||||
owner: ctx.repo.owner,
|
|
||||||
repo: ctx.repo.repo,
|
|
||||||
[`pull_number`]: pr.number,
|
|
||||||
mediaType: {
|
|
||||||
format: `diff`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (patchResp.status !== 200) {
|
|
||||||
core.warning(`failed to fetch pull request patch: response status is ${patchResp.status}`)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
patch = patchResp.data as any
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`failed to fetch pull request patch:`, err)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const tempDir = await createTempDir()
|
|
||||||
const patchPath = path.join(tempDir, "pull.patch")
|
|
||||||
core.info(`Writing patch to ${patchPath}`)
|
|
||||||
await writeFile(patchPath, alterDiffPatch(patch))
|
|
||||||
return patchPath
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`failed to save pull request patch:`, err)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchPushPatch(ctx: Context): Promise<string> {
|
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
|
||||||
|
|
||||||
let patch: string
|
|
||||||
try {
|
|
||||||
const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({
|
|
||||||
owner: ctx.repo.owner,
|
|
||||||
repo: ctx.repo.repo,
|
|
||||||
basehead: `${ctx.payload.before}...${ctx.payload.after}`,
|
|
||||||
mediaType: {
|
|
||||||
format: `diff`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (patchResp.status !== 200) {
|
|
||||||
core.warning(`failed to fetch push patch: response status is ${patchResp.status}`)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
patch = patchResp.data as any
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`failed to fetch push patch:`, err)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const tempDir = await createTempDir()
|
|
||||||
const patchPath = path.join(tempDir, "push.patch")
|
|
||||||
core.info(`Writing patch to ${patchPath}`)
|
|
||||||
await writeFile(patchPath, alterDiffPatch(patch))
|
|
||||||
return patchPath
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`failed to save pull request patch:`, err)
|
|
||||||
return `` // don't fail the action, but analyze without patch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Env = {
|
type Env = {
|
||||||
binPath: string
|
binPath: string
|
||||||
@ -151,7 +22,7 @@ async function prepareEnv(): Promise<Env> {
|
|||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
await restoreCache()
|
await restoreCache()
|
||||||
|
|
||||||
const binPath = await prepareLint()
|
const binPath = await install()
|
||||||
const patchPath = await fetchPatch()
|
const patchPath = await fetchPatch()
|
||||||
|
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||||
@ -266,6 +137,15 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
|||||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (core.getBooleanInput(`verify`, { required: true })) {
|
||||||
|
const cmdVerify = `${binPath} config verify`
|
||||||
|
|
||||||
|
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||||
|
|
||||||
|
const res = await execShellCommand(cmdVerify, cmdArgs)
|
||||||
|
printOutput(res)
|
||||||
|
}
|
||||||
|
|
||||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
||||||
|
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||||
|
Reference in New Issue
Block a user