Compare commits

...

76 Commits

Author SHA1 Message Date
23faadfdeb doc: improve readme 2024-05-07 01:56:19 +02:00
b556f25b3c doc: improve readme 2024-05-07 01:44:28 +02:00
789f114c52 feat: rewrite format handling (#1038) 2024-05-07 01:40:17 +02:00
d36b91c294 build(deps-dev): bump @typescript-eslint/parser from 7.7.1 to 7.8.0 (#1035) 2024-05-06 15:48:38 +02:00
a9eb115348 build(deps): bump @types/node from 20.12.7 to 20.12.8 (#1036) 2024-05-06 15:42:05 +02:00
bd4fa7c900 build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.7.1 to 7.8.0 (#1034) 2024-05-06 15:41:21 +02:00
38e1018663 feat: improve log about pwd/cwd (#1033) 2024-05-05 01:13:21 +02:00
21e9e6b47f feat: use OS and working-directory as cache key (#1032) 2024-05-04 18:43:48 +02:00
dbe4fc23f1 chore: use getBooleanInput 2024-05-04 17:49:04 +02:00
dbb7ebcd4c feat: add option to control cache invalidation interval (#1031) 2024-05-04 17:47:25 +02:00
ecb32920c6 feat: uses 2 dots compare syntax for push diff (#1030) 2024-05-04 16:54:30 +02:00
046435d14c doc: improve options documentation 2024-05-04 02:42:39 +02:00
ca8befdfb6 doc: improve options documentation 2024-05-04 02:36:06 +02:00
d9c9b53e53 chore: improve marketplace style 2024-05-04 01:41:30 +02:00
aebff4bd9c feat: add option to enable/disable annotations 2024-05-04 01:40:50 +02:00
2bff406277 doc: improve options documentation 2024-05-04 01:27:11 +02:00
7a6f31107b doc: improve options description 2024-05-04 01:17:12 +02:00
57c4c9d189 docs: update readme 2024-05-04 00:37:42 +02:00
3519a25e89 chore: update tests workflow 2024-05-04 00:37:42 +02:00
d073fb8ea7 doc: add information about annotation limitations 2024-05-01 04:24:14 +02:00
9d1e0624a7 feat: only new issues enhancements (#1029) 2024-04-29 17:07:23 +02:00
692c9c9dba build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.7.0 to 7.7.1 (#1028) 2024-04-29 13:56:18 +02:00
ef6d5d0e99 build(deps-dev): bump @typescript-eslint/parser from 7.7.0 to 7.7.1 (#1027) 2024-04-29 13:37:38 +02:00
d149ece3f4 docs: update readme 2024-04-27 04:18:26 +02:00
f89fd48199 docs: update readme 2024-04-27 03:06:28 +02:00
47ef1b2e7f docs: update readme 2024-04-26 17:25:34 +02:00
7c0f80cbb8 docs: update readme 2024-04-25 03:39:35 +02:00
3adb6d0473 docs: update readme 2024-04-25 03:38:07 +02:00
03a8ce6d60 docs: update readme 2024-04-25 03:35:41 +02:00
82d40c283a feat: remove Go cache management (#1024) 2024-04-25 03:26:57 +02:00
c683728f10 feat: add option to not save cache (#851) 2024-04-25 01:17:21 +00:00
bf6479d5ec feat: add support for pull_request_target and only-new-issues (#506) 2024-04-25 03:03:53 +02:00
d6238b002a build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.6.0 to 7.7.0 (#1023) 2024-04-22 16:53:44 +02:00
847b9efe2e build(deps-dev): bump @typescript-eslint/parser from 7.5.0 to 7.7.0 (#1022) 2024-04-22 11:09:08 +02:00
019c5ec617 build(deps-dev): bump eslint-plugin-simple-import-sort from 12.0.0 to 12.1.0 (#1018) 2024-04-15 11:30:10 +00:00
3dea681709 build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.5.0 to 7.6.0 (#1019) 2024-04-15 13:23:06 +02:00
155e5ebdeb build(deps-dev): bump typescript from 5.4.4 to 5.4.5 (#1017) 2024-04-15 13:22:12 +02:00
14117827cf build(deps): bump @types/node from 20.12.5 to 20.12.7 (#1016) 2024-04-15 13:21:54 +02:00
e3c1789d3f build(deps-dev): bump @typescript-eslint/parser from 7.4.0 to 7.5.0 (#1014) 2024-04-08 15:02:41 +02:00
24de455de2 build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.4.0 to 7.5.0 (#1013) 2024-04-08 13:31:32 +02:00
0068957dcf build(deps): bump @types/node from 20.12.2 to 20.12.5 (#1012) 2024-04-08 13:31:06 +02:00
8cca243457 build(deps-dev): bump typescript from 5.4.3 to 5.4.4 (#1011) 2024-04-08 13:30:51 +02:00
c1ec8d27ed build(deps): bump undici from 5.28.3 to 5.28.4 (#1010)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-04-04 21:23:29 +02:00
80ffcf7ac5 build(deps-dev): bump @typescript-eslint/parser from 7.3.1 to 7.4.0 (#1009) 2024-04-01 16:07:04 +02:00
c9cf8614bf build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.3.1 to 7.4.0 (#1008) 2024-04-01 14:50:56 +02:00
ca92b655d7 build(deps): bump @types/node from 20.11.30 to 20.12.2 (#1007) 2024-04-01 14:50:30 +02:00
e637d2bbe4 build(deps-dev): bump @typescript-eslint/parser from 7.2.0 to 7.3.1 (#1006) 2024-03-25 11:54:13 +00:00
f7e6ffb14d build(deps-dev): bump typescript from 5.4.2 to 5.4.3 (#1005) 2024-03-25 12:42:58 +01:00
04092870fd build(deps): bump @types/node from 20.11.28 to 20.11.30 (#1004) 2024-03-25 12:42:27 +01:00
15ace4fc54 build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.2.0 to 7.3.1 (#1003) 2024-03-25 12:42:10 +01:00
66db41e5dd build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.1.1 to 7.2.0 (#999) 2024-03-18 13:41:34 +01:00
a54aa6ce0b build(deps): bump @types/node from 20.11.25 to 20.11.28 (#1000) 2024-03-18 13:22:57 +01:00
0cb4e4ce8a build(deps-dev): bump @typescript-eslint/parser from 7.1.1 to 7.2.0 (#998) 2024-03-18 13:22:29 +01:00
c2b1114313 build(deps): bump google.golang.org/protobuf from 1.28.0 to 1.33.0 in /sample-go-mod (#997) 2024-03-13 23:01:31 +01:00
1ef822c9e7 build(deps): bump @actions/http-client from 2.2.0 to 2.2.1 (#995)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-03-11 19:03:02 +01:00
0cf702c571 build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.1.0 to 7.1.1 (#994) 2024-03-11 17:35:13 +01:00
e0e0b2b842 build(deps-dev): bump typescript from 5.3.3 to 5.4.2 (#993) 2024-03-11 17:23:20 +01:00
d7b3f577a7 build(deps): bump @types/node from 20.11.24 to 20.11.25 (#992) 2024-03-11 17:23:00 +01:00
a3062e4021 build(deps-dev): bump @typescript-eslint/parser from 7.1.0 to 7.1.1 (#991) 2024-03-11 17:22:40 +01:00
0cea014686 build(deps): bump @types/node from 20.11.20 to 20.11.24 (#990) 2024-03-04 13:43:42 +01:00
c9cca96908 build(deps-dev): bump @typescript-eslint/parser from 6.21.0 to 7.1.0 (#988)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-03-04 13:40:26 +01:00
2e99f461f3 build(deps): bump tmp from 0.2.1 to 0.2.3 (#989)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-03-04 13:36:42 +01:00
27463c1456 build(deps-dev): bump eslint from 8.56.0 to 8.57.0 (#987) 2024-02-26 17:04:02 +01:00
47f5f04922 build(deps): bump @types/semver from 7.5.7 to 7.5.8 (#986) 2024-02-26 13:09:12 +00:00
6d0160cbf8 build(deps): bump @types/node from 20.11.19 to 20.11.20 (#985) 2024-02-26 14:00:14 +01:00
52b846a8b5 build(deps): bump undici from 5.26.3 to 5.28.3 (#976)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-02-19 15:35:38 +01:00
3f7fc68782 build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.21.0 to 7.0.0 (#980) 2024-02-19 14:40:55 +01:00
1eba11c6d8 build(deps): bump @types/node from 20.11.17 to 20.11.19 (#979) 2024-02-19 14:40:33 +01:00
552a57d5dc docs: update the version of the action used in the README example (#977)
Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
2024-02-17 15:43:17 +00:00
a83e3d11f6 build(deps): bump @types/node from 20.11.16 to 20.11.17 (#972) 2024-02-12 16:33:45 +01:00
2fc4c770fc build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.20.0 to 6.21.0 (#973) 2024-02-12 16:33:36 +01:00
0ea26a0a52 build(deps-dev): bump eslint-plugin-simple-import-sort from 10.0.0 to 12.0.0 (#971) 2024-02-12 15:12:04 +01:00
f1a742892f build(deps-dev): bump @typescript-eslint/parser from 6.20.0 to 6.21.0 (#970) 2024-02-12 15:11:56 +01:00
2031bb15ab build(deps): bump @types/semver from 7.5.6 to 7.5.7 (#969) 2024-02-12 15:11:44 +01:00
17bf0db4b7 chore: use olstable as Go version 2024-02-12 14:12:44 +01:00
de85e3b9b1 chore: update tested golangci-lint version 2024-02-12 13:57:04 +01:00
14 changed files with 3134 additions and 6107 deletions

View File

@ -52,8 +52,8 @@ jobs:
version: version:
- "" - ""
- "latest" - "latest"
- "v1.53" - "v1.58"
- "v1.53.2" - "v1.58.0"
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
permissions: permissions:
contents: read contents: read
@ -62,7 +62,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
with: with:
cache: false # setup-go v4 caches by default go-version: oldstable
- uses: ./ - uses: ./
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
@ -80,8 +80,8 @@ jobs:
version: version:
- "" - ""
- "latest" - "latest"
- "v1.53.2" - "v1.58.0"
- "b5093688c0d3008eaacd6066773a1a52e689252f" - "4bf574a12bb61234e28e3d6172be6ed95b0e8baf"
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
permissions: permissions:
contents: read contents: read
@ -90,7 +90,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
with: with:
cache: false # setup-go v4 caches by default go-version: oldstable
- uses: ./ - uses: ./
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
@ -113,7 +113,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
with: with:
cache: false # setup-go v4 caches by default go-version: oldstable
- uses: ./ - uses: ./
with: with:
working-directory: sample-go-mod working-directory: sample-go-mod

277
README.md
View File

@ -3,13 +3,18 @@
[![Build Status](https://github.com/golangci/golangci-lint-action/workflows/build-and-test/badge.svg)](https://github.com/golangci/golangci-lint-action/actions) [![Build Status](https://github.com/golangci/golangci-lint-action/workflows/build-and-test/badge.svg)](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. 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. The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters.
![GitHub Annotations](./static/annotations.png) ![GitHub Annotations](./static/annotations.png)
![Logs](./static/colored-line-number.png)
## Compatibility ## Compatibility
* `v3.0.0+` requires explicit setup-go installation step prior to using this action: `uses: actions/setup-go@v3`. * `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. The `skip-go-installation` option has been removed.
* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3` * `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.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))
@ -24,8 +29,8 @@ name: golangci-lint
on: on:
push: push:
branches: branches:
- master
- main - main
- master
pull_request: pull_request:
permissions: permissions:
@ -38,59 +43,32 @@ jobs:
name: lint name: lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-go@v4 - uses: actions/setup-go@v5
with: with:
go-version: '1.21' go-version: '1.22'
cache: false
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v5
with: with:
# Require: The version of golangci-lint to use. version: latest
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
# 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 all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true
# Optional: if set to true, then the action won'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"
``` ```
We recommend running this action in a job separate from other jobs (`go test`, etc) 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). because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
### Multiple OS Support ### Multiple OS Support
If you need to run linters for specific operating systems, you will need to use the action `>=v2`. Here is a sample configuration file: If you need to run linters for specific operating systems, you will need to use the action `>=v2`.
Here is a sample configuration file:
```yaml ```yaml
name: golangci-lint name: golangci-lint
on: on:
push: push:
branches: branches:
- master
- main - main
- master
pull_request: pull_request:
permissions: permissions:
@ -102,38 +80,19 @@ jobs:
golangci: golangci:
strategy: strategy:
matrix: matrix:
go: ['1.21'] go: ['1.22']
os: [macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
name: lint name: lint
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-go@v4 - uses: actions/setup-go@v5
with: with:
go-version: ${{ matrix.go }} go-version: ${{ matrix.go }}
cache: false
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v5
with: with:
# Require: The version of golangci-lint to use. version: latest
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
# 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"
``` ```
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:
@ -142,16 +101,169 @@ You will also likely need to add the following `.gitattributes` file to ensure t
*.go text eol=lf *.go text eol=lf
``` ```
## Comments and Annotations ## 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.
* When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
```yml
uses: golangci/golangci-lint-action@v5
with:
version: latest
# ...
```
### `install-mode`
(optional)
The mode to install golangci-lint: it can be `binary` or `goinstall`.
The default value is `binary`.
```yml
uses: golangci/golangci-lint-action@v5
with:
install-mode: "goinstall"
# ...
```
### `only-new-issues`
(optional)
Show only new issues.
The default value is `false`.
```yml
uses: golangci/golangci-lint-action@v5
with:
only-new-issues: true
# ...
```
* `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.
### `working-directory`
(optional)
Working directory, useful for monorepos.
```yml
uses: golangci/golangci-lint-action@v5
with:
working-directory: somedir
# ...
```
### `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`.
```yml
uses: golangci/golangci-lint-action@v5
with:
skip-cache: true
# ...
```
### `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`.
```yml
uses: golangci/golangci-lint-action@v5
with:
skip-save-cache: true
# ...
```
### `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`.
```yml
uses: golangci/golangci-lint-action@v5
with:
cache-invalidation-interval: 15
# ...
```
If set the number is `<= 0`, the cache will be always invalidate (Not recommended).
### `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`.
```yml
uses: golangci/golangci-lint-action@v5
with:
problem-matchers: true
# ...
```
### `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=`
```yml
uses: golangci/golangci-lint-action@v5
with:
args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
# ...
```
## Annotations
Currently, GitHub parses the action's output and creates [annotations](https://github.blog/2018-12-14-introducing-check-runs-and-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: 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)) 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 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). 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. To enable annotations, you need to add the `checks` permission to your action.
```yaml annotate ```yaml annotate
permissions: permissions:
@ -159,7 +271,7 @@ permissions:
contents: read contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option. # Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read pull-requests: read
# Optional: Allow write access to checks to allow the action to annotate code in the PR. # Optional: allow write access to checks to allow the action to annotate code in the PR.
checks: write checks: write
``` ```
@ -167,9 +279,9 @@ permissions:
The action was implemented with performance in mind: 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. 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: 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: * in parallel:
@ -179,9 +291,10 @@ For example, in a repository of [golangci-lint](https://github.com/golangci/gola
## Internals ## 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) 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.
@ -189,18 +302,22 @@ We support different platforms, such as `ubuntu`, `macos`, and `windows` with `x
Inside our action, we perform 3 steps: Inside our action, we perform 3 steps:
1. Setup environment running in parallel: 1. Setup environment running in parallel:
* restore [cache](https://github.com/actions/cache) of previous analyses * 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 * 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
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) (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` 2. Run `golangci-lint` with specified by user `args`
3. Save cache for later builds 3. Save cache for later builds
### Caching internals ### Caching internals
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`. 1. We save and restore the following directory: `~/.cache/golangci-lint`.
2. The primary caching key looks like `golangci-lint.cache-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate 2. The primary caching key looks like `golangci-lint.cache-{runner_os}-{working_directory}-{interval_number}-{go.mod_hash}`.
our cache (every 7 days). `go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed. Interval number ensures that we periodically invalidate our cache (every 7 days).
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. `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. This scheme is basic and needs improvements. Pull requests and ideas are welcome.

View File

@ -1,4 +1,5 @@
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." description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
author: "golangci" author: "golangci"
inputs: inputs:
@ -8,9 +9,9 @@ inputs:
When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
required: false required: false
args: install-mode:
description: "golangci-lint command line arguments" description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
default: "" default: "binary"
required: false required: false
working-directory: working-directory:
description: "golangci-lint working directory, default is project root" description: "golangci-lint working directory, default is project root"
@ -29,17 +30,23 @@ inputs:
takes precedence over all other caching options. takes precedence over all other caching options.
default: 'false' default: 'false'
required: false required: false
skip-pkg-cache: skip-save-cache:
description: "if set to true then the action doesn't cache or restore ~/go/pkg." 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' default: 'false'
required: false required: false
skip-build-cache: problem-matchers:
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build." description: "Force the usage of the embedded problem matchers"
default: 'false' default: 'false'
required: false required: false
install-mode: args:
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'." description: "golangci-lint command line arguments"
default: "binary" default: ""
required: false
cache-invalidation-interval:
description: "Periodically invalidate a cache because a new code being added. (number of days)"
default: '7'
required: false required: false
runs: runs:
using: "node20" using: "node20"
@ -47,4 +54,4 @@ runs:
post: "dist/post_run/index.js" post: "dist/post_run/index.js"
branding: branding:
icon: "shield" icon: "shield"
color: "yellow" color: "white"

4079
dist/post_run/index.js generated vendored

File diff suppressed because it is too large Load Diff

4079
dist/run/index.js generated vendored

File diff suppressed because it is too large Load Diff

524
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,23 +28,23 @@
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/http-client": "^2.2.0", "@actions/http-client": "^2.2.1",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@types/node": "^20.11.16", "@types/node": "^20.12.8",
"@types/semver": "^7.5.6", "@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6", "@types/tmp": "^0.2.6",
"tmp": "^0.2.1" "tmp": "^0.2.3"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.20.0", "@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^6.20.0", "@typescript-eslint/parser": "^7.8.0",
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0", "eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1", "eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3", "eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-simple-import-sort": "^12.1.0",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"typescript": "^5.3.3" "typescript": "^5.4.5"
} }
} }

17
problem-matchers.json Normal file
View 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
}
]
}
]
}

View File

@ -167,7 +167,7 @@ require (
golang.org/x/sys v0.5.0 // indirect golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect golang.org/x/text v0.6.0 // indirect
golang.org/x/tools 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/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

View File

@ -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.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-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.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 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/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 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -23,28 +23,13 @@ const getLintCacheDir = (): string => {
return path.resolve(`${process.env.HOME}/.cache/golangci-lint`) return path.resolve(`${process.env.HOME}/.cache/golangci-lint`)
} }
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
}
const getIntervalKey = (invalidationIntervalDays: number): string => { const getIntervalKey = (invalidationIntervalDays: number): string => {
const now = new Date() const now = new Date()
if (invalidationIntervalDays <= 0) {
return `${now.getTime()}`
}
const secondsSinceEpoch = now.getTime() / 1000 const secondsSinceEpoch = now.getTime() / 1000
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400)) const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400))
return intervalNumber.toString() return intervalNumber.toString()
@ -52,28 +37,42 @@ const getIntervalKey = (invalidationIntervalDays: number): string => {
async function buildCacheKeys(): Promise<string[]> { async function buildCacheKeys(): Promise<string[]> {
const keys = [] const keys = []
// Periodically invalidate a cache because a new code being added.
// TODO: configure it via inputs. // Cache by OS.
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-` let cacheKey = `golangci-lint.cache-${process.env?.RUNNER_OS}-`
keys.push(cacheKey)
// Get working directory from input // Get working directory from input
const workingDirectory = core.getInput(`working-directory`) 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 // create path to go.mod prepending the workingDirectory if it exists
const goModPath = path.join(workingDirectory, `go.mod`) const goModPath = path.join(workingDirectory, `go.mod`)
core.info(`Checking for go.mod: ${goModPath}`) core.info(`Checking for go.mod: ${goModPath}`)
if (await pathExists(goModPath)) { if (await pathExists(goModPath)) {
// Add checksum to key to invalidate a cache when dependencies change. // Add checksum to key to invalidate a cache when dependencies change.
cacheKey += await checksumFile(`sha1`, goModPath) cacheKey += await checksumFile(`sha1`, goModPath)
} else { } else {
cacheKey += `nogomod` cacheKey += `nogomod`
} }
keys.push(cacheKey) keys.push(cacheKey)
return keys return keys
} }
export async function restoreCache(): Promise<void> { 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()) { if (!utils.isValidEvent()) {
utils.logWarning( utils.logWarning(
@ -97,7 +96,7 @@ export async function restoreCache(): Promise<void> {
} }
core.saveState(State.CachePrimaryKey, primaryKey) core.saveState(State.CachePrimaryKey, primaryKey)
try { try {
const cacheKey = await cache.restoreCache(getCacheDirs(), primaryKey, restoreKeys) const cacheKey = await cache.restoreCache([getLintCacheDir()], primaryKey, restoreKeys)
if (!cacheKey) { if (!cacheKey) {
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(", ")}`) core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(", ")}`)
return return
@ -115,7 +114,8 @@ export async function restoreCache(): Promise<void> {
} }
export async function saveCache(): 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 // Validate inputs, this can cause task failure
if (!utils.isValidEvent()) { if (!utils.isValidEvent()) {
@ -127,7 +127,7 @@ export async function saveCache(): Promise<void> {
const startedAt = Date.now() const startedAt = Date.now()
const cacheDirs = getCacheDirs() const cacheDirs = [getLintCacheDir()]
const primaryKey = core.getState(State.CachePrimaryKey) const primaryKey = core.getState(State.CachePrimaryKey)
if (!primaryKey) { if (!primaryKey) {
utils.logWarning(`Error retrieving key from state.`) utils.logWarning(`Error retrieving key from state.`)

View File

@ -1,5 +1,6 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import * as github from "@actions/github" import * as github from "@actions/github"
import { Context } from "@actions/github/lib/context"
import { exec, ExecOptions } from "child_process" import { exec, ExecOptions } from "child_process"
import * as fs from "fs" import * as fs from "fs"
import * as path from "path" import * as path from "path"
@ -15,6 +16,10 @@ const execShellCommand = promisify(exec)
const writeFile = promisify(fs.writeFile) const writeFile = promisify(fs.writeFile)
const createTempDir = promisify(dir) const createTempDir = promisify(dir)
function isOnlyNewIssues(): boolean {
return core.getBooleanInput(`only-new-issues`, { required: true })
}
async function prepareLint(): Promise<string> { async function prepareLint(): Promise<string> {
const mode = core.getInput("install-mode").toLowerCase() const mode = core.getInput("install-mode").toLowerCase()
const versionConfig = await findLintVersion(<InstallMode>mode) const versionConfig = await findLintVersion(<InstallMode>mode)
@ -23,31 +28,42 @@ async function prepareLint(): Promise<string> {
} }
async function fetchPatch(): Promise<string> { async function fetchPatch(): Promise<string> {
const onlyNewIssues = core.getInput(`only-new-issues`, { required: true }).trim() if (!isOnlyNewIssues()) {
if (onlyNewIssues !== `false` && onlyNewIssues !== `true`) {
throw new Error(`invalid value of "only-new-issues": "${onlyNewIssues}", expected "true" or "false"`)
}
if (onlyNewIssues === `false`) {
return `` return ``
} }
const ctx = github.context 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}`) switch (ctx.eventName) {
return `` case `pull_request`:
case `pull_request_target`:
return await fetchPullRequestPatch(ctx)
case `push`:
return await fetchPushPatch(ctx)
case `merge_group`:
core.info(JSON.stringify(ctx.payload))
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`) core.warning(`No pull request in context`)
return `` return ``
} }
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })) const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
let patch: string let patch: string
try { try {
const patchResp = await octokit.rest.pulls.get({ const patchResp = await octokit.rest.pulls.get({
owner: ctx.repo.owner, owner: ctx.repo.owner,
repo: ctx.repo.repo, repo: ctx.repo.repo,
[`pull_number`]: pull.number, [`pull_number`]: pr.number,
mediaType: { mediaType: {
format: `diff`, format: `diff`,
}, },
@ -77,6 +93,44 @@ async function fetchPatch(): Promise<string> {
} }
} }
async function fetchPushPatch(ctx: Context): Promise<string> {
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
let patch: string
try {
const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({
owner: ctx.repo.owner,
repo: ctx.repo.repo,
basehead: `${ctx.payload.before}..${ctx.payload.after}`,
mediaType: {
format: `diff`,
},
})
if (patchResp.status !== 200) {
core.warning(`failed to fetch push patch: response status is ${patchResp.status}`)
return `` // don't fail the action, but analyze without patch
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
patch = patchResp.data as any
} catch (err) {
console.warn(`failed to fetch push patch:`, err)
return `` // don't fail the action, but analyze without patch
}
try {
const tempDir = await createTempDir()
const patchPath = path.join(tempDir, "push.patch")
core.info(`Writing patch to ${patchPath}`)
await writeFile(patchPath, alterDiffPatch(patch))
return patchPath
} catch (err) {
console.warn(`failed to save pull request patch:`, err)
return `` // don't fail the action, but analyze without patch
}
}
type Env = { type Env = {
lintPath: string lintPath: string
patchPath: string patchPath: string
@ -87,11 +141,9 @@ async function prepareEnv(): Promise<Env> {
// Prepare cache, lint and go in parallel. // Prepare cache, lint and go in parallel.
await restoreCache() await restoreCache()
const prepareLintPromise = prepareLint()
const patchPromise = fetchPatch()
const lintPath = await prepareLintPromise const lintPath = await prepareLint()
const patchPath = await patchPromise const patchPath = await fetchPatch()
core.info(`Prepared env in ${Date.now() - startedAt}ms`) core.info(`Prepared env in ${Date.now() - startedAt}ms`)
@ -133,30 +185,68 @@ async function runLint(lintPath: string, patchPath: 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}`)
}
}
const formats = (userArgsMap.get("out-format") || "") const formats = (userArgsMap.get("out-format") || "")
.trim() .trim()
.split(",") .split(",")
.filter((f) => f.length > 0) .filter((f) => f.length > 0)
.filter((f) => !f.startsWith(`github-actions`)) .filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
.concat("github-actions")
.join(",") .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() 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`)) { if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
throw new Error(`please, don't specify manually --new* args when requesting only new issues`) throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
} }
addedArgs.push(`--new-from-patch=${patchPath}`)
// Override config values. const ctx = github.context
addedArgs.push(`--new=false`)
addedArgs.push(`--new-from-rev=`) 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 cmdArgs: ExecOptions = {}
const workingDirectory = core.getInput(`working-directory`)
if (workingDirectory) { if (workingDirectory) {
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
throw new Error(`working-directory (${workingDirectory}) was not a path`) throw new Error(`working-directory (${workingDirectory}) was not a path`)
@ -169,7 +259,7 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd() 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() const startedAt = Date.now()
try { try {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB