mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2026-01-16 04:14:30 +07:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7fa5ac41e | ||
|
|
f3ae99f5f5 | ||
|
|
1dfda283ac | ||
|
|
8b0f9424d0 | ||
|
|
a77756c838 | ||
|
|
37a9fafcae | ||
|
|
199a9c2889 | ||
|
|
c7c1219093 |
27
.github/workflows/test.yml
vendored
27
.github/workflows/test.yml
vendored
@@ -146,3 +146,30 @@ jobs:
|
||||
version: ${{ matrix.version }}
|
||||
working-directory: sample-plugins
|
||||
args: --timeout=5m --issues-exit-code=0 ./...
|
||||
|
||||
test-monorepo:
|
||||
needs: [ build ]
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- ubuntu-22.04-arm
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24.x
|
||||
- uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version: oldstable
|
||||
- uses: ./
|
||||
with:
|
||||
working-directory: sample-monorepo
|
||||
experimental: "automatic-module-directories"
|
||||
args: --timeout=5m --issues-exit-code=0 ./...
|
||||
|
||||
235
README.md
235
README.md
@@ -54,9 +54,9 @@ jobs:
|
||||
with:
|
||||
go-version: stable
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: v2.1
|
||||
version: v2.6
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -92,9 +92,9 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: v2.1
|
||||
version: v2.6
|
||||
```
|
||||
|
||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
|
||||
@@ -120,7 +120,7 @@ on:
|
||||
|
||||
env:
|
||||
GO_VERSION: stable
|
||||
GOLANGCI_LINT_VERSION: v2.1
|
||||
GOLANGCI_LINT_VERSION: v2.6
|
||||
|
||||
jobs:
|
||||
detect-modules:
|
||||
@@ -147,7 +147,7 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: golangci-lint ${{ matrix.modules }}
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: ${{ env.GOLANGCI_LINT_VERSION }}
|
||||
working-directory: ${{ matrix.modules }}
|
||||
@@ -179,7 +179,7 @@ jobs:
|
||||
with:
|
||||
os: ${{ matrix.os }}
|
||||
go-version: ${{ matrix.go-version }}
|
||||
golangci-lint-version: v2.1
|
||||
golangci-lint-version: v2.6
|
||||
```
|
||||
|
||||
```yaml
|
||||
@@ -201,7 +201,7 @@ on:
|
||||
golangci-lint-version:
|
||||
description: 'Golangci-lint version'
|
||||
type: string
|
||||
default: 'v2.1'
|
||||
default: 'v2.6'
|
||||
|
||||
jobs:
|
||||
detect-modules:
|
||||
@@ -229,7 +229,7 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ inputs.go-version }}
|
||||
- name: golangci-lint ${{ matrix.modules }}
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: ${{ inputs.golangci-lint-version }}
|
||||
working-directory: ${{ matrix.modules }}
|
||||
@@ -259,7 +259,27 @@ You will also likely need to add the following `.gitattributes` file to ensure t
|
||||
|
||||
## Options
|
||||
|
||||
### `version`
|
||||
### Overview
|
||||
|
||||
| Option | Description |
|
||||
|---------------------------------------------------------------|----------------------------------------------------|
|
||||
| [`version`](#version) | The version of golangci-lint to use. |
|
||||
| [`install-mode`](#install-mode) | The mode to install golangci-lint. |
|
||||
| [`install-only`](#install-only) | Only install golangci-lint. |
|
||||
| [`verify`](#verify) | Validates golangci-lint configuration file. |
|
||||
| [`github-token`](#github-token) | Used by the `only-new-issues` option. |
|
||||
| [`only-new-issues`](#only-new-issues) | Show only new issues. |
|
||||
| [`working-directory`](#working-directory) | The golangci-lint working directory. |
|
||||
| [`args`](#args) | Golangci-lint command line arguments. |
|
||||
| [`skip-cache`](#skip-cache) | Disable cache support. |
|
||||
| [`skip-save-cache`](#skip-save-cache) | Don't save cache. |
|
||||
| [`cache-invalidation-interval`](#cache-invalidation-interval) | Number of days before cache invalidation. |
|
||||
| [`problem-matchers`](#problem-matchers) | Forces the usage of the embedded problem matchers. |
|
||||
| [Experimental](#experimental) | Experimental options |
|
||||
|
||||
### Installation
|
||||
|
||||
#### `version`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -274,15 +294,15 @@ When `install-mode` is:
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: v2.1
|
||||
version: v2.6
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `install-mode`
|
||||
#### `install-mode`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -296,7 +316,7 @@ The default value is `binary`.
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
install-mode: "none"
|
||||
# ...
|
||||
@@ -304,7 +324,7 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `install-only`
|
||||
#### `install-only`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -317,7 +337,7 @@ The default value is `false`.
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
install-only: true
|
||||
# ...
|
||||
@@ -325,27 +345,9 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `github-token`
|
||||
### Run
|
||||
|
||||
(optional)
|
||||
|
||||
When using the `only-new-issues` option, the GitHub API is used, so a token is required.
|
||||
|
||||
By default, it uses the `github.token` from the action.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
github-token: xxx
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `verify`
|
||||
#### `verify`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -360,7 +362,7 @@ The JSON Schema used to validate the configuration depends on the version of gol
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
verify: false
|
||||
# ...
|
||||
@@ -368,7 +370,27 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `only-new-issues`
|
||||
#### `github-token`
|
||||
|
||||
(optional)
|
||||
|
||||
When using the `only-new-issues` option, the GitHub API is used, so a token is required.
|
||||
|
||||
By default, it uses the `github.token` from the action.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
github-token: xxx
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### `only-new-issues`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -385,7 +407,7 @@ The default value is `false`.
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
only-new-issues: true
|
||||
# ...
|
||||
@@ -393,7 +415,7 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `working-directory`
|
||||
#### `working-directory`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -403,7 +425,7 @@ The golangci-lint working directory, useful for monorepos. The default is the pr
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
working-directory: somedir
|
||||
# ...
|
||||
@@ -411,7 +433,7 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `args`
|
||||
#### `args`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -428,7 +450,7 @@ golangci-lint command line arguments.
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
# In some rare cases,
|
||||
# you may need to use `${{ github.workspace }}` as the base directory to reference your configuration file.
|
||||
@@ -438,7 +460,74 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `problem-matchers`
|
||||
### Cache
|
||||
|
||||
#### `skip-cache`
|
||||
|
||||
(optional)
|
||||
|
||||
If set to `true`, all caching functionality will be completely disabled.
|
||||
This takes precedence over all other caching options.
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
skip-cache: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### `skip-save-cache`
|
||||
|
||||
(optional)
|
||||
|
||||
If set to `true`, caches will not be saved, but they may still be restored, requiring `skip-cache: false`.
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
skip-save-cache: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### `cache-invalidation-interval`
|
||||
|
||||
(optional)
|
||||
|
||||
Periodically invalidate a cache every `cache-invalidation-interval` days to ensure that outdated data is removed and fresh data is loaded.
|
||||
|
||||
The default value is `7`.
|
||||
|
||||
If the number is `<= 0`, the cache will always be invalidated (not recommended).
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
cache-invalidation-interval: 15
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Extra
|
||||
|
||||
#### `problem-matchers`
|
||||
|
||||
(optional)
|
||||
|
||||
@@ -456,7 +545,7 @@ The default value is `false`.
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
problem-matchers: true
|
||||
# ...
|
||||
@@ -464,65 +553,43 @@ with:
|
||||
|
||||
</details>
|
||||
|
||||
### `skip-cache`
|
||||
### Experimental
|
||||
|
||||
(optional)
|
||||
The following options are experimental: those may or may not be supported in the future, and so they will be either converted into a dedicated option or removed.
|
||||
|
||||
If set to `true`, all caching functionality will be completely disabled.
|
||||
This takes precedence over all other caching options.
|
||||
|
||||
The default value is `false`.
|
||||
List of comma-separated options.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
```yaml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
skip-cache: true
|
||||
# ...
|
||||
experimental: "foo,bar"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `skip-save-cache`
|
||||
#### `automatic-module-directories`
|
||||
|
||||
(optional)
|
||||
|
||||
If set to `true`, caches will not be saved, but they may still be restored, requiring `skip-cache: false`.
|
||||
This option will run golangci-lint in each module directory, useful for monorepos.
|
||||
|
||||
The default value is `false`.
|
||||
The automatic detection of modules uses the `working-directory` as the base directory if defined, otherwise the root directory.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> - The cache key will refer to the `working-directory` (if defined) because all the golangci-lint runs must use the same cache directory/key.
|
||||
> - The version detection will only work if the project has a single module.
|
||||
> - If the project has multiple modules, the custom build file must be located in the repository root ( or `working-directory`).
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
```yaml
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
skip-save-cache: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `cache-invalidation-interval`
|
||||
|
||||
(optional)
|
||||
|
||||
Periodically invalidate a cache every `cache-invalidation-interval` days to ensure that outdated data is removed and fresh data is loaded.
|
||||
|
||||
The default value is `7`.
|
||||
|
||||
If the number is `<= 0`, the cache will always be invalidated (not recommended).
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
cache-invalidation-interval: 15
|
||||
# ...
|
||||
experimental: "automatic-module-directories"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
27
action.yml
27
action.yml
@@ -34,6 +34,10 @@ inputs:
|
||||
description: "If set to true and the action runs on a pull request, the action outputs only newly found issues."
|
||||
default: 'false'
|
||||
required: false
|
||||
args:
|
||||
description: "golangci-lint command line arguments."
|
||||
default: ""
|
||||
required: false
|
||||
skip-cache:
|
||||
description: |
|
||||
If set to true, all caching functionality will be completely disabled.
|
||||
@@ -42,21 +46,30 @@ inputs:
|
||||
required: false
|
||||
skip-save-cache:
|
||||
description: |
|
||||
If set to true, the action will not save any caches, but it may still
|
||||
restore existing caches, subject to other options.
|
||||
If set to true, the action will not save any caches,
|
||||
but it may still restore existing caches, subject to other options.
|
||||
default: 'false'
|
||||
required: false
|
||||
cache-invalidation-interval:
|
||||
description: "Periodically invalidate a cache when new code is added (number of days)."
|
||||
default: '7'
|
||||
required: false
|
||||
problem-matchers:
|
||||
description: "Force the usage of the embedded problem matchers."
|
||||
default: 'false'
|
||||
required: false
|
||||
args:
|
||||
description: "golangci-lint command line arguments."
|
||||
debug:
|
||||
description: |
|
||||
Debug options for the action.
|
||||
List of comma separated options, the values are `cache`, `clean`.
|
||||
example: "cache,clean"
|
||||
default: ""
|
||||
required: false
|
||||
cache-invalidation-interval:
|
||||
description: "Periodically invalidate a cache when new code is added (number of days)."
|
||||
default: '7'
|
||||
experimental:
|
||||
description: |
|
||||
Experimental options for the action.
|
||||
List of comma separated options.
|
||||
default: ""
|
||||
required: false
|
||||
runs:
|
||||
using: "node24"
|
||||
|
||||
193
dist/post_run/index.js
generated
vendored
193
dist/post_run/index.js
generated
vendored
@@ -96844,8 +96844,10 @@ async function buildCacheKeys() {
|
||||
return keys;
|
||||
}
|
||||
async function restoreCache() {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true }))
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache restoration`);
|
||||
return;
|
||||
}
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
||||
return;
|
||||
@@ -96881,10 +96883,14 @@ async function restoreCache() {
|
||||
}
|
||||
}
|
||||
async function saveCache() {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true }))
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`);
|
||||
return;
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true }))
|
||||
}
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`);
|
||||
return;
|
||||
}
|
||||
// Validate inputs, this can cause task failure
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
||||
@@ -96999,12 +97005,13 @@ exports.installBinary = installBinary;
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
const tc = __importStar(__nccwpck_require__(33472));
|
||||
const child_process_1 = __nccwpck_require__(35317);
|
||||
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
||||
const os_1 = __importDefault(__nccwpck_require__(70857));
|
||||
const path_1 = __importDefault(__nccwpck_require__(16928));
|
||||
const util_1 = __nccwpck_require__(39023);
|
||||
const which_1 = __importDefault(__nccwpck_require__(11189));
|
||||
const version_1 = __nccwpck_require__(311);
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
var InstallMode;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
@@ -97018,6 +97025,7 @@ const printOutput = (res) => {
|
||||
if (res.stderr) {
|
||||
core.info(res.stderr);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
/**
|
||||
* Install golangci-lint.
|
||||
@@ -97025,6 +97033,15 @@ const printOutput = (res) => {
|
||||
* @returns path to installed binary of golangci-lint.
|
||||
*/
|
||||
async function install() {
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path_1.default.join(__dirname, "../..", "problem-matchers.json");
|
||||
if (fs_1.default.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`);
|
||||
}
|
||||
}
|
||||
const mode = core.getInput("install-mode").toLowerCase();
|
||||
if (mode === InstallMode.None) {
|
||||
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
||||
@@ -97064,10 +97081,8 @@ async function goInstall(versionInfo) {
|
||||
core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`);
|
||||
const startedAt = Date.now();
|
||||
const options = { env: { ...process.env, CGO_ENABLED: "1" } };
|
||||
const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
|
||||
printOutput(exres);
|
||||
const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
|
||||
printOutput(res);
|
||||
await execCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(printOutput);
|
||||
const res = await execCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(printOutput);
|
||||
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||
const binPath = res.stderr
|
||||
.split(/\r?\n/)
|
||||
@@ -97196,9 +97211,6 @@ function isOnlyNewIssues() {
|
||||
return core.getBooleanInput(`only-new-issues`, { required: true });
|
||||
}
|
||||
async function fetchPatch() {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``;
|
||||
}
|
||||
const ctx = github.context;
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
@@ -97242,8 +97254,7 @@ async function fetchPullRequestPatch(ctx) {
|
||||
return ``; // don't fail the action, but analyze without patch
|
||||
}
|
||||
try {
|
||||
const tempDir = await createTempDir();
|
||||
const patchPath = path_1.default.join(tempDir, "pull.patch");
|
||||
const patchPath = await createTempDir().then((tempDir) => path_1.default.join(tempDir, "pull.patch"));
|
||||
core.info(`Writing patch to ${patchPath}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@@ -97277,8 +97288,7 @@ async function fetchPushPatch(ctx) {
|
||||
return ``; // don't fail the action, but analyze without patch
|
||||
}
|
||||
try {
|
||||
const tempDir = await createTempDir();
|
||||
const patchPath = path_1.default.join(tempDir, "push.patch");
|
||||
const patchPath = await createTempDir().then((tempDir) => path_1.default.join(tempDir, "push.patch"));
|
||||
core.info(`Writing patch to ${patchPath}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@@ -97341,7 +97351,7 @@ const fs = __importStar(__nccwpck_require__(79896));
|
||||
const path = __importStar(__nccwpck_require__(16928));
|
||||
const util_1 = __nccwpck_require__(39023);
|
||||
const yaml_1 = __importDefault(__nccwpck_require__(38815));
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const printOutput = (res) => {
|
||||
if (res.stdout) {
|
||||
core.info(res.stdout);
|
||||
@@ -97361,11 +97371,12 @@ async function install(binPath) {
|
||||
else {
|
||||
rootDir = process.cwd();
|
||||
}
|
||||
const configFile = [".custom-gcl.yml", ".custom-gcl.yaml", ".custom-gcl.json"]
|
||||
.map((v) => path.join(rootDir, v))
|
||||
const configFile = ["yml", "yaml", "json"]
|
||||
.map((ext) => `.custom-gcl.${ext}`)
|
||||
.map((filename) => path.join(rootDir, filename))
|
||||
.find((filePath) => fs.existsSync(filePath));
|
||||
if (!configFile || configFile === "") {
|
||||
return "";
|
||||
return binPath;
|
||||
}
|
||||
core.info(`Found configuration for the plugin module system : ${configFile}`);
|
||||
core.info(`Building and installing custom golangci-lint binary...`);
|
||||
@@ -97373,7 +97384,7 @@ async function install(binPath) {
|
||||
const config = yaml_1.default.parse(fs.readFileSync(configFile, "utf-8"));
|
||||
const v = core.getInput(`version`);
|
||||
if (v !== "" && config.version !== v) {
|
||||
core.warning(`The golangci-lint version (${config.version}) defined inside in ${configFile} does not match the version defined in the action (${v})`);
|
||||
core.warning(`The golangci-lint version (${config.version}) defined inside ${configFile} does not match the version defined in the action (${v})`);
|
||||
}
|
||||
if (!config.destination) {
|
||||
config.destination = ".";
|
||||
@@ -97387,18 +97398,16 @@ async function install(binPath) {
|
||||
}
|
||||
const cmd = `${binPath} custom`;
|
||||
core.info(`Running [${cmd}] in [${rootDir}] ...`);
|
||||
try {
|
||||
const options = {
|
||||
cwd: rootDir,
|
||||
};
|
||||
const res = await execShellCommand(cmd, options);
|
||||
printOutput(res);
|
||||
core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`);
|
||||
return path.join(rootDir, config.destination, config.name);
|
||||
}
|
||||
catch (exc) {
|
||||
const options = {
|
||||
cwd: rootDir,
|
||||
};
|
||||
return execCommand(cmd, options)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`))
|
||||
.then(() => path.join(rootDir, config.destination, config.name))
|
||||
.catch((exc) => {
|
||||
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -97455,24 +97464,7 @@ const cache_1 = __nccwpck_require__(97377);
|
||||
const install_1 = __nccwpck_require__(90232);
|
||||
const patch_1 = __nccwpck_require__(47161);
|
||||
const plugins = __importStar(__nccwpck_require__(96067));
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
async function prepareEnv(installOnly) {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await (0, cache_1.restoreCache)();
|
||||
let binPath = await (0, install_1.install)();
|
||||
// Build custom golangci-lint if needed.
|
||||
const customBinPath = await plugins.install(binPath);
|
||||
if (customBinPath !== "") {
|
||||
binPath = customBinPath;
|
||||
}
|
||||
if (installOnly) {
|
||||
return { binPath, patchPath: `` };
|
||||
}
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
return { binPath, patchPath };
|
||||
}
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const printOutput = (res) => {
|
||||
if (res.stdout) {
|
||||
core.info(res.stdout);
|
||||
@@ -97481,12 +97473,7 @@ const printOutput = (res) => {
|
||||
core.info(res.stderr);
|
||||
}
|
||||
};
|
||||
async function runLint(binPath, patchPath) {
|
||||
const debug = core.getInput(`debug`);
|
||||
if (debug.split(`,`).includes(`cache`)) {
|
||||
const res = await execShellCommand(`${binPath} cache status`);
|
||||
printOutput(res);
|
||||
}
|
||||
async function runGolangciLint(binPath, rootDir) {
|
||||
const userArgs = core.getInput(`args`);
|
||||
const addedArgs = [];
|
||||
const userArgsList = userArgs
|
||||
@@ -97498,15 +97485,6 @@ async function runLint(binPath, patchPath) {
|
||||
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
||||
const userArgsMap = new Map(userArgsList);
|
||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json");
|
||||
if (fs.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`);
|
||||
}
|
||||
}
|
||||
if ((0, patch_1.isOnlyNewIssues)()) {
|
||||
if (userArgNames.has(`new`) ||
|
||||
userArgNames.has(`new-from-rev`) ||
|
||||
@@ -97515,6 +97493,7 @@ async function runLint(binPath, patchPath) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
}
|
||||
const ctx = github.context;
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`);
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
@@ -97540,27 +97519,21 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
}
|
||||
const cmdArgs = {};
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
if (rootDir) {
|
||||
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
||||
addedArgs.push(`--path-mode=abs`);
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
cmdArgs.cwd = path.resolve(rootDir);
|
||||
}
|
||||
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();
|
||||
try {
|
||||
const res = await execShellCommand(cmd, cmdArgs);
|
||||
printOutput(res);
|
||||
core.info(`golangci-lint found no issues`);
|
||||
}
|
||||
catch (exc) {
|
||||
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
|
||||
return execCommand(cmd, cmdArgs)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`golangci-lint found no issues`))
|
||||
.catch((exc) => {
|
||||
// This logging passes issues to GitHub annotations.
|
||||
printOutput(exc);
|
||||
if (exc.code === 1) {
|
||||
core.setFailed(`issues found`);
|
||||
@@ -97568,8 +97541,8 @@ async function runLint(binPath, patchPath) {
|
||||
else {
|
||||
core.setFailed(`golangci-lint exit with code ${exc.code}`);
|
||||
}
|
||||
}
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
|
||||
})
|
||||
.finally(() => core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`));
|
||||
}
|
||||
async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
const verify = core.getBooleanInput(`verify`, { required: true });
|
||||
@@ -97585,8 +97558,7 @@ async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
cmdVerify += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||
printOutput(res);
|
||||
await execCommand(cmdVerify, cmdArgs).then(printOutput);
|
||||
}
|
||||
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
let cmdConfigPath = `${binPath} config path`;
|
||||
@@ -97595,22 +97567,73 @@ async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
}
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
|
||||
const resPath = await execCommand(cmdConfigPath, cmdArgs);
|
||||
return resPath.stderr.trim();
|
||||
}
|
||||
catch {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
async function debugAction(binPath) {
|
||||
const flags = core.getInput(`debug`).split(`,`);
|
||||
if (flags.includes(`clean`)) {
|
||||
const cmd = `${binPath} cache clean`;
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
await execCommand(cmd).then(printOutput);
|
||||
}
|
||||
if (flags.includes(`cache`)) {
|
||||
const cmd = `${binPath} cache status`;
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
await execCommand(cmd).then(printOutput);
|
||||
}
|
||||
}
|
||||
function getWorkingDirectory() {
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
}
|
||||
return workingDirectory;
|
||||
}
|
||||
function modulesAutoDetection(rootDir) {
|
||||
const o = {
|
||||
cwd: rootDir,
|
||||
exclude: ["**/vendor/**", "**/node_modules/**", "**/.git/**", "**/dist/**"],
|
||||
};
|
||||
const matches = fs.globSync("**/go.mod", o);
|
||||
const dirs = matches
|
||||
.filter((m) => typeof m === "string")
|
||||
.map((m) => path.resolve(rootDir, path.dirname(m)))
|
||||
.sort();
|
||||
return [...new Set(dirs)];
|
||||
}
|
||||
async function runLint(binPath) {
|
||||
const workingDirectory = getWorkingDirectory();
|
||||
const experimental = core.getInput(`experimental`).split(`,`);
|
||||
if (experimental.includes(`automatic-module-directories`)) {
|
||||
const wds = modulesAutoDetection(workingDirectory);
|
||||
const cwd = process.cwd();
|
||||
for (const wd of wds) {
|
||||
await core.group(`run golangci-lint in ${path.relative(cwd, wd)}`, () => runGolangciLint(binPath, wd));
|
||||
}
|
||||
return;
|
||||
}
|
||||
await core.group(`run golangci-lint`, () => runGolangciLint(binPath, workingDirectory));
|
||||
}
|
||||
async function run() {
|
||||
try {
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true });
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, () => prepareEnv(installOnly));
|
||||
await core.group(`Restore cache`, cache_1.restoreCache);
|
||||
const binPath = await core.group(`Install`, () => (0, install_1.install)().then(plugins.install));
|
||||
core.addPath(path.dirname(binPath));
|
||||
if (core.getInput(`debug`)) {
|
||||
await core.group(`Debug`, () => debugAction(binPath));
|
||||
}
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true });
|
||||
if (installOnly) {
|
||||
return;
|
||||
}
|
||||
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath));
|
||||
await runLint(binPath);
|
||||
}
|
||||
catch (error) {
|
||||
core.error(`Failed to run: ${error}, ${error.stack}`);
|
||||
|
||||
193
dist/run/index.js
generated
vendored
193
dist/run/index.js
generated
vendored
@@ -96844,8 +96844,10 @@ async function buildCacheKeys() {
|
||||
return keys;
|
||||
}
|
||||
async function restoreCache() {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true }))
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache restoration`);
|
||||
return;
|
||||
}
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
||||
return;
|
||||
@@ -96881,10 +96883,14 @@ async function restoreCache() {
|
||||
}
|
||||
}
|
||||
async function saveCache() {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true }))
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`);
|
||||
return;
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true }))
|
||||
}
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`);
|
||||
return;
|
||||
}
|
||||
// Validate inputs, this can cause task failure
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
||||
@@ -96999,12 +97005,13 @@ exports.installBinary = installBinary;
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
const tc = __importStar(__nccwpck_require__(33472));
|
||||
const child_process_1 = __nccwpck_require__(35317);
|
||||
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
||||
const os_1 = __importDefault(__nccwpck_require__(70857));
|
||||
const path_1 = __importDefault(__nccwpck_require__(16928));
|
||||
const util_1 = __nccwpck_require__(39023);
|
||||
const which_1 = __importDefault(__nccwpck_require__(11189));
|
||||
const version_1 = __nccwpck_require__(311);
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
var InstallMode;
|
||||
(function (InstallMode) {
|
||||
InstallMode["Binary"] = "binary";
|
||||
@@ -97018,6 +97025,7 @@ const printOutput = (res) => {
|
||||
if (res.stderr) {
|
||||
core.info(res.stderr);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
/**
|
||||
* Install golangci-lint.
|
||||
@@ -97025,6 +97033,15 @@ const printOutput = (res) => {
|
||||
* @returns path to installed binary of golangci-lint.
|
||||
*/
|
||||
async function install() {
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path_1.default.join(__dirname, "../..", "problem-matchers.json");
|
||||
if (fs_1.default.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`);
|
||||
}
|
||||
}
|
||||
const mode = core.getInput("install-mode").toLowerCase();
|
||||
if (mode === InstallMode.None) {
|
||||
const binPath = await (0, which_1.default)("golangci-lint", { nothrow: true });
|
||||
@@ -97064,10 +97081,8 @@ async function goInstall(versionInfo) {
|
||||
core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`);
|
||||
const startedAt = Date.now();
|
||||
const options = { env: { ...process.env, CGO_ENABLED: "1" } };
|
||||
const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
|
||||
printOutput(exres);
|
||||
const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options);
|
||||
printOutput(res);
|
||||
await execCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(printOutput);
|
||||
const res = await execCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(printOutput);
|
||||
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||
const binPath = res.stderr
|
||||
.split(/\r?\n/)
|
||||
@@ -97196,9 +97211,6 @@ function isOnlyNewIssues() {
|
||||
return core.getBooleanInput(`only-new-issues`, { required: true });
|
||||
}
|
||||
async function fetchPatch() {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``;
|
||||
}
|
||||
const ctx = github.context;
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
@@ -97242,8 +97254,7 @@ async function fetchPullRequestPatch(ctx) {
|
||||
return ``; // don't fail the action, but analyze without patch
|
||||
}
|
||||
try {
|
||||
const tempDir = await createTempDir();
|
||||
const patchPath = path_1.default.join(tempDir, "pull.patch");
|
||||
const patchPath = await createTempDir().then((tempDir) => path_1.default.join(tempDir, "pull.patch"));
|
||||
core.info(`Writing patch to ${patchPath}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@@ -97277,8 +97288,7 @@ async function fetchPushPatch(ctx) {
|
||||
return ``; // don't fail the action, but analyze without patch
|
||||
}
|
||||
try {
|
||||
const tempDir = await createTempDir();
|
||||
const patchPath = path_1.default.join(tempDir, "push.patch");
|
||||
const patchPath = await createTempDir().then((tempDir) => path_1.default.join(tempDir, "push.patch"));
|
||||
core.info(`Writing patch to ${patchPath}`);
|
||||
await writeFile(patchPath, (0, diffUtils_1.alterDiffPatch)(patch));
|
||||
return patchPath;
|
||||
@@ -97341,7 +97351,7 @@ const fs = __importStar(__nccwpck_require__(79896));
|
||||
const path = __importStar(__nccwpck_require__(16928));
|
||||
const util_1 = __nccwpck_require__(39023);
|
||||
const yaml_1 = __importDefault(__nccwpck_require__(38815));
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const printOutput = (res) => {
|
||||
if (res.stdout) {
|
||||
core.info(res.stdout);
|
||||
@@ -97361,11 +97371,12 @@ async function install(binPath) {
|
||||
else {
|
||||
rootDir = process.cwd();
|
||||
}
|
||||
const configFile = [".custom-gcl.yml", ".custom-gcl.yaml", ".custom-gcl.json"]
|
||||
.map((v) => path.join(rootDir, v))
|
||||
const configFile = ["yml", "yaml", "json"]
|
||||
.map((ext) => `.custom-gcl.${ext}`)
|
||||
.map((filename) => path.join(rootDir, filename))
|
||||
.find((filePath) => fs.existsSync(filePath));
|
||||
if (!configFile || configFile === "") {
|
||||
return "";
|
||||
return binPath;
|
||||
}
|
||||
core.info(`Found configuration for the plugin module system : ${configFile}`);
|
||||
core.info(`Building and installing custom golangci-lint binary...`);
|
||||
@@ -97373,7 +97384,7 @@ async function install(binPath) {
|
||||
const config = yaml_1.default.parse(fs.readFileSync(configFile, "utf-8"));
|
||||
const v = core.getInput(`version`);
|
||||
if (v !== "" && config.version !== v) {
|
||||
core.warning(`The golangci-lint version (${config.version}) defined inside in ${configFile} does not match the version defined in the action (${v})`);
|
||||
core.warning(`The golangci-lint version (${config.version}) defined inside ${configFile} does not match the version defined in the action (${v})`);
|
||||
}
|
||||
if (!config.destination) {
|
||||
config.destination = ".";
|
||||
@@ -97387,18 +97398,16 @@ async function install(binPath) {
|
||||
}
|
||||
const cmd = `${binPath} custom`;
|
||||
core.info(`Running [${cmd}] in [${rootDir}] ...`);
|
||||
try {
|
||||
const options = {
|
||||
cwd: rootDir,
|
||||
};
|
||||
const res = await execShellCommand(cmd, options);
|
||||
printOutput(res);
|
||||
core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`);
|
||||
return path.join(rootDir, config.destination, config.name);
|
||||
}
|
||||
catch (exc) {
|
||||
const options = {
|
||||
cwd: rootDir,
|
||||
};
|
||||
return execCommand(cmd, options)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`))
|
||||
.then(() => path.join(rootDir, config.destination, config.name))
|
||||
.catch((exc) => {
|
||||
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -97455,24 +97464,7 @@ const cache_1 = __nccwpck_require__(97377);
|
||||
const install_1 = __nccwpck_require__(90232);
|
||||
const patch_1 = __nccwpck_require__(47161);
|
||||
const plugins = __importStar(__nccwpck_require__(96067));
|
||||
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
async function prepareEnv(installOnly) {
|
||||
const startedAt = Date.now();
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await (0, cache_1.restoreCache)();
|
||||
let binPath = await (0, install_1.install)();
|
||||
// Build custom golangci-lint if needed.
|
||||
const customBinPath = await plugins.install(binPath);
|
||||
if (customBinPath !== "") {
|
||||
binPath = customBinPath;
|
||||
}
|
||||
if (installOnly) {
|
||||
return { binPath, patchPath: `` };
|
||||
}
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`);
|
||||
return { binPath, patchPath };
|
||||
}
|
||||
const execCommand = (0, util_1.promisify)(child_process_1.exec);
|
||||
const printOutput = (res) => {
|
||||
if (res.stdout) {
|
||||
core.info(res.stdout);
|
||||
@@ -97481,12 +97473,7 @@ const printOutput = (res) => {
|
||||
core.info(res.stderr);
|
||||
}
|
||||
};
|
||||
async function runLint(binPath, patchPath) {
|
||||
const debug = core.getInput(`debug`);
|
||||
if (debug.split(`,`).includes(`cache`)) {
|
||||
const res = await execShellCommand(`${binPath} cache status`);
|
||||
printOutput(res);
|
||||
}
|
||||
async function runGolangciLint(binPath, rootDir) {
|
||||
const userArgs = core.getInput(`args`);
|
||||
const addedArgs = [];
|
||||
const userArgsList = userArgs
|
||||
@@ -97498,15 +97485,6 @@ async function runLint(binPath, patchPath) {
|
||||
.map(([key, value]) => [key.toLowerCase(), value ?? ""]);
|
||||
const userArgsMap = new Map(userArgsList);
|
||||
const userArgNames = new Set(userArgsList.map(([key]) => key));
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`);
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json");
|
||||
if (fs.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`);
|
||||
}
|
||||
}
|
||||
if ((0, patch_1.isOnlyNewIssues)()) {
|
||||
if (userArgNames.has(`new`) ||
|
||||
userArgNames.has(`new-from-rev`) ||
|
||||
@@ -97515,6 +97493,7 @@ async function runLint(binPath, patchPath) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`);
|
||||
}
|
||||
const ctx = github.context;
|
||||
const patchPath = await (0, patch_1.fetchPatch)();
|
||||
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`);
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
@@ -97540,27 +97519,21 @@ async function runLint(binPath, patchPath) {
|
||||
}
|
||||
}
|
||||
const cmdArgs = {};
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
if (rootDir) {
|
||||
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
||||
addedArgs.push(`--path-mode=abs`);
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
cmdArgs.cwd = path.resolve(rootDir);
|
||||
}
|
||||
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();
|
||||
try {
|
||||
const res = await execShellCommand(cmd, cmdArgs);
|
||||
printOutput(res);
|
||||
core.info(`golangci-lint found no issues`);
|
||||
}
|
||||
catch (exc) {
|
||||
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
|
||||
return execCommand(cmd, cmdArgs)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`golangci-lint found no issues`))
|
||||
.catch((exc) => {
|
||||
// This logging passes issues to GitHub annotations.
|
||||
printOutput(exc);
|
||||
if (exc.code === 1) {
|
||||
core.setFailed(`issues found`);
|
||||
@@ -97568,8 +97541,8 @@ async function runLint(binPath, patchPath) {
|
||||
else {
|
||||
core.setFailed(`golangci-lint exit with code ${exc.code}`);
|
||||
}
|
||||
}
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`);
|
||||
})
|
||||
.finally(() => core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`));
|
||||
}
|
||||
async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
const verify = core.getBooleanInput(`verify`, { required: true });
|
||||
@@ -97585,8 +97558,7 @@ async function runVerify(binPath, userArgsMap, cmdArgs) {
|
||||
cmdVerify += ` --config=${userArgsMap.get("config")}`;
|
||||
}
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs);
|
||||
printOutput(res);
|
||||
await execCommand(cmdVerify, cmdArgs).then(printOutput);
|
||||
}
|
||||
async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
let cmdConfigPath = `${binPath} config path`;
|
||||
@@ -97595,22 +97567,73 @@ async function getConfigPath(binPath, userArgsMap, cmdArgs) {
|
||||
}
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`);
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs);
|
||||
const resPath = await execCommand(cmdConfigPath, cmdArgs);
|
||||
return resPath.stderr.trim();
|
||||
}
|
||||
catch {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
async function debugAction(binPath) {
|
||||
const flags = core.getInput(`debug`).split(`,`);
|
||||
if (flags.includes(`clean`)) {
|
||||
const cmd = `${binPath} cache clean`;
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
await execCommand(cmd).then(printOutput);
|
||||
}
|
||||
if (flags.includes(`cache`)) {
|
||||
const cmd = `${binPath} cache status`;
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
await execCommand(cmd).then(printOutput);
|
||||
}
|
||||
}
|
||||
function getWorkingDirectory() {
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
}
|
||||
return workingDirectory;
|
||||
}
|
||||
function modulesAutoDetection(rootDir) {
|
||||
const o = {
|
||||
cwd: rootDir,
|
||||
exclude: ["**/vendor/**", "**/node_modules/**", "**/.git/**", "**/dist/**"],
|
||||
};
|
||||
const matches = fs.globSync("**/go.mod", o);
|
||||
const dirs = matches
|
||||
.filter((m) => typeof m === "string")
|
||||
.map((m) => path.resolve(rootDir, path.dirname(m)))
|
||||
.sort();
|
||||
return [...new Set(dirs)];
|
||||
}
|
||||
async function runLint(binPath) {
|
||||
const workingDirectory = getWorkingDirectory();
|
||||
const experimental = core.getInput(`experimental`).split(`,`);
|
||||
if (experimental.includes(`automatic-module-directories`)) {
|
||||
const wds = modulesAutoDetection(workingDirectory);
|
||||
const cwd = process.cwd();
|
||||
for (const wd of wds) {
|
||||
await core.group(`run golangci-lint in ${path.relative(cwd, wd)}`, () => runGolangciLint(binPath, wd));
|
||||
}
|
||||
return;
|
||||
}
|
||||
await core.group(`run golangci-lint`, () => runGolangciLint(binPath, workingDirectory));
|
||||
}
|
||||
async function run() {
|
||||
try {
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true });
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, () => prepareEnv(installOnly));
|
||||
await core.group(`Restore cache`, cache_1.restoreCache);
|
||||
const binPath = await core.group(`Install`, () => (0, install_1.install)().then(plugins.install));
|
||||
core.addPath(path.dirname(binPath));
|
||||
if (core.getInput(`debug`)) {
|
||||
await core.group(`Debug`, () => debugAction(binPath));
|
||||
}
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true });
|
||||
if (installOnly) {
|
||||
return;
|
||||
}
|
||||
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath));
|
||||
await runLint(binPath);
|
||||
}
|
||||
catch (error) {
|
||||
core.error(`Failed to run: ${error}, ${error.stack}`);
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
||||
module github.com/golangci/golangci-lint-action
|
||||
|
||||
go 1.23
|
||||
go 1.24.0
|
||||
|
||||
136
package-lock.json
generated
136
package-lock.json
generated
@@ -16,16 +16,16 @@
|
||||
"@actions/http-client": "^3.0.0",
|
||||
"@actions/tool-cache": "^2.0.2",
|
||||
"@octokit/plugin-retry": "^6.1.0",
|
||||
"@types/node": "^24.10.0",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/semver": "^7.7.1",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"@types/which": "^3.0.4",
|
||||
"tmp": "^0.2.5",
|
||||
"which": "^5.0.0",
|
||||
"which": "^6.0.0",
|
||||
"yaml": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
||||
"@typescript-eslint/parser": "^8.32.1",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"eslint": "^8.57.1",
|
||||
@@ -730,9 +730,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.0.tgz",
|
||||
"integrity": "sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A==",
|
||||
"version": "24.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz",
|
||||
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
@@ -788,17 +788,17 @@
|
||||
"integrity": "sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w=="
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.46.2.tgz",
|
||||
"integrity": "sha512-ZGBMToy857/NIPaaCucIUQgqueOiq7HeAKkhlvqVV4lm089zUFW6ikRySx2v+cAhKeUCPuWVHeimyk6Dw1iY3w==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.46.4.tgz",
|
||||
"integrity": "sha512-R48VhmTJqplNyDxCyqqVkFSZIx1qX6PzwqgcXn1olLrzxcSBDlOsbtcnQuQhNtnNiJ4Xe5gREI1foajYaYU2Vg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@eslint-community/regexpp": "^4.10.0",
|
||||
"@typescript-eslint/scope-manager": "8.46.2",
|
||||
"@typescript-eslint/type-utils": "8.46.2",
|
||||
"@typescript-eslint/utils": "8.46.2",
|
||||
"@typescript-eslint/visitor-keys": "8.46.2",
|
||||
"@typescript-eslint/scope-manager": "8.46.4",
|
||||
"@typescript-eslint/type-utils": "8.46.4",
|
||||
"@typescript-eslint/utils": "8.46.4",
|
||||
"@typescript-eslint/visitor-keys": "8.46.4",
|
||||
"graphemer": "^1.4.0",
|
||||
"ignore": "^7.0.0",
|
||||
"natural-compare": "^1.4.0",
|
||||
@@ -812,7 +812,7 @@
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/parser": "^8.46.2",
|
||||
"@typescript-eslint/parser": "^8.46.4",
|
||||
"eslint": "^8.57.0 || ^9.0.0",
|
||||
"typescript": ">=4.8.4 <6.0.0"
|
||||
}
|
||||
@@ -828,16 +828,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.46.2.tgz",
|
||||
"integrity": "sha512-BnOroVl1SgrPLywqxyqdJ4l3S2MsKVLDVxZvjI1Eoe8ev2r3kGDo+PcMihNmDE+6/KjkTubSJnmqGZZjQSBq/g==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.46.4.tgz",
|
||||
"integrity": "sha512-tK3GPFWbirvNgsNKto+UmB/cRtn6TZfyw0D6IKrW55n6Vbs7KJoZtI//kpTKzE/DUmmnAFD8/Ca46s7Obs92/w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.46.2",
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/typescript-estree": "8.46.2",
|
||||
"@typescript-eslint/visitor-keys": "8.46.2",
|
||||
"@typescript-eslint/scope-manager": "8.46.4",
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"@typescript-eslint/typescript-estree": "8.46.4",
|
||||
"@typescript-eslint/visitor-keys": "8.46.4",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@@ -853,14 +853,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/project-service": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.46.2.tgz",
|
||||
"integrity": "sha512-PULOLZ9iqwI7hXcmL4fVfIsBi6AN9YxRc0frbvmg8f+4hQAjQ5GYNKK0DIArNo+rOKmR/iBYwkpBmnIwin4wBg==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.46.4.tgz",
|
||||
"integrity": "sha512-nPiRSKuvtTN+no/2N1kt2tUh/HoFzeEgOm9fQ6XQk4/ApGqjx0zFIIaLJ6wooR1HIoozvj2j6vTi/1fgAz7UYQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/tsconfig-utils": "^8.46.2",
|
||||
"@typescript-eslint/types": "^8.46.2",
|
||||
"@typescript-eslint/tsconfig-utils": "^8.46.4",
|
||||
"@typescript-eslint/types": "^8.46.4",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@@ -875,14 +875,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.46.2.tgz",
|
||||
"integrity": "sha512-LF4b/NmGvdWEHD2H4MsHD8ny6JpiVNDzrSZr3CsckEgCbAGZbYM4Cqxvi9L+WqDMT+51Ozy7lt2M+d0JLEuBqA==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.46.4.tgz",
|
||||
"integrity": "sha512-tMDbLGXb1wC+McN1M6QeDx7P7c0UWO5z9CXqp7J8E+xGcJuUuevWKxuG8j41FoweS3+L41SkyKKkia16jpX7CA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/visitor-keys": "8.46.2"
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"@typescript-eslint/visitor-keys": "8.46.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||
@@ -893,9 +893,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/tsconfig-utils": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.46.2.tgz",
|
||||
"integrity": "sha512-a7QH6fw4S57+F5y2FIxxSDyi5M4UfGF+Jl1bCGd7+L4KsaUY80GsiF/t0UoRFDHAguKlBaACWJRmdrc6Xfkkag==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.46.4.tgz",
|
||||
"integrity": "sha512-+/XqaZPIAk6Cjg7NWgSGe27X4zMGqrFqZ8atJsX3CWxH/jACqWnrWI68h7nHQld0y+k9eTTjb9r+KU4twLoo9A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -910,15 +910,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/type-utils": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.46.2.tgz",
|
||||
"integrity": "sha512-HbPM4LbaAAt/DjxXaG9yiS9brOOz6fabal4uvUmaUYe6l3K1phQDMQKBRUrr06BQkxkvIZVVHttqiybM9nJsLA==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.46.4.tgz",
|
||||
"integrity": "sha512-V4QC8h3fdT5Wro6vANk6eojqfbv5bpwHuMsBcJUJkqs2z5XnYhJzyz9Y02eUmF9u3PgXEUiOt4w4KHR3P+z0PQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/typescript-estree": "8.46.2",
|
||||
"@typescript-eslint/utils": "8.46.2",
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"@typescript-eslint/typescript-estree": "8.46.4",
|
||||
"@typescript-eslint/utils": "8.46.4",
|
||||
"debug": "^4.3.4",
|
||||
"ts-api-utils": "^2.1.0"
|
||||
},
|
||||
@@ -935,9 +935,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/types": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.46.2.tgz",
|
||||
"integrity": "sha512-lNCWCbq7rpg7qDsQrd3D6NyWYu+gkTENkG5IKYhUIcxSb59SQC/hEQ+MrG4sTgBVghTonNWq42bA/d4yYumldQ==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.46.4.tgz",
|
||||
"integrity": "sha512-USjyxm3gQEePdUwJBFjjGNG18xY9A2grDVGuk7/9AkjIF1L+ZrVnwR5VAU5JXtUnBL/Nwt3H31KlRDaksnM7/w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -949,16 +949,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.46.2.tgz",
|
||||
"integrity": "sha512-f7rW7LJ2b7Uh2EiQ+7sza6RDZnajbNbemn54Ob6fRwQbgcIn+GWfyuHDHRYgRoZu1P4AayVScrRW+YfbTvPQoQ==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.46.4.tgz",
|
||||
"integrity": "sha512-7oV2qEOr1d4NWNmpXLR35LvCfOkTNymY9oyW+lUHkmCno7aOmIf/hMaydnJBUTBMRCOGZh8YjkFOc8dadEoNGA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/project-service": "8.46.2",
|
||||
"@typescript-eslint/tsconfig-utils": "8.46.2",
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/visitor-keys": "8.46.2",
|
||||
"@typescript-eslint/project-service": "8.46.4",
|
||||
"@typescript-eslint/tsconfig-utils": "8.46.4",
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"@typescript-eslint/visitor-keys": "8.46.4",
|
||||
"debug": "^4.3.4",
|
||||
"fast-glob": "^3.3.2",
|
||||
"is-glob": "^4.0.3",
|
||||
@@ -1017,16 +1017,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.46.2.tgz",
|
||||
"integrity": "sha512-sExxzucx0Tud5tE0XqR0lT0psBQvEpnpiul9XbGUB1QwpWJJAps1O/Z7hJxLGiZLBKMCutjTzDgmd1muEhBnVg==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.46.4.tgz",
|
||||
"integrity": "sha512-AbSv11fklGXV6T28dp2Me04Uw90R2iJ30g2bgLz529Koehrmkbs1r7paFqr1vPCZi7hHwYxYtxfyQMRC8QaVSg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.7.0",
|
||||
"@typescript-eslint/scope-manager": "8.46.2",
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/typescript-estree": "8.46.2"
|
||||
"@typescript-eslint/scope-manager": "8.46.4",
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"@typescript-eslint/typescript-estree": "8.46.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||
@@ -1041,13 +1041,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "8.46.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.46.2.tgz",
|
||||
"integrity": "sha512-tUFMXI4gxzzMXt4xpGJEsBsTox0XbNQ1y94EwlD/CuZwFcQP79xfQqMhau9HsRc/J0cAPA/HZt1dZPtGn9V/7w==",
|
||||
"version": "8.46.4",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.46.4.tgz",
|
||||
"integrity": "sha512-/++5CYLQqsO9HFGLI7APrxBJYo+5OCMpViuhV8q5/Qa3o5mMrF//eQHks+PXcsAVaLdn817fMuS7zqoXNNZGaw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "8.46.2",
|
||||
"@typescript-eslint/types": "8.46.4",
|
||||
"eslint-visitor-keys": "^4.2.1"
|
||||
},
|
||||
"engines": {
|
||||
@@ -3028,10 +3028,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
|
||||
"integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
@@ -4273,9 +4274,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-5.0.0.tgz",
|
||||
"integrity": "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==",
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-6.0.0.tgz",
|
||||
"integrity": "sha512-f+gEpIKMR9faW/JgAgPK1D7mekkFoqbmiwvNzuhsHetni20QSgzg9Vhn0g2JSJkkfehQnqdUAx7/e15qS1lPxg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^3.1.1"
|
||||
},
|
||||
@@ -4283,7 +4285,7 @@
|
||||
"node-which": "bin/which.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/which-boxed-primitive": {
|
||||
|
||||
@@ -34,16 +34,16 @@
|
||||
"@actions/http-client": "^3.0.0",
|
||||
"@octokit/plugin-retry": "^6.1.0",
|
||||
"@actions/tool-cache": "^2.0.2",
|
||||
"@types/node": "^24.10.0",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/semver": "^7.7.1",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"@types/which": "^3.0.4",
|
||||
"tmp": "^0.2.5",
|
||||
"which": "^5.0.0",
|
||||
"which": "^6.0.0",
|
||||
"yaml": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
||||
"@typescript-eslint/parser": "^8.32.1",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"eslint": "^8.57.1",
|
||||
|
||||
3
sample-monorepo/a/go.mod
Normal file
3
sample-monorepo/a/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/golangci/actiona
|
||||
|
||||
go 1.24.0
|
||||
26
sample-monorepo/a/sample.go
Normal file
26
sample-monorepo/a/sample.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package sample is used as test input for golangci action.
|
||||
package sample
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Hash~
|
||||
func Hash(data string) string {
|
||||
retError()
|
||||
retError2()
|
||||
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func retError() error {
|
||||
return errors.New("err")
|
||||
}
|
||||
|
||||
func retError2() error {
|
||||
return errors.New("err2")
|
||||
}
|
||||
3
sample-monorepo/a/suba/go.mod
Normal file
3
sample-monorepo/a/suba/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/golangci/actiona/suba
|
||||
|
||||
go 1.24.0
|
||||
26
sample-monorepo/a/suba/sample.go
Normal file
26
sample-monorepo/a/suba/sample.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package sample is used as test input for golangci action.
|
||||
package sample
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Hash~
|
||||
func Hash(data string) string {
|
||||
retError()
|
||||
retError2()
|
||||
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func retError() error {
|
||||
return errors.New("err")
|
||||
}
|
||||
|
||||
func retError2() error {
|
||||
return errors.New("err2")
|
||||
}
|
||||
3
sample-monorepo/b/go.mod
Normal file
3
sample-monorepo/b/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/golangci/actionb
|
||||
|
||||
go 1.24.0
|
||||
26
sample-monorepo/b/sample.go
Normal file
26
sample-monorepo/b/sample.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package sample is used as test input for golangci action.
|
||||
package sample
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Hash~
|
||||
func Hash(data string) string {
|
||||
retError()
|
||||
retError2()
|
||||
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func retError() error {
|
||||
return errors.New("err")
|
||||
}
|
||||
|
||||
func retError2() error {
|
||||
return errors.New("err2")
|
||||
}
|
||||
3
sample-monorepo/c/go.mod
Normal file
3
sample-monorepo/c/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/golangci/actionc
|
||||
|
||||
go 1.24.0
|
||||
26
sample-monorepo/c/sample.go
Normal file
26
sample-monorepo/c/sample.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package sample is used as test input for golangci action.
|
||||
package sample
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Hash~
|
||||
func Hash(data string) string {
|
||||
retError()
|
||||
retError2()
|
||||
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func retError() error {
|
||||
return errors.New("err")
|
||||
}
|
||||
|
||||
func retError2() error {
|
||||
return errors.New("err2")
|
||||
}
|
||||
16
src/cache.ts
16
src/cache.ts
@@ -74,7 +74,10 @@ async function buildCacheKeys(): Promise<string[]> {
|
||||
}
|
||||
|
||||
export async function restoreCache(): Promise<void> {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache restoration`)
|
||||
return
|
||||
}
|
||||
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(
|
||||
@@ -116,8 +119,15 @@ export async function restoreCache(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function saveCache(): Promise<void> {
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) return
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`)
|
||||
return
|
||||
}
|
||||
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) {
|
||||
core.info(`Skipping cache saving`)
|
||||
return
|
||||
}
|
||||
|
||||
// Validate inputs, this can cause task failure
|
||||
if (!utils.isValidEvent()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as tc from "@actions/tool-cache"
|
||||
import { exec, ExecOptionsWithStringEncoding } from "child_process"
|
||||
import fs from "fs"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { promisify } from "util"
|
||||
@@ -8,7 +9,7 @@ import which from "which"
|
||||
|
||||
import { getVersion, VersionInfo } from "./version"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
const execCommand = promisify(exec)
|
||||
|
||||
export enum InstallMode {
|
||||
Binary = "binary",
|
||||
@@ -21,13 +22,15 @@ type ExecRes = {
|
||||
stderr: string
|
||||
}
|
||||
|
||||
const printOutput = (res: ExecRes): void => {
|
||||
const printOutput = (res: ExecRes): ExecRes => {
|
||||
if (res.stdout) {
|
||||
core.info(res.stdout)
|
||||
}
|
||||
if (res.stderr) {
|
||||
core.info(res.stderr)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +39,17 @@ const printOutput = (res: ExecRes): void => {
|
||||
* @returns path to installed binary of golangci-lint.
|
||||
*/
|
||||
export async function install(): Promise<string> {
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`)
|
||||
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json")
|
||||
if (fs.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
const mode = core.getInput("install-mode").toLowerCase()
|
||||
|
||||
if (mode === InstallMode.None) {
|
||||
@@ -84,17 +98,14 @@ async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
||||
|
||||
const options: ExecOptionsWithStringEncoding = { env: { ...process.env, CGO_ENABLED: "1" } }
|
||||
|
||||
const exres = await execShellCommand(
|
||||
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
options
|
||||
await execCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(
|
||||
printOutput
|
||||
)
|
||||
printOutput(exres)
|
||||
|
||||
const res = await execShellCommand(
|
||||
const res = await execCommand(
|
||||
`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||
options
|
||||
)
|
||||
printOutput(res)
|
||||
).then(printOutput)
|
||||
|
||||
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||
const binPath = res.stderr
|
||||
|
||||
10
src/patch.ts
10
src/patch.ts
@@ -17,10 +17,6 @@ export function isOnlyNewIssues(): boolean {
|
||||
}
|
||||
|
||||
export async function fetchPatch(): Promise<string> {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``
|
||||
}
|
||||
|
||||
const ctx = github.context
|
||||
|
||||
switch (ctx.eventName) {
|
||||
@@ -70,8 +66,7 @@ async function fetchPullRequestPatch(ctx: Context): Promise<string> {
|
||||
}
|
||||
|
||||
try {
|
||||
const tempDir = await createTempDir()
|
||||
const patchPath = path.join(tempDir, "pull.patch")
|
||||
const patchPath = await createTempDir().then((tempDir) => path.join(tempDir, "pull.patch"))
|
||||
core.info(`Writing patch to ${patchPath}`)
|
||||
await writeFile(patchPath, alterDiffPatch(patch))
|
||||
return patchPath
|
||||
@@ -108,8 +103,7 @@ async function fetchPushPatch(ctx: Context): Promise<string> {
|
||||
}
|
||||
|
||||
try {
|
||||
const tempDir = await createTempDir()
|
||||
const patchPath = path.join(tempDir, "push.patch")
|
||||
const patchPath = await createTempDir().then((tempDir) => path.join(tempDir, "push.patch"))
|
||||
core.info(`Writing patch to ${patchPath}`)
|
||||
await writeFile(patchPath, alterDiffPatch(patch))
|
||||
return patchPath
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as path from "path"
|
||||
import { promisify } from "util"
|
||||
import YAML from "yaml"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
const execCommand = promisify(exec)
|
||||
|
||||
type ExecRes = {
|
||||
stdout: string
|
||||
@@ -34,12 +34,13 @@ export async function install(binPath: string): Promise<string> {
|
||||
rootDir = process.cwd()
|
||||
}
|
||||
|
||||
const configFile = [".custom-gcl.yml", ".custom-gcl.yaml", ".custom-gcl.json"]
|
||||
.map((v) => path.join(rootDir, v))
|
||||
const configFile = ["yml", "yaml", "json"]
|
||||
.map((ext) => `.custom-gcl.${ext}`)
|
||||
.map((filename) => path.join(rootDir, filename))
|
||||
.find((filePath) => fs.existsSync(filePath))
|
||||
|
||||
if (!configFile || configFile === "") {
|
||||
return ""
|
||||
return binPath
|
||||
}
|
||||
|
||||
core.info(`Found configuration for the plugin module system : ${configFile}`)
|
||||
@@ -53,7 +54,7 @@ export async function install(binPath: string): Promise<string> {
|
||||
const v: string = core.getInput(`version`)
|
||||
if (v !== "" && config.version !== v) {
|
||||
core.warning(
|
||||
`The golangci-lint version (${config.version}) defined inside in ${configFile} does not match the version defined in the action (${v})`
|
||||
`The golangci-lint version (${config.version}) defined inside ${configFile} does not match the version defined in the action (${v})`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,18 +74,15 @@ export async function install(binPath: string): Promise<string> {
|
||||
|
||||
core.info(`Running [${cmd}] in [${rootDir}] ...`)
|
||||
|
||||
try {
|
||||
const options: ExecOptionsWithStringEncoding = {
|
||||
cwd: rootDir,
|
||||
}
|
||||
|
||||
const res = await execShellCommand(cmd, options)
|
||||
printOutput(res)
|
||||
|
||||
core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`)
|
||||
|
||||
return path.join(rootDir, config.destination, config.name)
|
||||
} catch (exc) {
|
||||
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`)
|
||||
const options: ExecOptionsWithStringEncoding = {
|
||||
cwd: rootDir,
|
||||
}
|
||||
|
||||
return execCommand(cmd, options)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`))
|
||||
.then(() => path.join(rootDir, config.destination, config.name))
|
||||
.catch((exc) => {
|
||||
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`)
|
||||
})
|
||||
}
|
||||
|
||||
171
src/run.ts
171
src/run.ts
@@ -10,37 +10,7 @@ import { install } from "./install"
|
||||
import { fetchPatch, isOnlyNewIssues } from "./patch"
|
||||
import * as plugins from "./plugins"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
|
||||
type Env = {
|
||||
binPath: string
|
||||
patchPath: string
|
||||
}
|
||||
|
||||
async function prepareEnv(installOnly: boolean): Promise<Env> {
|
||||
const startedAt = Date.now()
|
||||
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await restoreCache()
|
||||
|
||||
let binPath = await install()
|
||||
|
||||
// Build custom golangci-lint if needed.
|
||||
const customBinPath = await plugins.install(binPath)
|
||||
if (customBinPath !== "") {
|
||||
binPath = customBinPath
|
||||
}
|
||||
|
||||
if (installOnly) {
|
||||
return { binPath, patchPath: `` }
|
||||
}
|
||||
|
||||
const patchPath = await fetchPatch()
|
||||
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||
|
||||
return { binPath, patchPath }
|
||||
}
|
||||
const execCommand = promisify(exec)
|
||||
|
||||
type ExecRes = {
|
||||
stdout: string
|
||||
@@ -56,13 +26,7 @@ const printOutput = (res: ExecRes): void => {
|
||||
}
|
||||
}
|
||||
|
||||
async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
const debug = core.getInput(`debug`)
|
||||
if (debug.split(`,`).includes(`cache`)) {
|
||||
const res = await execShellCommand(`${binPath} cache status`)
|
||||
printOutput(res)
|
||||
}
|
||||
|
||||
async function runGolangciLint(binPath: string, rootDir: string): Promise<void> {
|
||||
const userArgs = core.getInput(`args`)
|
||||
const addedArgs: string[] = []
|
||||
|
||||
@@ -77,17 +41,6 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
const userArgsMap = new Map<string, string>(userArgsList)
|
||||
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
||||
|
||||
const problemMatchers = core.getBooleanInput(`problem-matchers`)
|
||||
|
||||
if (problemMatchers) {
|
||||
const matchersPath = path.join(__dirname, "../..", "problem-matchers.json")
|
||||
if (fs.existsSync(matchersPath)) {
|
||||
// Adds problem matchers.
|
||||
// https://github.com/actions/setup-go/blob/cdcb36043654635271a94b9a6d1392de5bb323a7/src/main.ts#L81-L83
|
||||
core.info(`##[add-matcher]${matchersPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnlyNewIssues()) {
|
||||
if (
|
||||
userArgNames.has(`new`) ||
|
||||
@@ -99,6 +52,7 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
}
|
||||
|
||||
const ctx = github.context
|
||||
const patchPath = await fetchPatch()
|
||||
|
||||
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`)
|
||||
|
||||
@@ -130,17 +84,12 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
|
||||
const cmdArgs: ExecOptionsWithStringEncoding = {}
|
||||
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
||||
}
|
||||
|
||||
if (rootDir) {
|
||||
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
||||
addedArgs.push(`--path-mode=abs`)
|
||||
}
|
||||
|
||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||
cmdArgs.cwd = path.resolve(rootDir)
|
||||
}
|
||||
|
||||
await runVerify(binPath, userArgsMap, cmdArgs)
|
||||
@@ -150,22 +99,21 @@ async function runLint(binPath: string, patchPath: string): Promise<void> {
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
const startedAt = Date.now()
|
||||
try {
|
||||
const res = await execShellCommand(cmd, cmdArgs)
|
||||
printOutput(res)
|
||||
core.info(`golangci-lint found no issues`)
|
||||
} catch (exc) {
|
||||
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
|
||||
printOutput(exc)
|
||||
|
||||
if (exc.code === 1) {
|
||||
core.setFailed(`issues found`)
|
||||
} else {
|
||||
core.setFailed(`golangci-lint exit with code ${exc.code}`)
|
||||
}
|
||||
}
|
||||
return execCommand(cmd, cmdArgs)
|
||||
.then(printOutput)
|
||||
.then(() => core.info(`golangci-lint found no issues`))
|
||||
.catch((exc) => {
|
||||
// This logging passes issues to GitHub annotations.
|
||||
printOutput(exc)
|
||||
|
||||
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`)
|
||||
if (exc.code === 1) {
|
||||
core.setFailed(`issues found`)
|
||||
} else {
|
||||
core.setFailed(`golangci-lint exit with code ${exc.code}`)
|
||||
}
|
||||
})
|
||||
.finally(() => core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`))
|
||||
}
|
||||
|
||||
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<void> {
|
||||
@@ -186,8 +134,7 @@ async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdA
|
||||
|
||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
const res = await execShellCommand(cmdVerify, cmdArgs)
|
||||
printOutput(res)
|
||||
await execCommand(cmdVerify, cmdArgs).then(printOutput)
|
||||
}
|
||||
|
||||
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<string> {
|
||||
@@ -199,26 +146,98 @@ async function getConfigPath(binPath: string, userArgsMap: Map<string, string>,
|
||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
try {
|
||||
const resPath = await execShellCommand(cmdConfigPath, cmdArgs)
|
||||
const resPath = await execCommand(cmdConfigPath, cmdArgs)
|
||||
return resPath.stderr.trim()
|
||||
} catch {
|
||||
return ``
|
||||
}
|
||||
}
|
||||
|
||||
async function debugAction(binPath: string) {
|
||||
const flags = core.getInput(`debug`).split(`,`)
|
||||
|
||||
if (flags.includes(`clean`)) {
|
||||
const cmd = `${binPath} cache clean`
|
||||
|
||||
core.info(`Running [${cmd}] ...`)
|
||||
|
||||
await execCommand(cmd).then(printOutput)
|
||||
}
|
||||
|
||||
if (flags.includes(`cache`)) {
|
||||
const cmd = `${binPath} cache status`
|
||||
|
||||
core.info(`Running [${cmd}] ...`)
|
||||
|
||||
await execCommand(cmd).then(printOutput)
|
||||
}
|
||||
}
|
||||
|
||||
function getWorkingDirectory(): string {
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
if (workingDirectory) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
||||
}
|
||||
}
|
||||
|
||||
return workingDirectory
|
||||
}
|
||||
|
||||
function modulesAutoDetection(rootDir: string): string[] {
|
||||
const o: fs.GlobOptions = {
|
||||
cwd: rootDir,
|
||||
exclude: ["**/vendor/**", "**/node_modules/**", "**/.git/**", "**/dist/**"],
|
||||
}
|
||||
|
||||
const matches = fs.globSync("**/go.mod", o)
|
||||
|
||||
const dirs = matches
|
||||
.filter((m) => typeof m === "string")
|
||||
.map((m) => path.resolve(rootDir, path.dirname(m)))
|
||||
.sort()
|
||||
|
||||
return [...new Set(dirs)]
|
||||
}
|
||||
|
||||
async function runLint(binPath: string): Promise<void> {
|
||||
const workingDirectory = getWorkingDirectory()
|
||||
|
||||
const experimental = core.getInput(`experimental`).split(`,`)
|
||||
|
||||
if (experimental.includes(`automatic-module-directories`)) {
|
||||
const wds = modulesAutoDetection(workingDirectory)
|
||||
|
||||
const cwd = process.cwd()
|
||||
|
||||
for (const wd of wds) {
|
||||
await core.group(`run golangci-lint in ${path.relative(cwd, wd)}`, () => runGolangciLint(binPath, wd))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
await core.group(`run golangci-lint`, () => runGolangciLint(binPath, workingDirectory))
|
||||
}
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true })
|
||||
await core.group(`Restore cache`, restoreCache)
|
||||
|
||||
const { binPath, patchPath } = await core.group(`prepare environment`, () => prepareEnv(installOnly))
|
||||
const binPath = await core.group(`Install`, () => install().then(plugins.install))
|
||||
|
||||
core.addPath(path.dirname(binPath))
|
||||
|
||||
if (core.getInput(`debug`)) {
|
||||
await core.group(`Debug`, () => debugAction(binPath))
|
||||
}
|
||||
|
||||
const installOnly = core.getBooleanInput(`install-only`, { required: true })
|
||||
if (installOnly) {
|
||||
return
|
||||
}
|
||||
|
||||
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
|
||||
await runLint(binPath)
|
||||
} catch (error) {
|
||||
core.error(`Failed to run: ${error}, ${error.stack}`)
|
||||
core.setFailed(error.message)
|
||||
|
||||
Reference in New Issue
Block a user