mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-16 15:38:28 +00:00
Compare commits
No commits in common. "main" and "v9.0.0" have entirely different histories.
38 changed files with 100406 additions and 96012 deletions
9
.github/workflows/codeql.yaml
vendored
9
.github/workflows/codeql.yaml
vendored
|
|
@ -11,11 +11,6 @@ on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 17 * * 5'
|
- cron: '0 17 * * 5'
|
||||||
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
codeQL:
|
codeQL:
|
||||||
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
|
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
|
||||||
|
|
@ -23,7 +18,7 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
# Must fetch at least the immediate parents so that if this is
|
# Must fetch at least the immediate parents so that if this is
|
||||||
# a pull request then we can checkout the head of the pull request.
|
# a pull request then we can checkout the head of the pull request.
|
||||||
|
|
@ -41,7 +36,7 @@ jobs:
|
||||||
uses: github/codeql-action/init@v4
|
uses: github/codeql-action/init@v4
|
||||||
# Override language selection by uncommenting this and choosing your languages
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
with:
|
with:
|
||||||
languages: 'javascript-typescript'
|
language: 'javascript'
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
npm install
|
||||||
|
|
|
||||||
77
.github/workflows/test.yml
vendored
77
.github/workflows/test.yml
vendored
|
|
@ -1,6 +1,5 @@
|
||||||
name: "build-and-test"
|
name: "build-and-test"
|
||||||
|
on: # rebuild any PRs and main branch changes
|
||||||
on:
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
@ -8,27 +7,22 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# make sure build/ci work properly
|
build: # make sure build/ci work properly
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v5
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
npm install
|
||||||
npm run all
|
npm run all
|
||||||
|
|
||||||
# Fail the build if there are changes.
|
# Fail the build if there is dirty change
|
||||||
- run: git diff --exit-code -- dist
|
- run: git diff --exit-code -- dist
|
||||||
|
|
||||||
# make sure the action works on a clean machine without building
|
test: # make sure the action works on a clean machine without building
|
||||||
test:
|
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -40,14 +34,14 @@ jobs:
|
||||||
version:
|
version:
|
||||||
- ""
|
- ""
|
||||||
- "latest"
|
- "latest"
|
||||||
- "v2.7"
|
- "v2.5"
|
||||||
- "v2.7.2"
|
- "v2.5.0"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pull-requests: read
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
|
|
@ -57,11 +51,10 @@ jobs:
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
args: --timeout=5m --issues-exit-code=0 ./fixtures/simple/...
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
|
||||||
# make sure the action works on a clean machine without building (go-install mode)
|
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
|
||||||
test-go-install:
|
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -73,14 +66,14 @@ jobs:
|
||||||
version:
|
version:
|
||||||
- ""
|
- ""
|
||||||
- "latest"
|
- "latest"
|
||||||
- "v2.7.2"
|
- "v2.5.0"
|
||||||
- "655e8ede5178280b2a640e185bc4a343aed0f54e"
|
- "655e8ede5178280b2a640e185bc4a343aed0f54e"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pull-requests: read
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
|
|
@ -90,7 +83,7 @@ jobs:
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
args: --timeout=5m --issues-exit-code=0 ./fixtures/simple/...
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
install-mode: goinstall
|
install-mode: goinstall
|
||||||
|
|
||||||
|
|
@ -104,13 +97,13 @@ jobs:
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
wd:
|
wd:
|
||||||
- fixtures/go-mod
|
- sample-go-mod
|
||||||
- fixtures/go-tool
|
- sample-go-tool
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
|
|
@ -122,8 +115,7 @@ jobs:
|
||||||
working-directory: ${{ matrix.wd }}
|
working-directory: ${{ matrix.wd }}
|
||||||
args: --timeout=5m --issues-exit-code=0 ./...
|
args: --timeout=5m --issues-exit-code=0 ./...
|
||||||
|
|
||||||
# make sure the action works on a clean machine with plugins
|
test-plugins: # make sure the action works on a clean machine with plugins
|
||||||
test-plugins:
|
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -135,14 +127,14 @@ jobs:
|
||||||
version:
|
version:
|
||||||
- ""
|
- ""
|
||||||
- "latest"
|
- "latest"
|
||||||
- "v2.7"
|
- "v2.5"
|
||||||
- "v2.7.2"
|
- "v2.5.0"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pull-requests: read
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
|
|
@ -152,32 +144,5 @@ jobs:
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
working-directory: fixtures/plugins
|
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@v6
|
|
||||||
- uses: actions/setup-node@v6
|
|
||||||
with:
|
|
||||||
node-version: 24.x
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: oldstable
|
|
||||||
- uses: ./
|
|
||||||
with:
|
|
||||||
working-directory: fixtures/monorepo
|
|
||||||
experimental: "automatic-module-directories"
|
|
||||||
args: --timeout=5m --issues-exit-code=0 ./...
|
args: --timeout=5m --issues-exit-code=0 ./...
|
||||||
|
|
|
||||||
258
README.md
258
README.md
|
|
@ -54,9 +54,9 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: stable
|
go-version: stable
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
version: v2.6
|
version: v2.1
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
@ -92,9 +92,9 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
version: v2.6
|
version: v2.1
|
||||||
```
|
```
|
||||||
|
|
||||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
|
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
|
||||||
|
|
@ -120,7 +120,7 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: stable
|
GO_VERSION: stable
|
||||||
GOLANGCI_LINT_VERSION: v2.6
|
GOLANGCI_LINT_VERSION: v2.1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
detect-modules:
|
detect-modules:
|
||||||
|
|
@ -147,7 +147,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ env.GO_VERSION }}
|
||||||
- name: golangci-lint ${{ matrix.modules }}
|
- name: golangci-lint ${{ matrix.modules }}
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
version: ${{ env.GOLANGCI_LINT_VERSION }}
|
version: ${{ env.GOLANGCI_LINT_VERSION }}
|
||||||
working-directory: ${{ matrix.modules }}
|
working-directory: ${{ matrix.modules }}
|
||||||
|
|
@ -179,7 +179,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
os: ${{ matrix.os }}
|
os: ${{ matrix.os }}
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
golangci-lint-version: v2.6
|
golangci-lint-version: v2.1
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|
@ -201,7 +201,7 @@ on:
|
||||||
golangci-lint-version:
|
golangci-lint-version:
|
||||||
description: 'Golangci-lint version'
|
description: 'Golangci-lint version'
|
||||||
type: string
|
type: string
|
||||||
default: 'v2.6'
|
default: 'v2.1'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
detect-modules:
|
detect-modules:
|
||||||
|
|
@ -229,7 +229,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: ${{ inputs.go-version }}
|
go-version: ${{ inputs.go-version }}
|
||||||
- name: golangci-lint ${{ matrix.modules }}
|
- name: golangci-lint ${{ matrix.modules }}
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
version: ${{ inputs.golangci-lint-version }}
|
version: ${{ inputs.golangci-lint-version }}
|
||||||
working-directory: ${{ matrix.modules }}
|
working-directory: ${{ matrix.modules }}
|
||||||
|
|
@ -259,28 +259,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
### Overview
|
### `version`
|
||||||
|
|
||||||
| Option | Description |
|
|
||||||
|---------------------------------------------------------------|-------------------------------------------------------|
|
|
||||||
| [`version`](#version) | The version of golangci-lint to use. |
|
|
||||||
| [`version-file`](#version-file) | Gets the version of golangci-lint to use from a file. |
|
|
||||||
| [`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)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -295,37 +274,15 @@ When `install-mode` is:
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
version: v2.6
|
version: v2.1
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `version-file`
|
### `install-mode`
|
||||||
|
|
||||||
Gets the version of golangci-lint to use from a file.
|
|
||||||
|
|
||||||
The path must be relative to the root of the project, or the `working-directory` if defined.
|
|
||||||
|
|
||||||
This parameter supports `.golangci-lint-version`, and `.tool-versions` files.
|
|
||||||
|
|
||||||
Only works with `install-mode: binary` (the default).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Example</summary>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
uses: golangci/golangci-lint-action@v9
|
|
||||||
with:
|
|
||||||
version-file: .tool-versions
|
|
||||||
# ...
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
#### `install-mode`
|
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -339,7 +296,7 @@ The default value is `binary`.
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
install-mode: "none"
|
install-mode: "none"
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -347,7 +304,7 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `install-only`
|
### `install-only`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -360,7 +317,7 @@ The default value is `false`.
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
install-only: true
|
install-only: true
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -368,9 +325,27 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Run
|
### `github-token`
|
||||||
|
|
||||||
#### `verify`
|
(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`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -385,7 +360,7 @@ The JSON Schema used to validate the configuration depends on the version of gol
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
verify: false
|
verify: false
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -393,27 +368,7 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `github-token`
|
### `only-new-issues`
|
||||||
|
|
||||||
(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)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -430,7 +385,7 @@ The default value is `false`.
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -438,7 +393,7 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `working-directory`
|
### `working-directory`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -448,7 +403,7 @@ The golangci-lint working directory, useful for monorepos. The default is the pr
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
working-directory: somedir
|
working-directory: somedir
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -456,7 +411,7 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `args`
|
### `args`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -473,7 +428,7 @@ golangci-lint command line arguments.
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
# In some rare cases,
|
# In some rare cases,
|
||||||
# you may need to use `${{ github.workspace }}` as the base directory to reference your configuration file.
|
# you may need to use `${{ github.workspace }}` as the base directory to reference your configuration file.
|
||||||
|
|
@ -483,74 +438,7 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Cache
|
### `problem-matchers`
|
||||||
|
|
||||||
#### `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)
|
(optional)
|
||||||
|
|
||||||
|
|
@ -568,7 +456,7 @@ The default value is `false`.
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
problem-matchers: true
|
problem-matchers: true
|
||||||
# ...
|
# ...
|
||||||
|
|
@ -576,43 +464,65 @@ with:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Experimental
|
### `skip-cache`
|
||||||
|
|
||||||
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.
|
(optional)
|
||||||
|
|
||||||
List of comma-separated options.
|
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>
|
<details>
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yaml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
experimental: "foo,bar"
|
skip-cache: true
|
||||||
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### `automatic-module-directories`
|
### `skip-save-cache`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
|
||||||
This option will run golangci-lint in each module directory, useful for monorepos.
|
If set to `true`, caches will not be saved, but they may still be restored, requiring `skip-cache: false`.
|
||||||
|
|
||||||
The automatic detection of modules uses the `working-directory` as the base directory if defined, otherwise the root directory.
|
The default value is `false`.
|
||||||
|
|
||||||
> [!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>
|
<details>
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
```yaml
|
```yml
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
experimental: "automatic-module-directories"
|
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
|
||||||
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
|
||||||
34
action.yml
34
action.yml
|
|
@ -11,13 +11,6 @@ inputs:
|
||||||
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
|
- `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit.
|
||||||
- `none`: the value is ignored.
|
- `none`: the value is ignored.
|
||||||
required: false
|
required: false
|
||||||
version-file:
|
|
||||||
description: |
|
|
||||||
Gets the version of golangci-lint to use from a file.
|
|
||||||
The path must be relative to the root of the project, or the `working-directory` if defined.
|
|
||||||
This parameter supports `.golangci-lint-version`, and `.tool-versions` files.
|
|
||||||
Only works with `install-mode: binary` (the default).
|
|
||||||
required: false
|
|
||||||
install-mode:
|
install-mode:
|
||||||
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
|
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
|
||||||
default: "binary"
|
default: "binary"
|
||||||
|
|
@ -41,10 +34,6 @@ inputs:
|
||||||
description: "If set to true and the action runs on a pull request, the action outputs only newly found issues."
|
description: "If set to true and the action runs on a pull request, the action outputs only newly found issues."
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
args:
|
|
||||||
description: "golangci-lint command line arguments."
|
|
||||||
default: ""
|
|
||||||
required: false
|
|
||||||
skip-cache:
|
skip-cache:
|
||||||
description: |
|
description: |
|
||||||
If set to true, all caching functionality will be completely disabled.
|
If set to true, all caching functionality will be completely disabled.
|
||||||
|
|
@ -53,30 +42,21 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
skip-save-cache:
|
skip-save-cache:
|
||||||
description: |
|
description: |
|
||||||
If set to true, the action will not save any caches,
|
If set to true, the action will not save any caches, but it may still
|
||||||
but it may still restore existing caches, subject to other options.
|
restore existing caches, subject to other options.
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: 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:
|
problem-matchers:
|
||||||
description: "Force the usage of the embedded problem matchers."
|
description: "Force the usage of the embedded problem matchers."
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
debug:
|
args:
|
||||||
description: |
|
description: "golangci-lint command line arguments."
|
||||||
Debug options for the action.
|
|
||||||
List of comma separated options, the values are `cache`, `clean`.
|
|
||||||
example: "cache,clean"
|
|
||||||
default: ""
|
default: ""
|
||||||
required: false
|
required: false
|
||||||
experimental:
|
cache-invalidation-interval:
|
||||||
description: |
|
description: "Periodically invalidate a cache when new code is added (number of days)."
|
||||||
Experimental options for the action.
|
default: '7'
|
||||||
List of comma separated options.
|
|
||||||
default: ""
|
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: "node24"
|
using: "node24"
|
||||||
|
|
|
||||||
97074
dist/post_run/index.js
generated
vendored
97074
dist/post_run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
97074
dist/run/index.js
generated
vendored
97074
dist/run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +0,0 @@
|
||||||
module github.com/golangci/actiona
|
|
||||||
|
|
||||||
go 1.24.0
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module github.com/golangci/actiona/suba
|
|
||||||
|
|
||||||
go 1.24.0
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// 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")
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module github.com/golangci/actionb
|
|
||||||
|
|
||||||
go 1.24.0
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// 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")
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module github.com/golangci/actionc
|
|
||||||
|
|
||||||
go 1.24.0
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// 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")
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// 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")
|
|
||||||
}
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,3 +1,3 @@
|
||||||
module github.com/golangci/golangci-lint-action
|
module github.com/golangci/golangci-lint-action
|
||||||
|
|
||||||
go 1.24.0
|
go 1.23
|
||||||
|
|
|
||||||
1031
package-lock.json
generated
1031
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -27,23 +27,23 @@
|
||||||
"node": ">=24.0.0"
|
"node": ">=24.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^5.0.1",
|
"@actions/cache": "^4.1.0",
|
||||||
"@actions/core": "^2.0.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^2.0.0",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^6.0.1",
|
"@actions/github": "^6.0.1",
|
||||||
"@actions/http-client": "^3.0.0",
|
"@actions/http-client": "^3.0.0",
|
||||||
"@octokit/plugin-retry": "^6.1.0",
|
"@octokit/plugin-retry": "^6.1.0",
|
||||||
"@actions/tool-cache": "^2.0.2",
|
"@actions/tool-cache": "^2.0.2",
|
||||||
"@types/node": "^25.0.2",
|
"@types/node": "^24.10.0",
|
||||||
"@types/semver": "^7.7.1",
|
"@types/semver": "^7.7.1",
|
||||||
"@types/tmp": "^0.2.6",
|
"@types/tmp": "^0.2.6",
|
||||||
"@types/which": "^3.0.4",
|
"@types/which": "^3.0.4",
|
||||||
"tmp": "^0.2.5",
|
"tmp": "^0.2.5",
|
||||||
"which": "^6.0.0",
|
"which": "^5.0.0",
|
||||||
"yaml": "^2.8.2"
|
"yaml": "^2.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^8.49.0",
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
||||||
"@typescript-eslint/parser": "^8.32.1",
|
"@typescript-eslint/parser": "^8.32.1",
|
||||||
"@vercel/ncc": "^0.38.4",
|
"@vercel/ncc": "^0.38.4",
|
||||||
"eslint": "^8.57.1",
|
"eslint": "^8.57.1",
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
"eslint-plugin-import": "^2.32.0",
|
"eslint-plugin-import": "^2.32.0",
|
||||||
"eslint-plugin-prettier": "^5.5.4",
|
"eslint-plugin-prettier": "^5.5.4",
|
||||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||||
"prettier": "^3.7.4",
|
"prettier": "^3.6.2",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/golangci/sample
|
module sample
|
||||||
|
|
||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/golangci/sample
|
module sample
|
||||||
|
|
||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
16
src/cache.ts
16
src/cache.ts
|
|
@ -74,10 +74,7 @@ async function buildCacheKeys(): Promise<string[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function restoreCache(): Promise<void> {
|
export async function restoreCache(): Promise<void> {
|
||||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||||
core.info(`Skipping cache restoration`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(
|
utils.logWarning(
|
||||||
|
|
@ -119,15 +116,8 @@ export async function restoreCache(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveCache(): Promise<void> {
|
export async function saveCache(): Promise<void> {
|
||||||
if (core.getBooleanInput(`skip-cache`, { required: true })) {
|
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||||
core.info(`Skipping cache saving`)
|
if (core.getBooleanInput(`skip-save-cache`, { required: true })) return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) {
|
|
||||||
core.info(`Skipping cache saving`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as tc from "@actions/tool-cache"
|
import * as tc from "@actions/tool-cache"
|
||||||
import { exec, ExecOptionsWithStringEncoding } from "child_process"
|
import { exec, ExecOptionsWithStringEncoding } from "child_process"
|
||||||
import fs from "fs"
|
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
|
|
@ -9,7 +8,7 @@ import which from "which"
|
||||||
|
|
||||||
import { getVersion, VersionInfo } from "./version"
|
import { getVersion, VersionInfo } from "./version"
|
||||||
|
|
||||||
const execCommand = promisify(exec)
|
const execShellCommand = promisify(exec)
|
||||||
|
|
||||||
export enum InstallMode {
|
export enum InstallMode {
|
||||||
Binary = "binary",
|
Binary = "binary",
|
||||||
|
|
@ -22,15 +21,13 @@ type ExecRes = {
|
||||||
stderr: string
|
stderr: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const printOutput = (res: ExecRes): ExecRes => {
|
const printOutput = (res: ExecRes): void => {
|
||||||
if (res.stdout) {
|
if (res.stdout) {
|
||||||
core.info(res.stdout)
|
core.info(res.stdout)
|
||||||
}
|
}
|
||||||
if (res.stderr) {
|
if (res.stderr) {
|
||||||
core.info(res.stderr)
|
core.info(res.stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,17 +36,6 @@ const printOutput = (res: ExecRes): ExecRes => {
|
||||||
* @returns path to installed binary of golangci-lint.
|
* @returns path to installed binary of golangci-lint.
|
||||||
*/
|
*/
|
||||||
export async function install(): Promise<string> {
|
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()
|
const mode = core.getInput("install-mode").toLowerCase()
|
||||||
|
|
||||||
if (mode === InstallMode.None) {
|
if (mode === InstallMode.None) {
|
||||||
|
|
@ -98,14 +84,17 @@ async function goInstall(versionInfo: VersionInfo): Promise<string> {
|
||||||
|
|
||||||
const options: ExecOptionsWithStringEncoding = { env: { ...process.env, CGO_ENABLED: "1" } }
|
const options: ExecOptionsWithStringEncoding = { env: { ...process.env, CGO_ENABLED: "1" } }
|
||||||
|
|
||||||
await execCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options).then(
|
const exres = await execShellCommand(
|
||||||
printOutput
|
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||||
|
options
|
||||||
)
|
)
|
||||||
|
printOutput(exres)
|
||||||
|
|
||||||
const res = await execCommand(
|
const res = await execShellCommand(
|
||||||
`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`,
|
||||||
options
|
options
|
||||||
).then(printOutput)
|
)
|
||||||
|
printOutput(res)
|
||||||
|
|
||||||
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||||
const binPath = res.stderr
|
const binPath = res.stderr
|
||||||
|
|
|
||||||
10
src/patch.ts
10
src/patch.ts
|
|
@ -17,6 +17,10 @@ export function isOnlyNewIssues(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchPatch(): Promise<string> {
|
export async function fetchPatch(): Promise<string> {
|
||||||
|
if (!isOnlyNewIssues()) {
|
||||||
|
return ``
|
||||||
|
}
|
||||||
|
|
||||||
const ctx = github.context
|
const ctx = github.context
|
||||||
|
|
||||||
switch (ctx.eventName) {
|
switch (ctx.eventName) {
|
||||||
|
|
@ -66,7 +70,8 @@ async function fetchPullRequestPatch(ctx: Context): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const patchPath = await createTempDir().then((tempDir) => path.join(tempDir, "pull.patch"))
|
const tempDir = await createTempDir()
|
||||||
|
const patchPath = path.join(tempDir, "pull.patch")
|
||||||
core.info(`Writing patch to ${patchPath}`)
|
core.info(`Writing patch to ${patchPath}`)
|
||||||
await writeFile(patchPath, alterDiffPatch(patch))
|
await writeFile(patchPath, alterDiffPatch(patch))
|
||||||
return patchPath
|
return patchPath
|
||||||
|
|
@ -103,7 +108,8 @@ async function fetchPushPatch(ctx: Context): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const patchPath = await createTempDir().then((tempDir) => path.join(tempDir, "push.patch"))
|
const tempDir = await createTempDir()
|
||||||
|
const patchPath = path.join(tempDir, "push.patch")
|
||||||
core.info(`Writing patch to ${patchPath}`)
|
core.info(`Writing patch to ${patchPath}`)
|
||||||
await writeFile(patchPath, alterDiffPatch(patch))
|
await writeFile(patchPath, alterDiffPatch(patch))
|
||||||
return patchPath
|
return patchPath
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import * as path from "path"
|
||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
import YAML from "yaml"
|
import YAML from "yaml"
|
||||||
|
|
||||||
const execCommand = promisify(exec)
|
const execShellCommand = promisify(exec)
|
||||||
|
|
||||||
type ExecRes = {
|
type ExecRes = {
|
||||||
stdout: string
|
stdout: string
|
||||||
|
|
@ -34,13 +34,12 @@ export async function install(binPath: string): Promise<string> {
|
||||||
rootDir = process.cwd()
|
rootDir = process.cwd()
|
||||||
}
|
}
|
||||||
|
|
||||||
const configFile = ["yml", "yaml", "json"]
|
const configFile = [".custom-gcl.yml", ".custom-gcl.yaml", ".custom-gcl.json"]
|
||||||
.map((ext) => `.custom-gcl.${ext}`)
|
.map((v) => path.join(rootDir, v))
|
||||||
.map((filename) => path.join(rootDir, filename))
|
|
||||||
.find((filePath) => fs.existsSync(filePath))
|
.find((filePath) => fs.existsSync(filePath))
|
||||||
|
|
||||||
if (!configFile || configFile === "") {
|
if (!configFile || configFile === "") {
|
||||||
return binPath
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Found configuration for the plugin module system : ${configFile}`)
|
core.info(`Found configuration for the plugin module system : ${configFile}`)
|
||||||
|
|
@ -54,7 +53,7 @@ export async function install(binPath: string): Promise<string> {
|
||||||
const v: string = core.getInput(`version`)
|
const v: string = core.getInput(`version`)
|
||||||
if (v !== "" && config.version !== v) {
|
if (v !== "" && config.version !== v) {
|
||||||
core.warning(
|
core.warning(
|
||||||
`The golangci-lint version (${config.version}) defined inside ${configFile} does not match the version defined in the action (${v})`
|
`The golangci-lint version (${config.version}) defined inside in ${configFile} does not match the version defined in the action (${v})`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,15 +73,18 @@ export async function install(binPath: string): Promise<string> {
|
||||||
|
|
||||||
core.info(`Running [${cmd}] in [${rootDir}] ...`)
|
core.info(`Running [${cmd}] in [${rootDir}] ...`)
|
||||||
|
|
||||||
|
try {
|
||||||
const options: ExecOptionsWithStringEncoding = {
|
const options: ExecOptionsWithStringEncoding = {
|
||||||
cwd: rootDir,
|
cwd: rootDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
return execCommand(cmd, options)
|
const res = await execShellCommand(cmd, options)
|
||||||
.then(printOutput)
|
printOutput(res)
|
||||||
.then(() => core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`))
|
|
||||||
.then(() => path.join(rootDir, config.destination, config.name))
|
core.info(`Built custom golangci-lint binary in ${Date.now() - startedAt}ms`)
|
||||||
.catch((exc) => {
|
|
||||||
|
return path.join(rootDir, config.destination, config.name)
|
||||||
|
} catch (exc) {
|
||||||
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`)
|
throw new Error(`Failed to build custom golangci-lint binary: ${exc.message}`)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
161
src/run.ts
161
src/run.ts
|
|
@ -10,7 +10,37 @@ import { install } from "./install"
|
||||||
import { fetchPatch, isOnlyNewIssues } from "./patch"
|
import { fetchPatch, isOnlyNewIssues } from "./patch"
|
||||||
import * as plugins from "./plugins"
|
import * as plugins from "./plugins"
|
||||||
|
|
||||||
const execCommand = promisify(exec)
|
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 }
|
||||||
|
}
|
||||||
|
|
||||||
type ExecRes = {
|
type ExecRes = {
|
||||||
stdout: string
|
stdout: string
|
||||||
|
|
@ -26,7 +56,13 @@ const printOutput = (res: ExecRes): void => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runGolangciLint(binPath: string, rootDir: string): Promise<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)
|
||||||
|
}
|
||||||
|
|
||||||
const userArgs = core.getInput(`args`)
|
const userArgs = core.getInput(`args`)
|
||||||
const addedArgs: string[] = []
|
const addedArgs: string[] = []
|
||||||
|
|
||||||
|
|
@ -41,6 +77,17 @@ async function runGolangciLint(binPath: string, rootDir: string): Promise<void>
|
||||||
const userArgsMap = new Map<string, string>(userArgsList)
|
const userArgsMap = new Map<string, string>(userArgsList)
|
||||||
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
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 (isOnlyNewIssues()) {
|
||||||
if (
|
if (
|
||||||
userArgNames.has(`new`) ||
|
userArgNames.has(`new`) ||
|
||||||
|
|
@ -52,7 +99,6 @@ async function runGolangciLint(binPath: string, rootDir: string): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = github.context
|
const ctx = github.context
|
||||||
const patchPath = await fetchPatch()
|
|
||||||
|
|
||||||
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`)
|
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`)
|
||||||
|
|
||||||
|
|
@ -84,12 +130,17 @@ async function runGolangciLint(binPath: string, rootDir: string): Promise<void>
|
||||||
|
|
||||||
const cmdArgs: ExecOptionsWithStringEncoding = {}
|
const cmdArgs: ExecOptionsWithStringEncoding = {}
|
||||||
|
|
||||||
if (rootDir) {
|
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 (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
||||||
addedArgs.push(`--path-mode=abs`)
|
addedArgs.push(`--path-mode=abs`)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs.cwd = path.resolve(rootDir)
|
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
await runVerify(binPath, userArgsMap, cmdArgs)
|
await runVerify(binPath, userArgsMap, cmdArgs)
|
||||||
|
|
@ -99,12 +150,12 @@ async function runGolangciLint(binPath: string, rootDir: string): Promise<void>
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
try {
|
||||||
return execCommand(cmd, cmdArgs)
|
const res = await execShellCommand(cmd, cmdArgs)
|
||||||
.then(printOutput)
|
printOutput(res)
|
||||||
.then(() => core.info(`golangci-lint found no issues`))
|
core.info(`golangci-lint found no issues`)
|
||||||
.catch((exc) => {
|
} catch (exc) {
|
||||||
// This logging passes issues to GitHub annotations.
|
// This logging passes issues to GitHub annotations but comments can be more convenient for some users.
|
||||||
printOutput(exc)
|
printOutput(exc)
|
||||||
|
|
||||||
if (exc.code === 1) {
|
if (exc.code === 1) {
|
||||||
|
|
@ -112,8 +163,9 @@ async function runGolangciLint(binPath: string, rootDir: string): Promise<void>
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`golangci-lint exit with code ${exc.code}`)
|
core.setFailed(`golangci-lint exit with code ${exc.code}`)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.finally(() => core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`))
|
|
||||||
|
core.info(`Ran golangci-lint in ${Date.now() - startedAt}ms`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<void> {
|
async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<void> {
|
||||||
|
|
@ -134,7 +186,8 @@ async function runVerify(binPath: string, userArgsMap: Map<string, string>, cmdA
|
||||||
|
|
||||||
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
core.info(`Running [${cmdVerify}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||||
|
|
||||||
await execCommand(cmdVerify, cmdArgs).then(printOutput)
|
const res = await execShellCommand(cmdVerify, cmdArgs)
|
||||||
|
printOutput(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<string> {
|
async function getConfigPath(binPath: string, userArgsMap: Map<string, string>, cmdArgs: ExecOptionsWithStringEncoding): Promise<string> {
|
||||||
|
|
@ -146,98 +199,26 @@ async function getConfigPath(binPath: string, userArgsMap: Map<string, string>,
|
||||||
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
core.info(`Running [${cmdConfigPath}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resPath = await execCommand(cmdConfigPath, cmdArgs)
|
const resPath = await execShellCommand(cmdConfigPath, cmdArgs)
|
||||||
return resPath.stderr.trim()
|
return resPath.stderr.trim()
|
||||||
} catch {
|
} catch {
|
||||||
return ``
|
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> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await core.group(`Restore cache`, restoreCache)
|
const installOnly = core.getBooleanInput(`install-only`, { required: true })
|
||||||
|
|
||||||
const binPath = await core.group(`Install`, () => install().then(plugins.install))
|
const { binPath, patchPath } = await core.group(`prepare environment`, () => prepareEnv(installOnly))
|
||||||
|
|
||||||
core.addPath(path.dirname(binPath))
|
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) {
|
if (installOnly) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await runLint(binPath)
|
await core.group(`run golangci-lint`, () => runLint(binPath, patchPath))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Failed to run: ${error}, ${error.stack}`)
|
core.error(`Failed to run: ${error}, ${error.stack}`)
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,6 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
||||||
|
|
||||||
const getRequestedVersion = (): Version => {
|
const getRequestedVersion = (): Version => {
|
||||||
let requestedVersion = core.getInput(`version`)
|
let requestedVersion = core.getInput(`version`)
|
||||||
let versionFilePath = core.getInput(`version-file`)
|
|
||||||
|
|
||||||
if (requestedVersion && versionFilePath) {
|
|
||||||
core.warning(`Both version (${requestedVersion}) and version-file (${versionFilePath}) inputs are specified, only version will be used`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const workingDirectory = core.getInput(`working-directory`)
|
const workingDirectory = core.getInput(`working-directory`)
|
||||||
|
|
||||||
let goMod = "go.mod"
|
let goMod = "go.mod"
|
||||||
|
|
@ -89,27 +83,6 @@ const getRequestedVersion = (): Version => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestedVersion == "" && versionFilePath) {
|
|
||||||
if (workingDirectory) {
|
|
||||||
versionFilePath = path.join(workingDirectory, versionFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
|
||||||
throw new Error(`The specified golangci-lint version file at: ${versionFilePath} does not exist`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const content = fs.readFileSync(versionFilePath, "utf-8")
|
|
||||||
|
|
||||||
if (path.basename(versionFilePath) === ".tool-versions") {
|
|
||||||
// asdf/mise file.
|
|
||||||
const match = content.match(/^golangci-lint\s+([^\n#]+)/m)
|
|
||||||
requestedVersion = match ? "v" + match[1].trim().replace(/^v/gi, "") : ""
|
|
||||||
} else {
|
|
||||||
// .golangci-lint-version file.
|
|
||||||
requestedVersion = "v" + content.trim().replace(/^v/gi, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedRequestedVersion = parseVersion(requestedVersion)
|
const parsedRequestedVersion = parseVersion(requestedVersion)
|
||||||
if (parsedRequestedVersion == null) {
|
if (parsedRequestedVersion == null) {
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue