Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
2226d7cb06 | |||
8d744d5b7f | |||
0e58f8e7ab | |||
6a3fb764d5 | |||
696fa5c0e7 | |||
80284ede25 | |||
818ec4d51a | |||
1c50240be2 | |||
0adbc47a59 | |||
f7463c56f6 | |||
32f961426b |
2
.github/workflows/codeql.yaml
vendored
2
.github/workflows/codeql.yaml
vendored
@ -3,12 +3,10 @@ name: "Code Scanning - Action"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
schedule:
|
||||
- cron: '0 17 * * 5'
|
||||
|
38
.github/workflows/test.yml
vendored
38
.github/workflows/test.yml
vendored
@ -2,13 +2,10 @@ name: "build-and-test"
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- "releases/*"
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
@ -51,7 +48,7 @@ jobs:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- ubuntu-24.04-arm
|
||||
- ubuntu-22.04-arm
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
version:
|
||||
@ -80,7 +77,7 @@ jobs:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- ubuntu-24.04-arm
|
||||
- ubuntu-22.04-arm
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
version:
|
||||
@ -104,15 +101,18 @@ jobs:
|
||||
only-new-issues: true
|
||||
install-mode: goinstall
|
||||
|
||||
test-go-mod-version:
|
||||
test-go-mod:
|
||||
needs: [ build ]
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- ubuntu-24.04-arm
|
||||
- ubuntu-22.04-arm
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
wd:
|
||||
- sample-go-mod
|
||||
- sample-go-tool
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: read
|
||||
@ -123,27 +123,5 @@ jobs:
|
||||
go-version: oldstable
|
||||
- uses: ./
|
||||
with:
|
||||
working-directory: sample-go-mod
|
||||
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
|
||||
working-directory: ${{ matrix.wd }}
|
||||
args: --timeout=5m --issues-exit-code=0 ./...
|
||||
|
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>
|
||||
|
||||
### `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`
|
||||
|
||||
(optional)
|
||||
|
@ -22,6 +22,10 @@ inputs:
|
||||
description: "the token is used for fetching patch of a pull request to show only new issues"
|
||||
default: ${{ github.token }}
|
||||
required: false
|
||||
verify:
|
||||
description: "if set to true and the action verify the configuration file against the JSONSchema"
|
||||
default: 'true'
|
||||
required: false
|
||||
only-new-issues:
|
||||
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
|
||||
default: 'false'
|
||||
|
213
dist/post_run/index.js
generated
vendored
213
dist/post_run/index.js
generated
vendored
@ -42098,7 +42098,7 @@ module.exports = __toCommonJS(dist_src_exports);
|
||||
var import_universal_user_agent = __nccwpck_require__(3843);
|
||||
|
||||
// pkg/dist-src/version.js
|
||||
var VERSION = "9.0.5";
|
||||
var VERSION = "9.0.6";
|
||||
|
||||
// pkg/dist-src/defaults.js
|
||||
var userAgent = `octokit-endpoint.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`;
|
||||
@ -42203,9 +42203,9 @@ function addQueryParameters(url, parameters) {
|
||||
}
|
||||
|
||||
// pkg/dist-src/util/extract-url-variable-names.js
|
||||
var urlVariableRegex = /\{[^}]+\}/g;
|
||||
var urlVariableRegex = /\{[^{}}]+\}/g;
|
||||
function removeNonChars(variableName) {
|
||||
return variableName.replace(/^\W+|\W+$/g, "").split(/,/);
|
||||
return variableName.replace(/(?:^\W+)|(?:(?<!\W)\W+$)/g, "").split(/,/);
|
||||
}
|
||||
function extractUrlVariableNames(url) {
|
||||
const matches = url.match(urlVariableRegex);
|
||||
@ -42391,7 +42391,7 @@ function parse(options) {
|
||||
}
|
||||
if (url.endsWith("/graphql")) {
|
||||
if (options.mediaType.previews?.length) {
|
||||
const previewsFromAcceptHeader = headers.accept.match(/[\w-]+(?=-preview)/g) || [];
|
||||
const previewsFromAcceptHeader = headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) || [];
|
||||
headers.accept = previewsFromAcceptHeader.concat(options.mediaType.previews).map((preview) => {
|
||||
const format = options.mediaType.format ? `.${options.mediaType.format}` : "+json";
|
||||
return `application/vnd.github.${preview}-preview${format}`;
|
||||
@ -45240,7 +45240,7 @@ var RequestError = class extends Error {
|
||||
if (options.request.headers.authorization) {
|
||||
requestCopy.headers = Object.assign({}, options.request.headers, {
|
||||
authorization: options.request.headers.authorization.replace(
|
||||
/ .*$/,
|
||||
/(?<! ) .*$/,
|
||||
" [REDACTED]"
|
||||
)
|
||||
});
|
||||
@ -93679,41 +93679,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.InstallMode = void 0;
|
||||
exports.installLint = installLint;
|
||||
exports.goInstall = goInstall;
|
||||
exports.installBin = installBin;
|
||||
exports.install = install;
|
||||
exports.installBinary = installBinary;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const tc = __importStar(__nccwpck_require__(3472));
|
||||
const child_process_1 = __nccwpck_require__(5317);
|
||||
const os_1 = __importDefault(__nccwpck_require__(857));
|
||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||
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 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;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
@ -93728,6 +93704,23 @@ const printOutput = (res) => {
|
||||
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.
|
||||
*
|
||||
@ -93735,7 +93728,7 @@ const printOutput = (res) => {
|
||||
* @param mode installation mode.
|
||||
* @returns path to installed binary of golangci-lint.
|
||||
*/
|
||||
async function installLint(versionInfo, mode) {
|
||||
async function installBinary(versionInfo, mode) {
|
||||
core.info(`Installation mode: ${mode}`);
|
||||
switch (mode) {
|
||||
case InstallMode.Binary:
|
||||
@ -93804,11 +93797,36 @@ async function installBin(versionInfo) {
|
||||
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
||||
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__) {
|
||||
|
||||
"use strict";
|
||||
@ -93850,38 +93868,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = run;
|
||||
exports.postRun = postRun;
|
||||
exports.isOnlyNewIssues = isOnlyNewIssues;
|
||||
exports.fetchPatch = fetchPatch;
|
||||
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 fs_1 = __importDefault(__nccwpck_require__(9896));
|
||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||
const tmp_1 = __nccwpck_require__(1288);
|
||||
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 version_1 = __nccwpck_require__(311);
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
||||
const writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
||||
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
||||
function isOnlyNewIssues() {
|
||||
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() {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``;
|
||||
@ -93930,7 +93930,7 @@ async function fetchPullRequestPatch(ctx) {
|
||||
}
|
||||
try {
|
||||
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}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@ -93965,7 +93965,7 @@ async function fetchPushPatch(ctx) {
|
||||
}
|
||||
try {
|
||||
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}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@ -93975,12 +93975,67 @@ async function fetchPushPatch(ctx) {
|
||||
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() {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await (0, cache_1.restoreCache)();
|
||||
const binPath = await prepareLint();
|
||||
const patchPath = await fetchPatch();
|
||||
const binPath = await (0, install_1.install)();
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
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`.
|
||||
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`)) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
}
|
||||
@ -94068,6 +94123,7 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
}
|
||||
await runVerify(binPath, userArgsMap, cmdArgs);
|
||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const startedAt = Date.now();
|
||||
@ -94089,6 +94145,37 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
|
||||
}
|
||||
async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
const verify = core.getBooleanInput(`verify`, { required: true });
|
||||
if (!verify) {
|
||||
return;
|
||||
}
|
||||
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs);
|
||||
if (!cfgPath) {
|
||||
return;
|
||||
}
|
||||
let cmdVerify = `${binPath} config verify`;
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdVerify += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||
printOutput(res);
|
||||
}
|
||||
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
let cmdConfigPath = `${binPath} config path`;
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdConfigPath += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
|
||||
return resPath.stderr.trim();
|
||||
}
|
||||
catch {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
async function run() {
|
||||
try {
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);
|
||||
|
213
dist/run/index.js
generated
vendored
213
dist/run/index.js
generated
vendored
@ -42098,7 +42098,7 @@ module.exports = __toCommonJS(dist_src_exports);
|
||||
var import_universal_user_agent = __nccwpck_require__(3843);
|
||||
|
||||
// pkg/dist-src/version.js
|
||||
var VERSION = "9.0.5";
|
||||
var VERSION = "9.0.6";
|
||||
|
||||
// pkg/dist-src/defaults.js
|
||||
var userAgent = `octokit-endpoint.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`;
|
||||
@ -42203,9 +42203,9 @@ function addQueryParameters(url, parameters) {
|
||||
}
|
||||
|
||||
// pkg/dist-src/util/extract-url-variable-names.js
|
||||
var urlVariableRegex = /\{[^}]+\}/g;
|
||||
var urlVariableRegex = /\{[^{}}]+\}/g;
|
||||
function removeNonChars(variableName) {
|
||||
return variableName.replace(/^\W+|\W+$/g, "").split(/,/);
|
||||
return variableName.replace(/(?:^\W+)|(?:(?<!\W)\W+$)/g, "").split(/,/);
|
||||
}
|
||||
function extractUrlVariableNames(url) {
|
||||
const matches = url.match(urlVariableRegex);
|
||||
@ -42391,7 +42391,7 @@ function parse(options) {
|
||||
}
|
||||
if (url.endsWith("/graphql")) {
|
||||
if (options.mediaType.previews?.length) {
|
||||
const previewsFromAcceptHeader = headers.accept.match(/[\w-]+(?=-preview)/g) || [];
|
||||
const previewsFromAcceptHeader = headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) || [];
|
||||
headers.accept = previewsFromAcceptHeader.concat(options.mediaType.previews).map((preview) => {
|
||||
const format = options.mediaType.format ? `.${options.mediaType.format}` : "+json";
|
||||
return `application/vnd.github.${preview}-preview${format}`;
|
||||
@ -45240,7 +45240,7 @@ var RequestError = class extends Error {
|
||||
if (options.request.headers.authorization) {
|
||||
requestCopy.headers = Object.assign({}, options.request.headers, {
|
||||
authorization: options.request.headers.authorization.replace(
|
||||
/ .*$/,
|
||||
/(?<! ) .*$/,
|
||||
" [REDACTED]"
|
||||
)
|
||||
});
|
||||
@ -93679,41 +93679,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.InstallMode = void 0;
|
||||
exports.installLint = installLint;
|
||||
exports.goInstall = goInstall;
|
||||
exports.installBin = installBin;
|
||||
exports.install = install;
|
||||
exports.installBinary = installBinary;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const tc = __importStar(__nccwpck_require__(3472));
|
||||
const child_process_1 = __nccwpck_require__(5317);
|
||||
const os_1 = __importDefault(__nccwpck_require__(857));
|
||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||
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 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;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
@ -93728,6 +93704,23 @@ const printOutput = (res) => {
|
||||
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.
|
||||
*
|
||||
@ -93735,7 +93728,7 @@ const printOutput = (res) => {
|
||||
* @param mode installation mode.
|
||||
* @returns path to installed binary of golangci-lint.
|
||||
*/
|
||||
async function installLint(versionInfo, mode) {
|
||||
async function installBinary(versionInfo, mode) {
|
||||
core.info(`Installation mode: ${mode}`);
|
||||
switch (mode) {
|
||||
case InstallMode.Binary:
|
||||
@ -93804,11 +93797,36 @@ async function installBin(versionInfo) {
|
||||
core.info(`Installed golangci-lint into ${binPath} in ${Date.now() - startedAt}ms`);
|
||||
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__) {
|
||||
|
||||
"use strict";
|
||||
@ -93850,38 +93868,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = run;
|
||||
exports.postRun = postRun;
|
||||
exports.isOnlyNewIssues = isOnlyNewIssues;
|
||||
exports.fetchPatch = fetchPatch;
|
||||
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 fs_1 = __importDefault(__nccwpck_require__(9896));
|
||||
const path_1 = __importDefault(__nccwpck_require__(6928));
|
||||
const tmp_1 = __nccwpck_require__(1288);
|
||||
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 version_1 = __nccwpck_require__(311);
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
||||
const writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
||||
const createTempDir = (0, util_1.promisify)(tmp_1.dir);
|
||||
function isOnlyNewIssues() {
|
||||
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() {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``;
|
||||
@ -93930,7 +93930,7 @@ async function fetchPullRequestPatch(ctx) {
|
||||
}
|
||||
try {
|
||||
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}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@ -93965,7 +93965,7 @@ async function fetchPushPatch(ctx) {
|
||||
}
|
||||
try {
|
||||
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}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@ -93975,12 +93975,67 @@ async function fetchPushPatch(ctx) {
|
||||
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() {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await (0, cache_1.restoreCache)();
|
||||
const binPath = await prepareLint();
|
||||
const patchPath = await fetchPatch();
|
||||
const binPath = await (0, install_1.install)();
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
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`.
|
||||
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`)) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
}
|
||||
@ -94068,6 +94123,7 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
}
|
||||
await runVerify(binPath, userArgsMap, cmdArgs);
|
||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd();
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const startedAt = Date.now();
|
||||
@ -94089,6 +94145,37 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
|
||||
}
|
||||
async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
const verify = core.getBooleanInput(`verify`, { required: true });
|
||||
if (!verify) {
|
||||
return;
|
||||
}
|
||||
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs);
|
||||
if (!cfgPath) {
|
||||
return;
|
||||
}
|
||||
let cmdVerify = `${binPath} config verify`;
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdVerify += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||
printOutput(res);
|
||||
}
|
||||
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
let cmdConfigPath = `${binPath} config path`;
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdConfigPath += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
|
||||
return resPath.stderr.trim();
|
||||
}
|
||||
catch {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
async function run() {
|
||||
try {
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv);
|
||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "golanci-lint-action",
|
||||
"version": "6.3.3",
|
||||
"version": "6.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "golanci-lint-action",
|
||||
"version": "6.3.3",
|
||||
"version": "6.5.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^4.0.0",
|
||||
@ -485,9 +485,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/endpoint": {
|
||||
"version": "9.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.5.tgz",
|
||||
"integrity": "sha512-ekqR4/+PCLkEBF6qgj8WqJfvDq65RH85OAgrtnVp1mSxaXF03u2xW/hUdweGS5654IlC0wkNYC18Z50tSYTAFw==",
|
||||
"version": "9.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.6.tgz",
|
||||
"integrity": "sha512-H1fNTMA57HbkFESSt3Y9+FBICv+0jFceJFPWDePYlR/iMGrwM5ph+Dd4XRQs+8X+PUFURLQgX9ChPfhJ/1uNQw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.1.0",
|
||||
"universal-user-agent": "^6.0.0"
|
||||
@ -583,9 +584,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/request-error": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.0.tgz",
|
||||
"integrity": "sha512-GETXfE05J0+7H2STzekpKObFe765O5dlAKUTLNGeH+x47z7JjXHfsHKo5z21D/o/IOZTUEI6nyWyR+bZVP/n5Q==",
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.1.tgz",
|
||||
"integrity": "sha512-v9iyEQJH6ZntoENr9/yXxjuezh4My67CBSu9r6Ve/05Iu5gNgnisNWOsoJHTP6k0Rr0+HQIpnH+kyammu90q/g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.1.0",
|
||||
"deprecation": "^2.0.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "golanci-lint-action",
|
||||
"version": "6.3.3",
|
||||
"version": "6.5.0",
|
||||
"private": true,
|
||||
"description": "golangci-lint github action",
|
||||
"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 path from "path"
|
||||
import { promisify } from "util"
|
||||
import which from "which"
|
||||
|
||||
import { VersionInfo } from "./version"
|
||||
import { getVersion, VersionInfo } from "./version"
|
||||
|
||||
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 {
|
||||
Binary = "binary",
|
||||
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.
|
||||
*
|
||||
@ -66,7 +58,7 @@ const printOutput = (res: ExecRes): void => {
|
||||
* @param mode installation mode.
|
||||
* @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}`)
|
||||
|
||||
switch (mode) {
|
||||
@ -85,7 +77,7 @@ export async function installLint(versionInfo: VersionInfo, mode: InstallMode):
|
||||
* @param versionInfo information about version to install.
|
||||
* @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}...`)
|
||||
|
||||
const startedAt = Date.now()
|
||||
@ -125,7 +117,7 @@ export async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
||||
* @param versionInfo information about version to install.
|
||||
* @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}...`)
|
||||
|
||||
const startedAt = Date.now()
|
||||
@ -158,3 +150,33 @@ export async function installBin(versionInfo: VersionInfo): Promise<string> {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
175
src/run.ts
175
src/run.ts
@ -1,144 +1,15 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as github from "@actions/github"
|
||||
import { Context } from "@actions/github/lib/context"
|
||||
import { exec, ExecOptions } from "child_process"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { dir } from "tmp"
|
||||
import { promisify } from "util"
|
||||
import which from "which"
|
||||
|
||||
import { restoreCache, saveCache } from "./cache"
|
||||
import { installLint, InstallMode } from "./install"
|
||||
import { alterDiffPatch } from "./utils/diffUtils"
|
||||
import { getVersion } from "./version"
|
||||
import { install } from "./install"
|
||||
import { fetchPatch, isOnlyNewIssues } from "./patch"
|
||||
|
||||
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 = {
|
||||
binPath: string
|
||||
@ -151,7 +22,7 @@ async function prepareEnv(): Promise<Env> {
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await restoreCache()
|
||||
|
||||
const binPath = await prepareLint()
|
||||
const binPath = await install()
|
||||
const patchPath = await fetchPatch()
|
||||
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||
@ -266,6 +137,8 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||
}
|
||||
|
||||
await runVerify(binPath, userArgsMap, cmdArgs)
|
||||
|
||||
const cmd = `${binPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
||||
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
@ -290,6 +163,44 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`)
|
||||
}
|
||||
|
||||
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<void> {
|
||||
const verify = core.getBooleanInput(`verify`, { required: true })
|
||||
if (!verify) {
|
||||
return
|
||||
}
|
||||
|
||||
const cfgPath = await getConfigPath(binPath, userArgsMap, cmdArgs)
|
||||
if (!cfgPath) {
|
||||
return
|
||||
}
|
||||
|
||||
let cmdVerify = `${binPath} config verify`
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdVerify += ` --config=${userArgsMap.get("config")}`
|
||||
}
|
||||
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs)
|
||||
printOutput(res)
|
||||
}
|
||||
|
||||
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptions): Promise<string> {
|
||||
let cmdConfigPath = `${binPath} config path`
|
||||
if (userArgsMap.get("config")) {
|
||||
cmdConfigPath += ` --config=${userArgsMap.get("config")}`
|
||||
}
|
||||
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs)
|
||||
return resPath.stderr.trim()
|
||||
} catch {
|
||||
return ``
|
||||
}
|
||||
}
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
|
||||
|
Reference in New Issue
Block a user