Compare commits
289 Commits
Author | SHA1 | Date | |
---|---|---|---|
aaa42aa062 | |||
9ec89731c3 | |||
58838cffc6 | |||
9f3ba2c3a8 | |||
2bd7a04e91 | |||
db819a10bd | |||
d09fb0808a | |||
605617a3e2 | |||
66f63c74bb | |||
2c01d264ab | |||
d8028e1f20 | |||
a0231c4ff0 | |||
e43020d72a | |||
9e57efc106 | |||
27d925f9c0 | |||
24b3d93762 | |||
26b1e83940 | |||
081b216ccf | |||
0d98fecd83 | |||
031a2fcd4a | |||
96843aea6d | |||
8032b26298 | |||
dfd6a77317 | |||
e1ff6fb1c1 | |||
4145754745 | |||
16507ab8ef | |||
725e01551b | |||
32b7e669bc | |||
e2918bb1f8 | |||
3f51204e49 | |||
b7f3daa60e | |||
952b7b2e57 | |||
7a82e5f967 | |||
4655d13902 | |||
182ce0be58 | |||
bc05d62e37 | |||
8a8f91e859 | |||
34be59169b | |||
abbeba8940 | |||
d7e9c664d4 | |||
42ebe7fde9 | |||
7b547992bc | |||
a4f60bb28d | |||
5815a4b917 | |||
23faadfdeb | |||
b556f25b3c | |||
789f114c52 | |||
d36b91c294 | |||
a9eb115348 | |||
bd4fa7c900 | |||
38e1018663 | |||
21e9e6b47f | |||
dbe4fc23f1 | |||
dbb7ebcd4c | |||
ecb32920c6 | |||
046435d14c | |||
ca8befdfb6 | |||
d9c9b53e53 | |||
aebff4bd9c | |||
2bff406277 | |||
7a6f31107b | |||
57c4c9d189 | |||
3519a25e89 | |||
d073fb8ea7 | |||
9d1e0624a7 | |||
692c9c9dba | |||
ef6d5d0e99 | |||
d149ece3f4 | |||
f89fd48199 | |||
47ef1b2e7f | |||
7c0f80cbb8 | |||
3adb6d0473 | |||
03a8ce6d60 | |||
82d40c283a | |||
c683728f10 | |||
bf6479d5ec | |||
d6238b002a | |||
847b9efe2e | |||
019c5ec617 | |||
3dea681709 | |||
155e5ebdeb | |||
14117827cf | |||
e3c1789d3f | |||
24de455de2 | |||
0068957dcf | |||
8cca243457 | |||
c1ec8d27ed | |||
80ffcf7ac5 | |||
c9cf8614bf | |||
ca92b655d7 | |||
e637d2bbe4 | |||
f7e6ffb14d | |||
04092870fd | |||
15ace4fc54 | |||
66db41e5dd | |||
a54aa6ce0b | |||
0cb4e4ce8a | |||
c2b1114313 | |||
1ef822c9e7 | |||
0cf702c571 | |||
e0e0b2b842 | |||
d7b3f577a7 | |||
a3062e4021 | |||
0cea014686 | |||
c9cca96908 | |||
2e99f461f3 | |||
27463c1456 | |||
47f5f04922 | |||
6d0160cbf8 | |||
52b846a8b5 | |||
3f7fc68782 | |||
1eba11c6d8 | |||
552a57d5dc | |||
a83e3d11f6 | |||
2fc4c770fc | |||
0ea26a0a52 | |||
f1a742892f | |||
2031bb15ab | |||
17bf0db4b7 | |||
de85e3b9b1 | |||
3cfe3a4abb | |||
cbc59cf0d1 | |||
459a04b021 | |||
e2315b67db | |||
d6173a45d0 | |||
0e8f5bf773 | |||
349d20632d | |||
2221aee284 | |||
3b44ae5b24 | |||
323b871bbc | |||
a23373f4c8 | |||
e38f944096 | |||
3c5e1cac39 | |||
0f1139540c | |||
81218f8e0c | |||
cc439c2555 | |||
3efd423e8d | |||
effc519e1b | |||
cfaf0f0750 | |||
86abc3c6d2 | |||
c5ba143a4c | |||
a9d24cbbd7 | |||
2e6adf08a9 | |||
1c2ceb7f27 | |||
5f85afe386 | |||
05d79cc0e4 | |||
edcd1211b8 | |||
eb69bf92e7 | |||
92ed864d2e | |||
3eeea96a33 | |||
c701339303 | |||
e03e943597 | |||
50372b6518 | |||
b6b6b379de | |||
7d8fef21df | |||
0d0b9c12e8 | |||
7989493c23 | |||
f7e7174579 | |||
46a279bd0a | |||
4f796ce6b5 | |||
dd7bdbe4bf | |||
5e13907514 | |||
c0b0a00641 | |||
88688a2400 | |||
a50083874e | |||
8e84a3001a | |||
9a8fa77b90 | |||
677d5e3b79 | |||
abd6e0ea0b | |||
7778b2da3c | |||
bfee5ee11d | |||
608f9e14ec | |||
9381bb2c2c | |||
17e44d79cb | |||
25ef9ca970 | |||
170a3a0cf1 | |||
a76f44e7d8 | |||
8fa7dff7b9 | |||
face0856de | |||
ec66a939a9 | |||
c44dc93f23 | |||
d2a0133e31 | |||
455de4e66d | |||
61c1a4a9f5 | |||
604fe72b13 | |||
3c85045f6e | |||
d9fc28500d | |||
7d357a3513 | |||
b45661bc10 | |||
31c68b6041 | |||
d27d0c27ac | |||
4b1e98b37d | |||
5a72764667 | |||
30416f05a0 | |||
a555e8cdd0 | |||
c8710f274e | |||
40776d7557 | |||
9cb5ef734c | |||
62f96762dd | |||
84072ff78e | |||
a625c15a6b | |||
5545aac6a3 | |||
e09eda33b5 | |||
526ce234e5 | |||
507ec96a74 | |||
252bd8e8ba | |||
07341d3490 | |||
9df6f480ac | |||
6f4d254d44 | |||
a24255b274 | |||
c12092e88f | |||
031ba7f7a9 | |||
c8d4ef2f53 | |||
31c1b1aa98 | |||
31eb4eaded | |||
5f5f252fe2 | |||
c624d54a53 | |||
d735dc073f | |||
846e7ddcd9 | |||
d66278f1e9 | |||
1afd74ce23 | |||
c67416616c | |||
29052a94fb | |||
2d06cf1746 | |||
953db97e74 | |||
f7b4bdd2ad | |||
239c8dab36 | |||
237bd9f909 | |||
fef6a0f2be | |||
2d891f879c | |||
1e9c424622 | |||
cf670955c6 | |||
c49c2afa5d | |||
81871bcfd1 | |||
b2f426ba19 | |||
f8a3dc114e | |||
1330ad3e73 | |||
6efbbade29 | |||
3a91952989 | |||
5e676315e9 | |||
18dad33d2e | |||
945dc98b91 | |||
cac24f53b7 | |||
ab66454db6 | |||
a2527500a4 | |||
44d9998d44 | |||
b6bdfb3d14 | |||
c0cd965566 | |||
66268c5fbe | |||
2ab8c4423e | |||
2c52863893 | |||
77db3f966c | |||
797977b61a | |||
015f418198 | |||
88ae11c65f | |||
51e800db2c | |||
f05002851f | |||
b39364735e | |||
a657dba833 | |||
ba65924209 | |||
c0edea7835 | |||
a1145a6b27 | |||
83e5ccebf6 | |||
8457318a42 | |||
a422a812eb | |||
84836b13d8 | |||
360e5b76ee | |||
42ba3c24d6 | |||
4f5a3af221 | |||
f1690ab489 | |||
98d324947b | |||
5326fa0045 | |||
4d9aae64da | |||
d29c0cc90a | |||
28fa3382e3 | |||
715abd3467 | |||
01827479ce | |||
05fe2da5ec | |||
2a20098909 | |||
71a9ad5faf | |||
b814b8606f | |||
455ad55fab | |||
cde40a3b90 | |||
444727df93 | |||
aca98fe711 | |||
8078b42bbd | |||
1577f9c80c | |||
313d11ed7d | |||
907f20a45e |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist/** linguist-generated=true
|
25
.github/CONTRIBUTING.md
vendored
Normal file
25
.github/CONTRIBUTING.md
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
## How to contribute
|
||||
|
||||
### Did you find a bug?
|
||||
|
||||
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/golangci/golangci-lint-action/issues).
|
||||
|
||||
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/golangci/golangci-lint-action/issues/new).
|
||||
Be sure to include a **title and clear description**, as much relevant information as possible,
|
||||
and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
|
||||
|
||||
* **Do not open up a GitHub issue if the bug is a security vulnerability**,
|
||||
and instead to refer to our [security policy](https://github.com/golangci/golangci-lint-action?tab=security-ov-file).
|
||||
|
||||
### Do you intend to add a new feature or change an existing one?
|
||||
|
||||
* Suggest your change inside an [issue](https://github.com/golangci/golangci-lint-action/issues).
|
||||
|
||||
* Do not open a pull request on GitHub until you have collected positive feedback about the change.
|
||||
|
||||
### Did you write a patch that fixes a bug?
|
||||
|
||||
* Open a new GitHub pull request with the patch.
|
||||
|
||||
* Ensure the PR description clearly describes the problem and solution.
|
||||
Include the relevant issue number if applicable.
|
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Bug Report
|
||||
name: 🐞 Bug Report
|
||||
description: "Create a report to help us improve."
|
||||
body:
|
||||
- type: checkboxes
|
||||
@ -36,14 +36,29 @@ body:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: config
|
||||
id: workflow-file
|
||||
attributes:
|
||||
label: Workflow file
|
||||
value: |-
|
||||
<details>
|
||||
|
||||
```yml
|
||||
<add your file content here>
|
||||
```
|
||||
<add you file here>
|
||||
|
||||
</details>
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: config
|
||||
attributes:
|
||||
label: Golangci-lint configuration
|
||||
value: |-
|
||||
<details>
|
||||
|
||||
```yml
|
||||
<add your file content here>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
17
.github/ISSUE_TEMPLATE/config.yml
vendored
17
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,11 +1,14 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Questions
|
||||
url: https://github.com/golangci/golangci-lint-action/discussions
|
||||
about: If you have a question, or are looking for advice, please post on our Discussions forum!
|
||||
- name: golangci-lint main repository
|
||||
url: https://github.com/golangci/golangci-lint
|
||||
about: The main repository of golangci-lint.
|
||||
- name: golangci-lint documentation
|
||||
- name: 📖 Golangci-lint documentation
|
||||
url: https://golangci-lint.run
|
||||
about: Please take a look to our documentation.
|
||||
- name: ❓ Questions
|
||||
url: https://github.com/golangci/golangci-lint-action/discussions
|
||||
about: If you have a question, or are looking for advice, please post on our Discussions forum!
|
||||
- name: 💬 Chat on Slack
|
||||
url: https://gophers.slack.com/archives/CS0TBRKPC
|
||||
about: Maybe chatting with the community can help
|
||||
- name: 🏡 Golangci-lint main repository
|
||||
url: https://github.com/golangci/golangci-lint
|
||||
about: The main repository of golangci-lint.
|
||||
|
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Feature request
|
||||
name: 💡 Feature request
|
||||
description: "Suggest an idea for this project."
|
||||
body:
|
||||
- type: checkboxes
|
||||
|
5
.github/dependabot.yml
vendored
5
.github/dependabot.yml
vendored
@ -6,5 +6,10 @@ updates:
|
||||
interval: weekly
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
groups:
|
||||
dev-dependencies:
|
||||
dependency-type: development
|
||||
dependencies:
|
||||
dependency-type: production
|
||||
schedule:
|
||||
interval: weekly
|
||||
|
15
.github/release.yml
vendored
Normal file
15
.github/release.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: Changes
|
||||
labels:
|
||||
- '*'
|
||||
exclude:
|
||||
labels:
|
||||
- documentation
|
||||
- dependencies
|
||||
- title: Documentation
|
||||
labels:
|
||||
- documentation
|
||||
- title: Dependencies
|
||||
labels:
|
||||
- dependencies
|
6
.github/workflows/codeql.yaml
vendored
6
.github/workflows/codeql.yaml
vendored
@ -16,7 +16,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# 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.
|
||||
@ -31,7 +31,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
with:
|
||||
language: 'javascript'
|
||||
@ -41,4 +41,4 @@ jobs:
|
||||
npm run all
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
30
.github/workflows/test.yml
vendored
30
.github/workflows/test.yml
vendored
@ -11,9 +11,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- if: ${{ !(github.event_name == 'pull_request' && (github.event.pull_request.user.id == 49699333 || contains(github.event.pull_request.labels.*.name, 'dependencies'))) }}
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- if: github.event_name == 'pull_request' && (github.event.pull_request.user.id == 49699333 || contains(github.event.pull_request.labels.*.name, 'dependencies'))
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
@ -52,17 +52,17 @@ jobs:
|
||||
version:
|
||||
- ""
|
||||
- "latest"
|
||||
- "v1.53"
|
||||
- "v1.53.2"
|
||||
- "v1.58"
|
||||
- "v1.58.0"
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
go-version: oldstable
|
||||
- uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
@ -80,17 +80,17 @@ jobs:
|
||||
version:
|
||||
- ""
|
||||
- "latest"
|
||||
- "v1.53.2"
|
||||
- "b5093688c0d3008eaacd6066773a1a52e689252f"
|
||||
- "v1.58.0"
|
||||
- "4bf574a12bb61234e28e3d6172be6ed95b0e8baf"
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
go-version: oldstable
|
||||
- uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
@ -110,10 +110,10 @@ jobs:
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
go-version: oldstable
|
||||
- uses: ./
|
||||
with:
|
||||
working-directory: sample-go-mod
|
||||
|
524
README.md
524
README.md
@ -3,29 +3,40 @@
|
||||
[](https://github.com/golangci/golangci-lint-action/actions)
|
||||
|
||||
It's the official GitHub action for [golangci-lint](https://github.com/golangci/golangci-lint) from its authors.
|
||||
|
||||
The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters.
|
||||
|
||||

|
||||
|
||||
## Compatibility
|
||||

|
||||
|
||||
* `v3.0.0+` requires explicit setup-go installation step prior to using this action: `uses: actions/setup-go@v3`.
|
||||
The `skip-go-installation` option has been removed.
|
||||
* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3`
|
||||
* `v1.2.2` is deprecated due to we forgot to change the minimum version of `golangci-lint` to `v1.28.3` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
* `v1.2.1` works with `golangci-lint` version >= `v1.14.0` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
## Supporting Us
|
||||
|
||||
<!-- [](https://github.com/sponsors/golangci) -->
|
||||
[](https://opencollective.com/golangci-lint)
|
||||
[](https://golangci-lint.run/product/thanks/)
|
||||
|
||||
`golangci-lint` is a free and open-source project built by volunteers.
|
||||
|
||||
If you value it, consider supporting us, we appreciate it! :heart:
|
||||
|
||||
## How to use
|
||||
|
||||
We recommend running this action in a job separate from other jobs (`go test`, etc.)
|
||||
because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
|
||||
|
||||
Add `.github/workflows/golangci-lint.yml` with the following contents:
|
||||
|
||||
<details>
|
||||
<summary>Simple Example</summary>
|
||||
|
||||
```yaml
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
@ -38,57 +49,28 @@ jobs:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.20'
|
||||
cache: false
|
||||
go-version: stable
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
#
|
||||
# Note: by default the `.golangci.yml` file should be at the root of the repository.
|
||||
# The location of the configuration file can be changed by using `--config=`
|
||||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
|
||||
# Optional: if set to true then the all caching functionality will be complete disabled,
|
||||
# takes precedence over all other caching options.
|
||||
# skip-cache: true
|
||||
|
||||
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
||||
# skip-pkg-cache: true
|
||||
|
||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||
# skip-build-cache: true
|
||||
|
||||
# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
|
||||
# install-mode: "goinstall"
|
||||
version: v1.59
|
||||
```
|
||||
|
||||
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
||||
because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
|
||||
</details>
|
||||
|
||||
### Multiple OS Support
|
||||
|
||||
If you need to run linters for specific operating systems, you will need to use `v2` of the action. Here is a sample configuration file:
|
||||
<details>
|
||||
<summary>Multiple OS Example</summary>
|
||||
|
||||
```yaml
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
@ -100,60 +82,425 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go: ['1.20']
|
||||
os: [macos-latest, windows-latest]
|
||||
go: [stable]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
name: lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
cache: false
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
#
|
||||
# Note: by default the `.golangci.yml` file should be at the root of the repository.
|
||||
# The location of the configuration file can be changed by using `--config=`
|
||||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
|
||||
# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
|
||||
# install-mode: "goinstall"
|
||||
version: v1.59
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```.gitattributes
|
||||
*.go text eol=lf
|
||||
```
|
||||
|
||||
## Comments and Annotations
|
||||
</details>
|
||||
|
||||
Currently, GitHub parses the action's output and creates [annotations](https://github.community/t5/GitHub-Actions/What-are-annotations/td-p/30770).
|
||||
<details>
|
||||
<summary>Go Workspace Example</summary>
|
||||
|
||||
```yaml
|
||||
name: golangci-lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
- "master"
|
||||
|
||||
env:
|
||||
GO_VERSION: stable
|
||||
GOLANGCI_LINT_VERSION: v1.59
|
||||
|
||||
jobs:
|
||||
detect-modules:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
modules: ${{ steps.set-modules.outputs.modules }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- id: set-modules
|
||||
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
|
||||
|
||||
golangci-lint:
|
||||
needs: detect-modules
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: golangci-lint ${{ matrix.modules }}
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: ${{ env.GOLANGCI_LINT_VERSION }}
|
||||
working-directory: ${{ matrix.modules }}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Go Workspace Example (Multiple OS)</summary>
|
||||
|
||||
```yaml
|
||||
# ./.github/workflows/golangci-lint.yml
|
||||
name: golangci-lint (multi OS)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
golangci-lint:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ stable, oldstable ]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
uses: ./.github/workflows/.golangci-lint-reusable.yml
|
||||
with:
|
||||
os: ${{ matrix.os }}
|
||||
go-version: ${{ matrix.go-version }}
|
||||
golangci-lint-version: v1.59
|
||||
```
|
||||
|
||||
```yaml
|
||||
# ./.github/workflows/.golangci-lint-reusable.yml
|
||||
name: golangci-lint-reusable
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
os:
|
||||
description: 'OS'
|
||||
required: true
|
||||
type: string
|
||||
go-version:
|
||||
description: 'Go version'
|
||||
required: true
|
||||
type: string
|
||||
default: stable
|
||||
golangci-lint-version:
|
||||
description: 'Golangci-lint version'
|
||||
type: string
|
||||
default: 'v1.59.1'
|
||||
|
||||
jobs:
|
||||
detect-modules:
|
||||
runs-on: ${{ inputs.os }}
|
||||
outputs:
|
||||
modules: ${{ steps.set-modules.outputs.modules }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ inputs.go-version }}
|
||||
- id: set-modules
|
||||
shell: bash # require for Windows to be able to use $GITHUB_OUTPUT https://github.com/actions/runner/issues/2224
|
||||
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
|
||||
|
||||
golangci-lint:
|
||||
needs: detect-modules
|
||||
runs-on: ${{ inputs.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ inputs.go-version }}
|
||||
- name: golangci-lint ${{ matrix.modules }}
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: ${{ inputs.golangci-lint-version }}
|
||||
working-directory: ${{ matrix.modules }}
|
||||
```
|
||||
|
||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
|
||||
|
||||
```.gitattributes
|
||||
*.go text eol=lf
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Compatibility
|
||||
|
||||
* `v6.0.0+` removes `annotations` option, removes the default output format (`github-actions`).
|
||||
* `v5.0.0+` removes `skip-pkg-cache` and `skip-build-cache` because the cache related to Go itself is already handled by `actions/setup-go`.
|
||||
* `v4.0.0+` requires an explicit `actions/setup-go` installation step before using this action: `uses: actions/setup-go@v5`.
|
||||
The `skip-go-installation` option has been removed.
|
||||
* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3`
|
||||
* `v1.2.2` is deprecated due to we forgot to change the minimum version of `golangci-lint` to `v1.28.3` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
* `v1.2.1` works with `golangci-lint` version >= `v1.14.0` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
|
||||
## Options
|
||||
|
||||
### `version`
|
||||
|
||||
(required)
|
||||
|
||||
The version of golangci-lint to use.
|
||||
|
||||
When `install-mode` is:
|
||||
* `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
|
||||
* `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit.
|
||||
* `none`: the value is ignored.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: v1.58
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `install-mode`
|
||||
|
||||
(optional)
|
||||
|
||||
The mode to install golangci-lint: it can be `binary`, `goinstall`, or `none`.
|
||||
|
||||
The default value is `binary`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
install-mode: "goinstall"
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `github-token`
|
||||
|
||||
(optional)
|
||||
|
||||
When using `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@v6
|
||||
with:
|
||||
github-token: xxx
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `only-new-issues`
|
||||
|
||||
(optional)
|
||||
|
||||
Show only new issues.
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
* `pull_request` and `pull_request_target`: the action gets the diff of the PR content from the [GitHub API](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request) and use it with `--new-from-patch`.
|
||||
* `push`: the action gets the diff of the push content (difference between commits before and after the push) from the [GitHub API](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits) and use it with `--new-from-patch`.
|
||||
* `merge_group`: the action gets the diff by using `--new-from-rev` option (relies on git).
|
||||
You should add the option `fetch-depth: 0` to `actions/checkout` step.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
only-new-issues: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `working-directory`
|
||||
|
||||
(optional)
|
||||
|
||||
Working directory, useful for monorepos.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
working-directory: somedir
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `args`
|
||||
|
||||
(optional)
|
||||
|
||||
golangci-lint command line arguments.
|
||||
|
||||
Note: By default, the `.golangci.yml` file should be at the root of the repository.
|
||||
The location of the configuration file can be changed by using `--config=`
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `problem-matchers`
|
||||
|
||||
(optional)
|
||||
|
||||
Force the usage of the embedded problem matchers.
|
||||
|
||||
By default, the [problem matcher of Go (`actions/setup-go`)](https://github.com/actions/setup-go/blob/main/matchers.json) already handles the golangci-lint output (`colored-line-number`).
|
||||
|
||||
Works only with `colored-line-number` (the golangci-lint default).
|
||||
|
||||
https://golangci-lint.run/usage/configuration/#output-configuration
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
problem-matchers: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `skip-cache`
|
||||
|
||||
(optional)
|
||||
|
||||
If set to `true`, then all caching functionality will be completely disabled,
|
||||
takes precedence over all other caching options.
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
skip-cache: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `skip-save-cache`
|
||||
|
||||
(optional)
|
||||
|
||||
If set to `true`, caches will not be saved, but they may still be restored, required `skip-cache: false`.
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
skip-save-cache: true
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `cache-invalidation-interval`
|
||||
|
||||
(optional)
|
||||
|
||||
Periodically invalidate the cache every `cache-invalidation-interval` days to ensure that outdated data is removed and fresh data is loaded.
|
||||
|
||||
The default value is `7`.
|
||||
|
||||
If set the number is `<= 0`, the cache will be always invalidate (Not recommended).
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```yml
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
cache-invalidation-interval: 15
|
||||
# ...
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Annotations
|
||||
|
||||
Currently, GitHub parses the action's output and creates [annotations](https://github.blog/2018-12-14-introducing-check-runs-and-annotations/).
|
||||
|
||||
The restrictions of annotations are the following:
|
||||
|
||||
1. Currently, they don't support markdown formatting (see the [feature request](https://github.community/t5/GitHub-API-Development-and/Checks-Ability-to-include-Markdown-in-line-annotations/m-p/56704))
|
||||
2. They aren't shown in list of comments like it was with [golangci.com](https://golangci.com). If you would like to have comments - please, up-vote [the issue](https://github.com/golangci/golangci-lint-action/issues/5).
|
||||
1. Currently, they don't support Markdown formatting (see the [feature request](https://github.community/t5/GitHub-API-Development-and/Checks-Ability-to-include-Markdown-in-line-annotations/m-p/56704))
|
||||
2. They aren't shown in the list of comments.
|
||||
If you would like to have comments - please, up-vote [the issue](https://github.com/golangci/golangci-lint-action/issues/5).
|
||||
3. The number of annotations is [limited](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md#limitations).
|
||||
|
||||
To enable annotations, you need to add the `checks` permission to your action.
|
||||
|
||||
```yaml annotate
|
||||
permissions:
|
||||
# Required: allow read access to the content for analysis.
|
||||
contents: read
|
||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||
pull-requests: read
|
||||
# Optional: allow write access to checks to allow the action to annotate code in the PR.
|
||||
checks: write
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
The action was implemented with performance in mind:
|
||||
|
||||
1. We cache data by [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache) between builds: Go build cache, Go modules cache, golangci-lint analysis cache.
|
||||
1. We cache data from golangci-lint analysis between builds by using [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache).
|
||||
2. We don't use Docker because image pulling is slow.
|
||||
3. We do as much as we can in parallel, e.g. we download cache, go and golangci-lint binary in parallel.
|
||||
3. We do as much as we can in parallel, e.g. we download cache, and golangci-lint binary in parallel.
|
||||
|
||||
For example, in a repository of [golangci-lint](https://github.com/golangci/golangci-lint) running this action without the cache takes 50s, but with cache takes 14s:
|
||||
* in parallel:
|
||||
@ -163,28 +510,33 @@ For example, in a repository of [golangci-lint](https://github.com/golangci/gola
|
||||
|
||||
## Internals
|
||||
|
||||
We use JavaScript-based action. We don't use Docker-based action because:
|
||||
We use JavaScript-based action.
|
||||
We don't use Docker-based action because:
|
||||
|
||||
1. docker pulling is slow currently
|
||||
1. Docker pulling is slow currently
|
||||
2. it's easier to use caching from [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache)
|
||||
|
||||
We support different platforms, such as `ubuntu`, `macos` and `windows` with `x32` and `x64` archs.
|
||||
We support different platforms, such as `ubuntu`, `macos`, and `windows` with `x32` and `x64` archs.
|
||||
|
||||
Inside our action we perform 3 steps:
|
||||
Inside our action, we perform 3 steps:
|
||||
|
||||
1. Setup environment running in parallel:
|
||||
* restore [cache](https://github.com/actions/cache) of previous analyzes
|
||||
* fetch [action config](https://github.com/golangci/golangci-lint/blob/master/assets/github-action-config.json) and find the latest `golangci-lint` patch version
|
||||
for needed version (users of this action can specify only minor version of `golangci-lint`). After that install [golangci-lint](https://github.com/golangci/golangci-lint) using [@actions/tool-cache](https://github.com/actions/toolkit/tree/master/packages/tool-cache)
|
||||
* restore [cache](https://github.com/actions/cache) of previous analyses
|
||||
* fetch [action config](https://github.com/golangci/golangci-lint/blob/master/assets/github-action-config.json) and find the latest `golangci-lint` patch version for needed version
|
||||
(users of this action can specify only minor version of `golangci-lint`).
|
||||
After that install [golangci-lint](https://github.com/golangci/golangci-lint) using [@actions/tool-cache](https://github.com/actions/toolkit/tree/master/packages/tool-cache)
|
||||
2. Run `golangci-lint` with specified by user `args`
|
||||
3. Save cache for later builds
|
||||
|
||||
### Caching internals
|
||||
|
||||
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
|
||||
2. The primary caching key looks like `golangci-lint.cache-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
|
||||
our cache (every 7 days). `go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed.
|
||||
3. We use [restore keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key): `golangci-lint.cache-{interval_number}-`. GitHub matches keys by prefix if we have no exact match for the primary cache.
|
||||
1. We save and restore the following directory: `~/.cache/golangci-lint`.
|
||||
2. The primary caching key looks like `golangci-lint.cache-{runner_os}-{working_directory}-{interval_number}-{go.mod_hash}`.
|
||||
Interval number ensures that we periodically invalidate our cache (every 7 days).
|
||||
`go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed.
|
||||
3. We use [restore keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key):
|
||||
`golangci-lint.cache-{runner_os}-{working_directory}-{interval_number}-`.
|
||||
GitHub matches keys by prefix if we have no exact match for the primary cache.
|
||||
|
||||
This scheme is basic and needs improvements. Pull requests and ideas are welcome.
|
||||
|
||||
|
48
action.yml
48
action.yml
@ -1,13 +1,19 @@
|
||||
name: "Run golangci-lint"
|
||||
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
|
||||
name: "Golangci-lint"
|
||||
description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
|
||||
author: "golangci"
|
||||
inputs:
|
||||
version:
|
||||
description: "version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version"
|
||||
description: |
|
||||
The version of golangci-lint to use.
|
||||
When `install-mode` is:
|
||||
- `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
|
||||
- `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit.
|
||||
- `none`: the value is ignored.
|
||||
required: false
|
||||
args:
|
||||
description: "golangci-lint command line arguments"
|
||||
default: ""
|
||||
install-mode:
|
||||
description: "The mode to install golangci-lint. It can be 'binary', 'goinstall', or 'none'."
|
||||
default: "binary"
|
||||
required: false
|
||||
working-directory:
|
||||
description: "golangci-lint working directory, default is project root"
|
||||
@ -18,30 +24,36 @@ inputs:
|
||||
required: false
|
||||
only-new-issues:
|
||||
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
|
||||
default: false
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-cache:
|
||||
description: |
|
||||
if set to true then the all caching functionality will be complete disabled,
|
||||
takes precedence over all other caching options.
|
||||
default: false
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-pkg-cache:
|
||||
description: "if set to true then the action doesn't cache or restore ~/go/pkg."
|
||||
default: false
|
||||
skip-save-cache:
|
||||
description: |
|
||||
if set to true then the action will not save any caches, but it may still
|
||||
restore existing caches, subject to other options.
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-build-cache:
|
||||
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
|
||||
default: false
|
||||
problem-matchers:
|
||||
description: "Force the usage of the embedded problem matchers"
|
||||
default: 'false'
|
||||
required: false
|
||||
install-mode:
|
||||
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
|
||||
default: "binary"
|
||||
args:
|
||||
description: "golangci-lint command line arguments"
|
||||
default: ""
|
||||
required: false
|
||||
cache-invalidation-interval:
|
||||
description: "Periodically invalidate a cache because a new code being added. (number of days)"
|
||||
default: '7'
|
||||
required: false
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "dist/run/index.js"
|
||||
post: "dist/post_run/index.js"
|
||||
branding:
|
||||
icon: "shield"
|
||||
color: "yellow"
|
||||
color: "white"
|
||||
|
38245
dist/post_run/index.js
generated
vendored
38245
dist/post_run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
38245
dist/run/index.js
generated
vendored
38245
dist/run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
4697
package-lock.json
generated
4697
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -24,27 +24,29 @@
|
||||
"author": "golangci",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.2.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/cache": "^3.2.4",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@actions/http-client": "^2.1.0",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/http-client": "^2.2.1",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@types/tmp": "^0.2.3",
|
||||
"tmp": "^0.2.1"
|
||||
"@types/node": "^22.0.0",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"@types/which": "^3.0.4",
|
||||
"tmp": "^0.2.3",
|
||||
"which": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"typescript": "^5.1.3"
|
||||
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
||||
"@typescript-eslint/parser": "^7.17.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"prettier": "^3.3.3",
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
|
17
problem-matchers.json
Normal file
17
problem-matchers.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "golangci-lint-colored-line-number",
|
||||
"severity": "error",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^([^:]+):(\\d+):(?:(\\d+):)?\\s+(.+ \\(.+\\))$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"message": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -167,7 +167,7 @@ require (
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
@ -924,8 +924,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
58
src/cache.ts
58
src/cache.ts
@ -20,31 +20,18 @@ function checksumFile(hashName: string, path: string): Promise<string> {
|
||||
const pathExists = async (path: string): Promise<boolean> => !!(await fs.promises.stat(path).catch(() => false))
|
||||
|
||||
const getLintCacheDir = (): string => {
|
||||
return path.resolve(`${process.env.HOME}/.cache/golangci-lint`)
|
||||
}
|
||||
const home = process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME
|
||||
|
||||
const getCacheDirs = (): string[] => {
|
||||
// Not existing dirs are ok here: it works.
|
||||
const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim()
|
||||
const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim()
|
||||
const dirs = [getLintCacheDir()]
|
||||
|
||||
if (skipBuildCache.toLowerCase() == "true") {
|
||||
core.info(`Omitting ~/.cache/go-build from cache directories`)
|
||||
} else {
|
||||
dirs.push(path.resolve(`${process.env.HOME}/.cache/go-build`))
|
||||
}
|
||||
if (skipPkgCache.toLowerCase() == "true") {
|
||||
core.info(`Omitting ~/go/pkg from cache directories`)
|
||||
} else {
|
||||
dirs.push(path.resolve(`${process.env.HOME}/go/pkg`))
|
||||
}
|
||||
|
||||
return dirs
|
||||
return path.resolve(`${home}`, `.cache`, `golangci-lint`)
|
||||
}
|
||||
|
||||
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
||||
const now = new Date()
|
||||
|
||||
if (invalidationIntervalDays <= 0) {
|
||||
return `${now.getTime()}`
|
||||
}
|
||||
|
||||
const secondsSinceEpoch = now.getTime() / 1000
|
||||
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400))
|
||||
return intervalNumber.toString()
|
||||
@ -52,28 +39,42 @@ const getIntervalKey = (invalidationIntervalDays: number): string => {
|
||||
|
||||
async function buildCacheKeys(): Promise<string[]> {
|
||||
const keys = []
|
||||
// Periodically invalidate a cache because a new code being added.
|
||||
// TODO: configure it via inputs.
|
||||
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`
|
||||
keys.push(cacheKey)
|
||||
|
||||
// Cache by OS.
|
||||
let cacheKey = `golangci-lint.cache-${process.env?.RUNNER_OS}-`
|
||||
|
||||
// Get working directory from input
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
|
||||
if (workingDirectory) {
|
||||
cacheKey += `${workingDirectory}-`
|
||||
}
|
||||
|
||||
// Periodically invalidate a cache because a new code being added.
|
||||
const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim())
|
||||
cacheKey += `${getIntervalKey(invalidationIntervalDays)}-`
|
||||
|
||||
keys.push(cacheKey)
|
||||
|
||||
// create path to go.mod prepending the workingDirectory if it exists
|
||||
const goModPath = path.join(workingDirectory, `go.mod`)
|
||||
|
||||
core.info(`Checking for go.mod: ${goModPath}`)
|
||||
|
||||
if (await pathExists(goModPath)) {
|
||||
// Add checksum to key to invalidate a cache when dependencies change.
|
||||
cacheKey += await checksumFile(`sha1`, goModPath)
|
||||
} else {
|
||||
cacheKey += `nogomod`
|
||||
}
|
||||
|
||||
keys.push(cacheKey)
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
export async function restoreCache(): Promise<void> {
|
||||
if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||
|
||||
if (!utils.isValidEvent()) {
|
||||
utils.logWarning(
|
||||
@ -97,7 +98,7 @@ export async function restoreCache(): Promise<void> {
|
||||
}
|
||||
core.saveState(State.CachePrimaryKey, primaryKey)
|
||||
try {
|
||||
const cacheKey = await cache.restoreCache(getCacheDirs(), primaryKey, restoreKeys)
|
||||
const cacheKey = await cache.restoreCache([getLintCacheDir()], primaryKey, restoreKeys)
|
||||
if (!cacheKey) {
|
||||
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(", ")}`)
|
||||
return
|
||||
@ -115,7 +116,8 @@ export async function restoreCache(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function saveCache(): Promise<void> {
|
||||
if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return
|
||||
if (core.getBooleanInput(`skip-cache`, { required: true })) return
|
||||
if (core.getBooleanInput(`skip-save-cache`, { required: true })) return
|
||||
|
||||
// Validate inputs, this can cause task failure
|
||||
if (!utils.isValidEvent()) {
|
||||
@ -127,7 +129,7 @@ export async function saveCache(): Promise<void> {
|
||||
|
||||
const startedAt = Date.now()
|
||||
|
||||
const cacheDirs = getCacheDirs()
|
||||
const cacheDirs = [getLintCacheDir()]
|
||||
const primaryKey = core.getState(State.CachePrimaryKey)
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Error retrieving key from state.`)
|
||||
|
@ -38,6 +38,7 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||
export enum InstallMode {
|
||||
Binary = "binary",
|
||||
GoInstall = "goinstall",
|
||||
None = "none",
|
||||
}
|
||||
|
||||
type ExecRes = {
|
||||
|
156
src/run.ts
156
src/run.ts
@ -1,52 +1,78 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as github from "@actions/github"
|
||||
import { Context } from "@actions/github/lib/context"
|
||||
import { exec, ExecOptions } from "child_process"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { dir } from "tmp"
|
||||
import { promisify } from "util"
|
||||
import which from "which"
|
||||
|
||||
import { restoreCache, saveCache } from "./cache"
|
||||
import { installLint, InstallMode } from "./install"
|
||||
import { alterDiffPatch } from "./utils/diffUtils"
|
||||
import { findLintVersion } from "./version"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
const writeFile = promisify(fs.writeFile)
|
||||
const createTempDir = promisify(dir)
|
||||
|
||||
function isOnlyNewIssues(): boolean {
|
||||
return core.getBooleanInput(`only-new-issues`, { required: true })
|
||||
}
|
||||
|
||||
async function prepareLint(): Promise<string> {
|
||||
const mode = core.getInput("install-mode").toLowerCase()
|
||||
|
||||
if (mode === InstallMode.None) {
|
||||
const bin = await which("golangci-lint", { nothrow: true })
|
||||
if (!bin) {
|
||||
throw new Error("golangci-lint binary not found in the PATH")
|
||||
}
|
||||
return bin
|
||||
}
|
||||
|
||||
const versionConfig = await findLintVersion(<InstallMode>mode)
|
||||
|
||||
return await installLint(versionConfig, <InstallMode>mode)
|
||||
}
|
||||
|
||||
async function fetchPatch(): Promise<string> {
|
||||
const onlyNewIssues = core.getInput(`only-new-issues`, { required: true }).trim()
|
||||
if (onlyNewIssues !== `false` && onlyNewIssues !== `true`) {
|
||||
throw new Error(`invalid value of "only-new-issues": "${onlyNewIssues}", expected "true" or "false"`)
|
||||
}
|
||||
if (onlyNewIssues === `false`) {
|
||||
if (!isOnlyNewIssues()) {
|
||||
return ``
|
||||
}
|
||||
|
||||
const ctx = github.context
|
||||
if (ctx.eventName !== `pull_request`) {
|
||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`)
|
||||
return ``
|
||||
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
case `pull_request_target`:
|
||||
return await fetchPullRequestPatch(ctx)
|
||||
case `push`:
|
||||
return await fetchPushPatch(ctx)
|
||||
case `merge_group`:
|
||||
return ``
|
||||
default:
|
||||
core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`)
|
||||
return ``
|
||||
}
|
||||
const pull = ctx.payload.pull_request
|
||||
if (!pull) {
|
||||
}
|
||||
|
||||
async function fetchPullRequestPatch(ctx: Context): Promise<string> {
|
||||
const pr = ctx.payload.pull_request
|
||||
if (!pr) {
|
||||
core.warning(`No pull request in context`)
|
||||
return ``
|
||||
}
|
||||
|
||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||
|
||||
let patch: string
|
||||
try {
|
||||
const patchResp = await octokit.rest.pulls.get({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.repo,
|
||||
[`pull_number`]: pull.number,
|
||||
[`pull_number`]: pr.number,
|
||||
mediaType: {
|
||||
format: `diff`,
|
||||
},
|
||||
@ -68,7 +94,45 @@ async function fetchPatch(): Promise<string> {
|
||||
const tempDir = await createTempDir()
|
||||
const patchPath = path.join(tempDir, "pull.patch")
|
||||
core.info(`Writing patch to ${patchPath}`)
|
||||
await writeFile(patchPath, patch)
|
||||
await writeFile(patchPath, alterDiffPatch(patch))
|
||||
return patchPath
|
||||
} catch (err) {
|
||||
console.warn(`failed to save pull request patch:`, err)
|
||||
return `` // don't fail the action, but analyze without patch
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchPushPatch(ctx: Context): Promise<string> {
|
||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||
|
||||
let patch: string
|
||||
try {
|
||||
const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.repo,
|
||||
basehead: `${ctx.payload.before}...${ctx.payload.after}`,
|
||||
mediaType: {
|
||||
format: `diff`,
|
||||
},
|
||||
})
|
||||
|
||||
if (patchResp.status !== 200) {
|
||||
core.warning(`failed to fetch push patch: response status is ${patchResp.status}`)
|
||||
return `` // don't fail the action, but analyze without patch
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
patch = patchResp.data as any
|
||||
} catch (err) {
|
||||
console.warn(`failed to fetch push patch:`, err)
|
||||
return `` // don't fail the action, but analyze without patch
|
||||
}
|
||||
|
||||
try {
|
||||
const tempDir = await createTempDir()
|
||||
const patchPath = path.join(tempDir, "push.patch")
|
||||
core.info(`Writing patch to ${patchPath}`)
|
||||
await writeFile(patchPath, alterDiffPatch(patch))
|
||||
return patchPath
|
||||
} catch (err) {
|
||||
console.warn(`failed to save pull request patch:`, err)
|
||||
@ -86,11 +150,9 @@ async function prepareEnv(): Promise<Env> {
|
||||
|
||||
// Prepare cache, lint and go in parallel.
|
||||
await restoreCache()
|
||||
const prepareLintPromise = prepareLint()
|
||||
const patchPromise = fetchPatch()
|
||||
|
||||
const lintPath = await prepareLintPromise
|
||||
const patchPath = await patchPromise
|
||||
const lintPath = await prepareLint()
|
||||
const patchPath = await fetchPatch()
|
||||
|
||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||
|
||||
@ -132,35 +194,69 @@ async function runLint(lintPath: 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}`)
|
||||
}
|
||||
}
|
||||
|
||||
const formats = (userArgsMap.get("out-format") || "")
|
||||
.trim()
|
||||
.split(",")
|
||||
.filter((f) => f.length > 0)
|
||||
.filter((f) => !f.startsWith(`github-actions`))
|
||||
.concat("github-actions")
|
||||
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
|
||||
.join(",")
|
||||
|
||||
addedArgs.push(`--out-format=${formats}`)
|
||||
if (formats) {
|
||||
// Adds formats but without `github-actions` format.
|
||||
addedArgs.push(`--out-format=${formats}`)
|
||||
}
|
||||
|
||||
// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
|
||||
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
||||
|
||||
if (patchPath) {
|
||||
if (isOnlyNewIssues()) {
|
||||
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
|
||||
throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
|
||||
}
|
||||
addedArgs.push(`--new-from-patch=${patchPath}`)
|
||||
|
||||
// Override config values.
|
||||
addedArgs.push(`--new=false`)
|
||||
addedArgs.push(`--new-from-rev=`)
|
||||
const ctx = github.context
|
||||
|
||||
core.info(`only new issues on ${ctx.eventName}: ${patchPath}`)
|
||||
|
||||
switch (ctx.eventName) {
|
||||
case `pull_request`:
|
||||
case `pull_request_target`:
|
||||
case `push`:
|
||||
if (patchPath) {
|
||||
addedArgs.push(`--new-from-patch=${patchPath}`)
|
||||
|
||||
// Override config values.
|
||||
addedArgs.push(`--new=false`)
|
||||
addedArgs.push(`--new-from-rev=`)
|
||||
}
|
||||
break
|
||||
case `merge_group`:
|
||||
addedArgs.push(`--new-from-rev=${ctx.payload.merge_group.base_sha}`)
|
||||
|
||||
// Override config values.
|
||||
addedArgs.push(`--new=false`)
|
||||
addedArgs.push(`--new-from-patch=`)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
const cmdArgs: ExecOptions = {}
|
||||
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
if (workingDirectory) {
|
||||
if (patchPath) {
|
||||
// TODO: make them compatible
|
||||
throw new Error(`options working-directory and only-new-issues aren't compatible`)
|
||||
}
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
||||
}
|
||||
@ -172,7 +268,7 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
||||
|
||||
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
||||
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`)
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)
|
||||
|
||||
const startedAt = Date.now()
|
||||
try {
|
||||
|
56
src/utils/diffUtils.ts
Normal file
56
src/utils/diffUtils.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as path from "path"
|
||||
|
||||
// If needed alter diff file to be compatible with working directory
|
||||
export function alterDiffPatch(patch: string): string {
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
|
||||
if (workingDirectory) {
|
||||
return alterPatchWithWorkingDirectory(patch, workingDirectory)
|
||||
}
|
||||
|
||||
return patch
|
||||
}
|
||||
|
||||
function alterPatchWithWorkingDirectory(patch: string, workingDirectory: string): string {
|
||||
const workspace = process.env["GITHUB_WORKSPACE"] || ""
|
||||
|
||||
const wd = path.relative(workspace, workingDirectory)
|
||||
|
||||
// ignore diff sections not related to the working directory
|
||||
let ignore = false
|
||||
|
||||
const lines = patch.split("\n")
|
||||
const filteredLines = []
|
||||
|
||||
// starts with "--- a/xxx/" or "+++ a/xxx/" or "--- b/xxx/" or "+++ b/xxx/"
|
||||
const cleanDiff = new RegExp(`^((?:\\+{3}|-{3}) [ab]\\/)${escapeRegExp(wd)}\\/(.*)`, "gm")
|
||||
|
||||
// contains " a/xxx/" or " b/xxx/"
|
||||
const firstLine = new RegExp(`( [ab]\\/)${escapeRegExp(wd)}\\/(.*)`, "gm")
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("diff --git")) {
|
||||
ignore = !line.includes(` a/${wd}/`)
|
||||
if (ignore) {
|
||||
continue
|
||||
}
|
||||
|
||||
filteredLines.push(line.replaceAll(firstLine, "$1$2"))
|
||||
} else {
|
||||
if (ignore) {
|
||||
continue
|
||||
}
|
||||
|
||||
filteredLines.push(line.replaceAll(cleanDiff, "$1$2"))
|
||||
}
|
||||
}
|
||||
|
||||
// Join the modified lines back into a diff string
|
||||
return filteredLines.join("\n")
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
||||
function escapeRegExp(exp: string): string {
|
||||
return exp.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 90 KiB |
BIN
static/colored-line-number.png
Normal file
BIN
static/colored-line-number.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"target": "ES2021", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
|
Reference in New Issue
Block a user