From bf6479d5eca7bb49c9c6d58a0de6e0cd7770f15c Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Thu, 25 Apr 2024 01:03:53 +0000 Subject: [PATCH 01/26] feat: add support for pull_request_target and only-new-issues (#506) --- dist/post_run/index.js | 2 +- dist/run/index.js | 2 +- src/run.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index e51711ce03..91fbc1b387 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89177,7 +89177,7 @@ async function fetchPatch() { return ``; } const ctx = github.context; - if (ctx.eventName !== `pull_request`) { + if (ctx.eventName !== `pull_request` && ctx.eventName !== `pull_request_target`) { core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`); return ``; } diff --git a/dist/run/index.js b/dist/run/index.js index 7cc8c9a706..6e8230c265 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89177,7 +89177,7 @@ async function fetchPatch() { return ``; } const ctx = github.context; - if (ctx.eventName !== `pull_request`) { + if (ctx.eventName !== `pull_request` && ctx.eventName !== `pull_request_target`) { core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`); return ``; } diff --git a/src/run.ts b/src/run.ts index 64e4164618..a721b760d9 100644 --- a/src/run.ts +++ b/src/run.ts @@ -32,7 +32,7 @@ async function fetchPatch(): Promise { } const ctx = github.context - if (ctx.eventName !== `pull_request`) { + if (ctx.eventName !== `pull_request` && ctx.eventName !== `pull_request_target`) { core.info(`Not fetching patch for showing only new issues because it's not a pull request context: event name is ${ctx.eventName}`) return `` } From c683728f105cc5845aaf6e77791d8757b454d52b Mon Sep 17 00:00:00 2001 From: Navneeth Jayendran Date: Wed, 24 Apr 2024 18:17:21 -0700 Subject: [PATCH 02/26] feat: add option to not save cache (#851) --- README.md | 4 ++++ action.yml | 6 ++++++ dist/post_run/index.js | 2 ++ dist/run/index.js | 2 ++ src/cache.ts | 1 + 5 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 14b77caa4c..70d2ff2d91 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ jobs: # takes precedence over all other caching options. # skip-cache: true + # Optional: if set to true, caches will not be saved, but they may still be restored, + # subject to other options + # skip-save-cache: true + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. # skip-pkg-cache: true diff --git a/action.yml b/action.yml index 3b3ea21c27..7ab3103190 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,12 @@ inputs: takes precedence over all other caching options. default: 'false' required: 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-pkg-cache: description: "if set to true then the action doesn't cache or restore ~/go/pkg." default: 'false' diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 91fbc1b387..89c0c1fbbd 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -88900,6 +88900,8 @@ exports.restoreCache = restoreCache; async function saveCache() { if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return; + if (core.getInput(`skip-save-cache`, { required: true }).trim() == "true") + return; // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); diff --git a/dist/run/index.js b/dist/run/index.js index 6e8230c265..d4c8ce078d 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -88900,6 +88900,8 @@ exports.restoreCache = restoreCache; async function saveCache() { if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return; + if (core.getInput(`skip-save-cache`, { required: true }).trim() == "true") + return; // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); diff --git a/src/cache.ts b/src/cache.ts index cb8f828ac9..ed1da7517a 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -116,6 +116,7 @@ export async function restoreCache(): Promise { export async function saveCache(): Promise { if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return + if (core.getInput(`skip-save-cache`, { required: true }).trim() == "true") return // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { From 82d40c283aeb1f2b6595839195e95c2d6a49081b Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 25 Apr 2024 03:26:57 +0200 Subject: [PATCH 03/26] feat: remove Go cache management (#1024) --- README.md | 8 +------- action.yml | 8 -------- dist/post_run/index.js | 23 ++--------------------- dist/run/index.js | 23 ++--------------------- src/cache.ts | 24 ++---------------------- 5 files changed, 7 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 70d2ff2d91..0dd993cac4 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ jobs: # Require: 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. - version: v1.54 + version: v1.57 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -71,12 +71,6 @@ jobs: # subject to other options # skip-save-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" ``` diff --git a/action.yml b/action.yml index 7ab3103190..4f3cb3a4bf 100644 --- a/action.yml +++ b/action.yml @@ -35,14 +35,6 @@ inputs: restore existing caches, subject to other options. default: 'false' required: false - skip-pkg-cache: - description: "if set to true then the action doesn't cache or restore ~/go/pkg." - 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' - required: false install-mode: description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'." default: "binary" diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 89c0c1fbbd..ff6cea0d20 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -88813,25 +88813,6 @@ const pathExists = async (path) => !!(await fs.promises.stat(path).catch(() => f const getLintCacheDir = () => { return path_1.default.resolve(`${process.env.HOME}/.cache/golangci-lint`); }; -const getCacheDirs = () => { - // 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_1.default.resolve(`${process.env.HOME}/.cache/go-build`)); - } - if (skipPkgCache.toLowerCase() == "true") { - core.info(`Omitting ~/go/pkg from cache directories`); - } - else { - dirs.push(path_1.default.resolve(`${process.env.HOME}/go/pkg`)); - } - return dirs; -}; const getIntervalKey = (invalidationIntervalDays) => { const now = new Date(); const secondsSinceEpoch = now.getTime() / 1000; @@ -88878,7 +88859,7 @@ async function restoreCache() { } core.saveState(constants_1.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; @@ -88908,7 +88889,7 @@ async function saveCache() { return; } const startedAt = Date.now(); - const cacheDirs = getCacheDirs(); + const cacheDirs = [getLintCacheDir()]; const primaryKey = core.getState(constants_1.State.CachePrimaryKey); if (!primaryKey) { utils.logWarning(`Error retrieving key from state.`); diff --git a/dist/run/index.js b/dist/run/index.js index d4c8ce078d..1965346a67 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -88813,25 +88813,6 @@ const pathExists = async (path) => !!(await fs.promises.stat(path).catch(() => f const getLintCacheDir = () => { return path_1.default.resolve(`${process.env.HOME}/.cache/golangci-lint`); }; -const getCacheDirs = () => { - // 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_1.default.resolve(`${process.env.HOME}/.cache/go-build`)); - } - if (skipPkgCache.toLowerCase() == "true") { - core.info(`Omitting ~/go/pkg from cache directories`); - } - else { - dirs.push(path_1.default.resolve(`${process.env.HOME}/go/pkg`)); - } - return dirs; -}; const getIntervalKey = (invalidationIntervalDays) => { const now = new Date(); const secondsSinceEpoch = now.getTime() / 1000; @@ -88878,7 +88859,7 @@ async function restoreCache() { } core.saveState(constants_1.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; @@ -88908,7 +88889,7 @@ async function saveCache() { return; } const startedAt = Date.now(); - const cacheDirs = getCacheDirs(); + const cacheDirs = [getLintCacheDir()]; const primaryKey = core.getState(constants_1.State.CachePrimaryKey); if (!primaryKey) { utils.logWarning(`Error retrieving key from state.`); diff --git a/src/cache.ts b/src/cache.ts index ed1da7517a..5c73169753 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -23,26 +23,6 @@ const getLintCacheDir = (): string => { 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 now = new Date() const secondsSinceEpoch = now.getTime() / 1000 @@ -97,7 +77,7 @@ export async function restoreCache(): Promise { } 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 @@ -128,7 +108,7 @@ export async function saveCache(): Promise { 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.`) From 03a8ce6d607f96b2a782a33578f7aa119386d127 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 25 Apr 2024 03:35:41 +0200 Subject: [PATCH 04/26] docs: update readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0dd993cac4..ae07d18aa3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and r ## Compatibility -* `v4.0.0+` requires an explicit setup-go installation step before using this action: `uses: actions/setup-go@v5`. +* `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)) @@ -44,7 +45,7 @@ jobs: go-version: '1.21' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v5 with: # Require: 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. From 3adb6d04739490c2ebd4cc54c125719ba5f04f37 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 25 Apr 2024 03:38:07 +0200 Subject: [PATCH 05/26] docs: update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae07d18aa3..c58f639968 100644 --- a/README.md +++ b/README.md @@ -166,9 +166,9 @@ permissions: 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 by [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache) between builds: golangci-lint analysis 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: From 7c0f80cbb834ccccac45e5b716269c71586af695 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 25 Apr 2024 03:39:35 +0200 Subject: [PATCH 06/26] docs: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c58f639968..ba219a4cae 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ jobs: go-version: ${{ matrix.go }} cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v5 with: # Require: 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. From 47ef1b2e7f3c56b151704c9dc68b2ae34c83df38 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 26 Apr 2024 17:25:34 +0200 Subject: [PATCH 07/26] docs: update readme --- README.md | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ba219a4cae..286f05a100 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![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. + The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters. ![GitHub Annotations](./static/annotations.png) @@ -25,8 +26,8 @@ name: golangci-lint on: push: branches: - - master - main + - master pull_request: permissions: @@ -76,20 +77,22 @@ jobs: # 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). ### 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 name: golangci-lint on: push: branches: - - master - main + - master pull_request: permissions: @@ -117,7 +120,7 @@ jobs: # Require: 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. - version: v1.54 + version: v1.57 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -147,8 +150,9 @@ Currently, GitHub parses the action's output and creates [annotations](https://g 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 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). +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). To enable annotations, you need to add the `checks' permission to your action. @@ -166,7 +170,7 @@ permissions: 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: 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, and golangci-lint binary in parallel. @@ -178,9 +182,10 @@ 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. @@ -188,18 +193,21 @@ We support different platforms, such as `ubuntu`, `macos`, and `windows` with `x Inside our action, we perform 3 steps: 1. Setup environment running in parallel: - * 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) + * 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-{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. This scheme is basic and needs improvements. Pull requests and ideas are welcome. From f89fd48199dc37e25257a4cbd0758a7e47127bda Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 27 Apr 2024 03:06:28 +0200 Subject: [PATCH 08/26] docs: update readme --- README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 286f05a100..c763ffd1e5 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ jobs: # 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`. + # Optional: For pull request only, show only new issues. The default value is `false`. # only-new-issues: true # Optional: if set to true, then all caching functionality will be completely disabled, @@ -126,15 +126,23 @@ jobs: # working-directory: somedir # Optional: golangci-lint command line arguments. - # - # Note: by default the `.golangci.yml` file should be at the root of the repository. + # + # 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 + # 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`. + # Optional: For pull request only, show only new issues. The default value is `false`. # only-new-issues: true - # Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # 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, caches will not be saved, but they may still be restored, + # subject to other options + # skip-save-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. # install-mode: "goinstall" ``` From d149ece3f4b24e9c6b291dbcdfe0b4bb68ed31b2 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 27 Apr 2024 04:18:26 +0200 Subject: [PATCH 09/26] docs: update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c763ffd1e5..cd727da622 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: '1.21' - cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v5 with: @@ -113,7 +112,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v5 with: From ef6d5d0e99cab5365ed2311aa6763d08ccfd8ae6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:37:38 +0200 Subject: [PATCH 10/26] build(deps-dev): bump @typescript-eslint/parser from 7.7.0 to 7.7.1 (#1027) --- package-lock.json | 215 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 2 +- 2 files changed, 201 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 41e4bc4099..532ea2c0bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.0", - "@typescript-eslint/parser": "^7.7.0", + "@typescript-eslint/parser": "^7.7.1", "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", @@ -741,15 +741,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", - "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.1.tgz", + "integrity": "sha512-vmPzBOOtz48F6JAGVS/kZYk4EkXao6iGrD838sp1w3NQQC0W8ry/q641KU4PrG7AKNAf56NOcR8GOpH8l9FPCw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4" }, "engines": { @@ -768,6 +768,120 @@ } } }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", + "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", + "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", + "dev": true, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", + "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", + "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.1", + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@typescript-eslint/scope-manager": { "version": "7.7.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", @@ -4640,16 +4754,87 @@ } }, "@typescript-eslint/parser": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", - "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.1.tgz", + "integrity": "sha512-vmPzBOOtz48F6JAGVS/kZYk4EkXao6iGrD838sp1w3NQQC0W8ry/q641KU4PrG7AKNAf56NOcR8GOpH8l9FPCw==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4" + }, + "dependencies": { + "@typescript-eslint/scope-manager": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", + "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1" + } + }, + "@typescript-eslint/types": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", + "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", + "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", + "dev": true, + "requires": { + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + } + }, + "@typescript-eslint/visitor-keys": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", + "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "7.7.1", + "eslint-visitor-keys": "^3.4.3" + } + }, + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } } }, "@typescript-eslint/scope-manager": { diff --git a/package.json b/package.json index 2f5d88798f..08fe7b3390 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.0", - "@typescript-eslint/parser": "^7.7.0", + "@typescript-eslint/parser": "^7.7.1", "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", From 692c9c9dba385536b59da68da5aef1775a6f94ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:56:18 +0200 Subject: [PATCH 11/26] build(deps-dev): bump @typescript-eslint/eslint-plugin from 7.7.0 to 7.7.1 (#1028) --- package-lock.json | 319 ++++++++++------------------------------------ package.json | 2 +- 2 files changed, 68 insertions(+), 253 deletions(-) diff --git a/package-lock.json b/package-lock.json index 532ea2c0bd..315e57cd3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "tmp": "^0.2.3" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.7.0", + "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", @@ -691,16 +691,16 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", - "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.1.tgz", + "integrity": "sha512-KwfdWXJBOviaBVhxO3p5TJiLpNuh2iyXyjmWN0f1nU87pwyvfS0EmjC6ukQVYVFJd/K1+0NWGPDXiyEyQorn0Q==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/type-utils": "7.7.0", - "@typescript-eslint/utils": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/type-utils": "7.7.1", + "@typescript-eslint/utils": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.3.1", @@ -768,7 +768,7 @@ } } }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": { + "node_modules/@typescript-eslint/scope-manager": { "version": "7.7.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", @@ -785,128 +785,14 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", - "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", - "dev": true, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", - "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.7.1", - "@typescript-eslint/visitor-keys": "7.7.1", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", - "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.7.1", - "eslint-visitor-keys": "^3.4.3" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@typescript-eslint/parser/node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", - "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", - "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.1.tgz", + "integrity": "sha512-ZksJLW3WF7o75zaBPScdW1Gbkwhd/lyeXGf1kQCxJaOeITscoSl0MjynVvCzuV5boUz/3fOI06Lz8La55mu29Q==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/utils": "7.7.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -927,9 +813,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", - "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", + "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -940,13 +826,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", - "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", + "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1007,17 +893,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", - "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.1.tgz", + "integrity": "sha512-QUvBxPEaBXf41ZBbaidKICgVL8Hin0p6prQDu6bbetWo39BKbWJxRsErOzMNT1rXvTll+J7ChrbmMCXM9rsvOQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.15", "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", "semver": "^7.6.0" }, "engines": { @@ -1047,12 +933,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", - "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", + "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/types": "7.7.1", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -4724,16 +4610,16 @@ } }, "@typescript-eslint/eslint-plugin": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", - "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.1.tgz", + "integrity": "sha512-KwfdWXJBOviaBVhxO3p5TJiLpNuh2iyXyjmWN0f1nU87pwyvfS0EmjC6ukQVYVFJd/K1+0NWGPDXiyEyQorn0Q==", "dev": true, "requires": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/type-utils": "7.7.0", - "@typescript-eslint/utils": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/type-utils": "7.7.1", + "@typescript-eslint/utils": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.3.1", @@ -4764,115 +4650,44 @@ "@typescript-eslint/typescript-estree": "7.7.1", "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4" - }, - "dependencies": { - "@typescript-eslint/scope-manager": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", - "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", - "dev": true, - "requires": { - "@typescript-eslint/types": "7.7.1", - "@typescript-eslint/visitor-keys": "7.7.1" - } - }, - "@typescript-eslint/types": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", - "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", - "dev": true - }, - "@typescript-eslint/typescript-estree": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", - "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", - "dev": true, - "requires": { - "@typescript-eslint/types": "7.7.1", - "@typescript-eslint/visitor-keys": "7.7.1", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^1.3.0" - } - }, - "@typescript-eslint/visitor-keys": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", - "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", - "dev": true, - "requires": { - "@typescript-eslint/types": "7.7.1", - "eslint-visitor-keys": "^3.4.3" - } - }, - "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0" - } - }, - "minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", - "dev": true, - "requires": { - "brace-expansion": "^2.0.1" - } - }, - "semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - } } }, "@typescript-eslint/scope-manager": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", - "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", + "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", "dev": true, "requires": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0" + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1" } }, "@typescript-eslint/type-utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", - "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.1.tgz", + "integrity": "sha512-ZksJLW3WF7o75zaBPScdW1Gbkwhd/lyeXGf1kQCxJaOeITscoSl0MjynVvCzuV5boUz/3fOI06Lz8La55mu29Q==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/utils": "7.7.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" } }, "@typescript-eslint/types": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", - "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", + "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", - "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", + "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", "dev": true, "requires": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -4911,17 +4726,17 @@ } }, "@typescript-eslint/utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", - "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.1.tgz", + "integrity": "sha512-QUvBxPEaBXf41ZBbaidKICgVL8Hin0p6prQDu6bbetWo39BKbWJxRsErOzMNT1rXvTll+J7ChrbmMCXM9rsvOQ==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.15", "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", "semver": "^7.6.0" }, "dependencies": { @@ -4937,12 +4752,12 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", - "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", + "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", "dev": true, "requires": { - "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/types": "7.7.1", "eslint-visitor-keys": "^3.4.3" } }, diff --git a/package.json b/package.json index 08fe7b3390..50fd789d8d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "tmp": "^0.2.3" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.7.0", + "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", From 9d1e0624a798bb64f6c3cea93db47765312263dc Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 29 Apr 2024 17:07:23 +0200 Subject: [PATCH 12/26] feat: only new issues enhancements (#1029) --- README.md | 10 +++- dist/post_run/index.js | 106 +++++++++++++++++++++++++++++------- dist/run/index.js | 106 +++++++++++++++++++++++++++++------- src/run.ts | 121 ++++++++++++++++++++++++++++++++++------- 4 files changed, 280 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index cd727da622..d1754e92ec 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,9 @@ jobs: # 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: For pull request only, show only new issues. The default value is `false`. + # Optional: Show only new issues. + # If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. + # The default value is `false`. # only-new-issues: true # Optional: if set to true, then all caching functionality will be completely disabled, @@ -104,7 +106,7 @@ jobs: strategy: matrix: go: ['1.21'] - os: [macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] name: lint runs-on: ${{ matrix.os }} steps: @@ -129,7 +131,9 @@ jobs: # 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: For pull request only, show only new issues. The default value is `false`. + # Optional: Show only new issues. + # If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. + # The default value is `false`. # only-new-issues: true # Optional: if set to true, then all caching functionality will be completely disabled, diff --git a/dist/post_run/index.js b/dist/post_run/index.js index ff6cea0d20..9dd2226db6 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89146,26 +89146,40 @@ const version_1 = __nccwpck_require__(1946); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); const createTempDir = (0, util_1.promisify)(tmp_1.dir); +function isOnlyNewIssues() { + 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"`); + } + return onlyNewIssues === `true`; +} async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); const versionConfig = await (0, version_1.findLintVersion)(mode); return await (0, install_1.installLint)(versionConfig, mode); } async function fetchPatch() { - 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` && ctx.eventName !== `pull_request_target`) { - 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`: + 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) { + const pr = ctx.payload.pull_request; + if (!pr) { core.warning(`No pull request in context`); return ``; } @@ -89175,7 +89189,7 @@ async function fetchPatch() { 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`, }, @@ -89203,14 +89217,48 @@ async function fetchPatch() { return ``; // don't fail the action, but analyze without patch } } +async function fetchPushPatch(ctx) { + const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); + let patch; + try { + const patchResp = await octokit.rest.repos.compareCommits({ + owner: ctx.repo.owner, + repo: ctx.repo.repo, + base: ctx.payload.before, + head: 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; + } + 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, (0, diffUtils_1.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 prepareEnv() { const startedAt = Date.now(); // Prepare cache, lint and go in parallel. await (0, cache_1.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`); return { lintPath, patchPath }; } @@ -89248,14 +89296,32 @@ async function runLint(lintPath, patchPath) { .join(","); addedArgs.push(`--out-format=${formats}`); 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 = {}; diff --git a/dist/run/index.js b/dist/run/index.js index 1965346a67..b015ef3b3f 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89146,26 +89146,40 @@ const version_1 = __nccwpck_require__(1946); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); const createTempDir = (0, util_1.promisify)(tmp_1.dir); +function isOnlyNewIssues() { + 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"`); + } + return onlyNewIssues === `true`; +} async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); const versionConfig = await (0, version_1.findLintVersion)(mode); return await (0, install_1.installLint)(versionConfig, mode); } async function fetchPatch() { - 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` && ctx.eventName !== `pull_request_target`) { - 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`: + 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) { + const pr = ctx.payload.pull_request; + if (!pr) { core.warning(`No pull request in context`); return ``; } @@ -89175,7 +89189,7 @@ async function fetchPatch() { 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`, }, @@ -89203,14 +89217,48 @@ async function fetchPatch() { return ``; // don't fail the action, but analyze without patch } } +async function fetchPushPatch(ctx) { + const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); + let patch; + try { + const patchResp = await octokit.rest.repos.compareCommits({ + owner: ctx.repo.owner, + repo: ctx.repo.repo, + base: ctx.payload.before, + head: 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; + } + 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, (0, diffUtils_1.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 prepareEnv() { const startedAt = Date.now(); // Prepare cache, lint and go in parallel. await (0, cache_1.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`); return { lintPath, patchPath }; } @@ -89248,14 +89296,32 @@ async function runLint(lintPath, patchPath) { .join(","); addedArgs.push(`--out-format=${formats}`); 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 = {}; diff --git a/src/run.ts b/src/run.ts index a721b760d9..60ff43201b 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,5 +1,6 @@ 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" @@ -15,6 +16,16 @@ const execShellCommand = promisify(exec) const writeFile = promisify(fs.writeFile) const createTempDir = promisify(dir) +function isOnlyNewIssues(): boolean { + 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"`) + } + + return onlyNewIssues === `true` +} + async function prepareLint(): Promise { const mode = core.getInput("install-mode").toLowerCase() const versionConfig = await findLintVersion(mode) @@ -23,31 +34,42 @@ async function prepareLint(): Promise { } async function fetchPatch(): Promise { - 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` && ctx.eventName !== `pull_request_target`) { - 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`: + 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 { + 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`, }, @@ -77,6 +99,45 @@ async function fetchPatch(): Promise { } } +async function fetchPushPatch(ctx: Context): Promise { + const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })) + + let patch: string + try { + const patchResp = await octokit.rest.repos.compareCommits({ + owner: ctx.repo.owner, + repo: ctx.repo.repo, + base: ctx.payload.before, + head: 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 = { lintPath: string patchPath: string @@ -87,11 +148,9 @@ async function prepareEnv(): Promise { // 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`) @@ -144,15 +203,37 @@ async function runLint(lintPath: string, patchPath: string): Promise { addedArgs.push(`--out-format=${formats}`) 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`) From d073fb8ea722be8ff7b2e3efea78f2b2bf338d3a Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 1 May 2024 04:24:14 +0200 Subject: [PATCH 13/26] doc: add information about annotation limitations --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1754e92ec..e05b4df60c 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t *.go text eol=lf ``` -## Comments and Annotations +## Annotations Currently, GitHub parses the action's output and creates [annotations](https://github.blog/2018-12-14-introducing-check-runs-and-annotations/). @@ -163,6 +163,7 @@ 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 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. From 3519a25e8931d06f18be2317c3f7f55c992666ed Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 00:37:13 +0200 Subject: [PATCH 14/26] chore: update tests workflow --- .github/workflows/test.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a16cb3069..46092cbc3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,8 +52,8 @@ jobs: version: - "" - "latest" - - "v1.56" - - "v1.56.1" + - "v1.58" + - "v1.58.0" runs-on: ${{ matrix.os }} permissions: contents: read @@ -63,7 +63,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: oldstable - cache: false # setup-go v4 caches by default - uses: ./ with: version: ${{ matrix.version }} @@ -81,8 +80,8 @@ jobs: version: - "" - "latest" - - "v1.56.1" - - "bf5008a11acf2da5fe76716eb21d808499e079fa" + - "v1.58.0" + - "4bf574a12bb61234e28e3d6172be6ed95b0e8baf" runs-on: ${{ matrix.os }} permissions: contents: read @@ -92,7 +91,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: oldstable - cache: false # setup-go v4 caches by default - uses: ./ with: version: ${{ matrix.version }} @@ -116,7 +114,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: oldstable - cache: false # setup-go v4 caches by default - uses: ./ with: working-directory: sample-go-mod From 57c4c9d18962515bb76a13f1b7204198cd7c2361 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 00:37:23 +0200 Subject: [PATCH 15/26] docs: update readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e05b4df60c..73cb06fd30 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: golangci-lint uses: golangci/golangci-lint-action@v5 with: # Require: 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. - version: v1.57 + version: v1.58 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -105,7 +105,7 @@ jobs: golangci: strategy: matrix: - go: ['1.21'] + go: ['1.22'] os: [ubuntu-latest, macos-latest, windows-latest] name: lint runs-on: ${{ matrix.os }} @@ -120,7 +120,7 @@ jobs: # Require: 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. - version: v1.57 + version: v1.58 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -165,7 +165,7 @@ The restrictions of annotations are the following: 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 permissions: @@ -173,7 +173,7 @@ permissions: 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. + # Optional: allow write access to checks to allow the action to annotate code in the PR. checks: write ``` From 7a6f31107b9dc1a55e7f317bbfac69d8af339e60 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 01:17:12 +0200 Subject: [PATCH 16/26] doc: improve options description --- README.md | 136 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 73cb06fd30..1aefc374d9 100644 --- a/README.md +++ b/README.md @@ -47,35 +47,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v5 with: - # Require: 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. - version: v1.58 - - # 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 you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. - # 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, caches will not be saved, but they may still be restored, - # subject to other options - # skip-save-cache: true - - # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" + version: latest ``` We recommend running this action in a job separate from other jobs (`go test`, etc.) @@ -117,35 +89,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v5 with: - # Require: 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. - version: v1.58 - - # 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 you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. - # 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, caches will not be saved, but they may still be restored, - # subject to other options - # skip-save-cache: true - - # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" + version: latest ``` You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted: @@ -154,6 +98,82 @@ You will also likely need to add the following `.gitattributes` file to ensure t *.go text eol=lf ``` +## 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: v1.58 + # ... +``` + +`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. +If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. +The default value is `false`. + +```yml +uses: golangci/golangci-lint-action@v5 +with: + only-new-issues: true + # ... +``` + +`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 + # ... +``` + +`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/). From 2bff40627723077fc557d83b223b2fcf2d4c6974 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 01:27:11 +0200 Subject: [PATCH 17/26] doc: improve options documentation --- README.md | 2 +- action.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1aefc374d9..4f8d941830 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t ```yml uses: golangci/golangci-lint-action@v5 with: - version: v1.58 + version: latest # ... ``` diff --git a/action.yml b/action.yml index 4f3cb3a4bf..a85cf66f1e 100644 --- a/action.yml +++ b/action.yml @@ -8,9 +8,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 `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. required: false - args: - description: "golangci-lint command line arguments" - default: "" + install-mode: + description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'." + default: "binary" required: false working-directory: description: "golangci-lint working directory, default is project root" @@ -35,9 +35,9 @@ inputs: restore existing caches, subject to other options. 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 runs: using: "node20" From aebff4bd9cd0198ff4f020915c27258a9edc4c01 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 01:36:48 +0200 Subject: [PATCH 18/26] feat: add option to enable/disable annotations --- README.md | 12 ++++++++++++ action.yml | 4 ++++ dist/post_run/index.js | 21 ++++++++++++--------- dist/run/index.js | 21 ++++++++++++--------- src/run.ts | 24 ++++++++++++++---------- 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4f8d941830..b33532660f 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,18 @@ with: # ... ``` +`annotations`: (optional) To enable/disable GitHub Action annotations. +If disabled (`false`), the output format(s) will follow the golangci-lint configuration file and use the same default as golangci-lint (i.e. `colored-line-number`). +https://golangci-lint.run/usage/configuration/#output-configuration +The default value is `true`. + +```yml +uses: golangci/golangci-lint-action@v5 +with: + annotations: false + # ... +``` + `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=` diff --git a/action.yml b/action.yml index a85cf66f1e..b498ad078f 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,10 @@ inputs: restore existing caches, subject to other options. default: 'false' required: false + annotations: + description: "To Enable/disable GitHub Action annotations" + default: 'true' + required: false args: description: "golangci-lint command line arguments" default: "" diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 9dd2226db6..b6746c4c53 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89287,15 +89287,18 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(","); - addedArgs.push(`--out-format=${formats}`); - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + const annotations = core.getInput(`annotations`).trim() !== "false"; + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(","); + addedArgs.push(`--out-format=${formats}`); + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + } 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`); diff --git a/dist/run/index.js b/dist/run/index.js index b015ef3b3f..278dc9a2c6 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89287,15 +89287,18 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(","); - addedArgs.push(`--out-format=${formats}`); - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + const annotations = core.getInput(`annotations`).trim() !== "false"; + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(","); + addedArgs.push(`--out-format=${formats}`); + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); + } 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`); diff --git a/src/run.ts b/src/run.ts index 60ff43201b..db8cf53a50 100644 --- a/src/run.ts +++ b/src/run.ts @@ -192,16 +192,20 @@ async function runLint(lintPath: string, patchPath: string): Promise { const userArgsMap = new Map(userArgsList) const userArgNames = new Set(userArgsList.map(([key]) => key)) - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) - .concat("github-actions") - .join(",") - - addedArgs.push(`--out-format=${formats}`) - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim() + const annotations = core.getInput(`annotations`).trim() !== "false" + + if (annotations) { + const formats = (userArgsMap.get("out-format") || "") + .trim() + .split(",") + .filter((f) => f.length > 0) + .filter((f) => !f.startsWith(`github-actions`)) + .concat("github-actions") + .join(",") + + addedArgs.push(`--out-format=${formats}`) + userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim() + } if (isOnlyNewIssues()) { if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { From d9c9b53e53fa63215cdd19637cd95fbc34fdf4a1 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 01:41:30 +0200 Subject: [PATCH 19/26] chore: improve marketplace style --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index b498ad078f..2318f3473b 100644 --- a/action.yml +++ b/action.yml @@ -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." author: "golangci" inputs: @@ -49,4 +50,4 @@ runs: post: "dist/post_run/index.js" branding: icon: "shield" - color: "yellow" + color: "white" From ca8befdfb6b98e59b2a2d1d65070c6e66a858ae1 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 02:36:06 +0200 Subject: [PATCH 20/26] doc: improve options documentation --- README.md | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b33532660f..abe55b532c 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,9 @@ You will also likely need to add the following `.gitattributes` file to ensure t ## Options -`version`: (required) The version of golangci-lint to use. +### `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. @@ -111,7 +113,9 @@ with: # ... ``` -`install-mode`: (optional) The mode to install golangci-lint. +### `install-mode` + +(optional) The mode to install golangci-lint. It can be `binary` or `goinstall`. The default value is `binary`. @@ -122,7 +126,9 @@ with: # ... ``` -`only-new-issues`: (optional) Show only new issues. +### `only-new-issues` + +(optional) Show only new issues. If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. The default value is `false`. @@ -133,7 +139,9 @@ with: # ... ``` -`working-directory`: (optional) working directory, useful for monorepos. +### `working-directory` + +(optional) working directory, useful for monorepos. ```yml uses: golangci/golangci-lint-action@v5 @@ -142,7 +150,9 @@ with: # ... ``` -`skip-cache`: (optional) If set to `true`, then all caching functionality will be completely disabled, +### `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`. @@ -153,7 +163,9 @@ with: # ... ``` -`skip-save-cache`: (optional) If set to `true`, caches will not be saved, but they may still be restored, required `skip-cache: false`. +### `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 @@ -163,7 +175,9 @@ with: # ... ``` -`annotations`: (optional) To enable/disable GitHub Action annotations. +### `annotations` + +(optional) To enable/disable GitHub Action annotations. If disabled (`false`), the output format(s) will follow the golangci-lint configuration file and use the same default as golangci-lint (i.e. `colored-line-number`). https://golangci-lint.run/usage/configuration/#output-configuration The default value is `true`. @@ -175,7 +189,9 @@ with: # ... ``` -`args`: (optional) golangci-lint command line arguments. +### `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=` From 046435d14ca6ec39fd472741e51e3bfbc403b4a7 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 02:42:39 +0200 Subject: [PATCH 21/26] doc: improve options documentation --- README.md | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index abe55b532c..b05f02e823 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,10 @@ You will also likely need to add the following `.gitattributes` file to ensure t ### `version` -(required) The version of golangci-lint to use. +(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. @@ -115,8 +118,10 @@ with: ### `install-mode` -(optional) The mode to install golangci-lint. -It can be `binary` or `goinstall`. +(optional) + +The mode to install golangci-lint: it can be `binary` or `goinstall`. + The default value is `binary`. ```yml @@ -128,8 +133,12 @@ with: ### `only-new-issues` -(optional) Show only new issues. +(optional) + +Show only new issues. + If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. + The default value is `false`. ```yml @@ -141,7 +150,9 @@ with: ### `working-directory` -(optional) working directory, useful for monorepos. +(optional) + +Working directory, useful for monorepos. ```yml uses: golangci/golangci-lint-action@v5 @@ -152,8 +163,11 @@ with: ### `skip-cache` -(optional) If set to `true`, then all caching functionality will be completely disabled, +(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 @@ -165,7 +179,10 @@ with: ### `skip-save-cache` -(optional) If set to `true`, caches will not be saved, but they may still be restored, required `skip-cache: false`. +(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 @@ -177,9 +194,15 @@ with: ### `annotations` -(optional) To enable/disable GitHub Action annotations. -If disabled (`false`), the output format(s) will follow the golangci-lint configuration file and use the same default as golangci-lint (i.e. `colored-line-number`). +(optional) + +To enable/disable GitHub Action annotations. + +If disabled (`false`), the output format(s) will follow the golangci-lint configuration file (or CLI flags from `args`) +and use the same default as golangci-lint (i.e. `colored-line-number`). + https://golangci-lint.run/usage/configuration/#output-configuration + The default value is `true`. ```yml @@ -191,7 +214,10 @@ with: ### `args` -(optional) golangci-lint command line arguments. +(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=` From ecb32920c642fc861819e7d1e27c1f9fff303882 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 4 May 2024 16:54:30 +0200 Subject: [PATCH 22/26] feat: uses 2 dots compare syntax for push diff (#1030) --- README.md | 7 +++++-- dist/post_run/index.js | 5 ++--- dist/run/index.js | 5 ++--- src/run.ts | 5 ++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b05f02e823..e89250977d 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,6 @@ with: Show only new issues. -If you are using `merge_group` event (merge queue) you should add the option `fetch-depth: 0` to `actions/checkout` step. - The default value is `false`. ```yml @@ -148,6 +146,11 @@ with: # ... ``` +* `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) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index b6746c4c53..257c21b5c5 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89221,11 +89221,10 @@ async function fetchPushPatch(ctx) { const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); let patch; try { - const patchResp = await octokit.rest.repos.compareCommits({ + const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({ owner: ctx.repo.owner, repo: ctx.repo.repo, - base: ctx.payload.before, - head: ctx.payload.after, + basehead: `${ctx.payload.before}..${ctx.payload.after}`, mediaType: { format: `diff`, }, diff --git a/dist/run/index.js b/dist/run/index.js index 278dc9a2c6..111a65705c 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89221,11 +89221,10 @@ async function fetchPushPatch(ctx) { const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); let patch; try { - const patchResp = await octokit.rest.repos.compareCommits({ + const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({ owner: ctx.repo.owner, repo: ctx.repo.repo, - base: ctx.payload.before, - head: ctx.payload.after, + basehead: `${ctx.payload.before}..${ctx.payload.after}`, mediaType: { format: `diff`, }, diff --git a/src/run.ts b/src/run.ts index db8cf53a50..2d5d3a2ae2 100644 --- a/src/run.ts +++ b/src/run.ts @@ -104,11 +104,10 @@ async function fetchPushPatch(ctx: Context): Promise { let patch: string try { - const patchResp = await octokit.rest.repos.compareCommits({ + const patchResp = await octokit.rest.repos.compareCommitsWithBasehead({ owner: ctx.repo.owner, repo: ctx.repo.repo, - base: ctx.payload.before, - head: ctx.payload.after, + basehead: `${ctx.payload.before}..${ctx.payload.after}`, mediaType: { format: `diff`, }, From dbb7ebcd4c72c62f0b6fe5dd8f2cf90cc85c7946 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 4 May 2024 17:47:25 +0200 Subject: [PATCH 23/26] feat: add option to control cache invalidation interval (#1031) --- README.md | 17 +++++++++++++++++ action.yml | 4 ++++ dist/post_run/index.js | 7 +++++-- dist/run/index.js | 7 +++++-- src/cache.ts | 16 ++++++++++++++-- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e89250977d..e32a5c0172 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,23 @@ with: # ... ``` +### `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). + ### `annotations` (optional) diff --git a/action.yml b/action.yml index 2318f3473b..bb4a50870e 100644 --- a/action.yml +++ b/action.yml @@ -44,6 +44,10 @@ inputs: 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: "node20" main: "dist/run/index.js" diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 257c21b5c5..06050ea1f0 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -88815,15 +88815,18 @@ const getLintCacheDir = () => { }; const getIntervalKey = (invalidationIntervalDays) => { 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(); }; async function buildCacheKeys() { const keys = []; + const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()); // Periodically invalidate a cache because a new code being added. - // TODO: configure it via inputs. - let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`; + let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`; keys.push(cacheKey); // Get working directory from input const workingDirectory = core.getInput(`working-directory`); diff --git a/dist/run/index.js b/dist/run/index.js index 111a65705c..b361fc4f25 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -88815,15 +88815,18 @@ const getLintCacheDir = () => { }; const getIntervalKey = (invalidationIntervalDays) => { 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(); }; async function buildCacheKeys() { const keys = []; + const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()); // Periodically invalidate a cache because a new code being added. - // TODO: configure it via inputs. - let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`; + let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`; keys.push(cacheKey); // Get working directory from input const workingDirectory = core.getInput(`working-directory`); diff --git a/src/cache.ts b/src/cache.ts index 5c73169753..75fda9f9a4 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -25,6 +25,11 @@ const getLintCacheDir = (): string => { 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() @@ -32,21 +37,28 @@ const getIntervalKey = (invalidationIntervalDays: number): string => { async function buildCacheKeys(): Promise { const keys = [] + + const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()) + // Periodically invalidate a cache because a new code being added. - // TODO: configure it via inputs. - let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-` + let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-` keys.push(cacheKey) + // Get working directory from input const workingDirectory = core.getInput(`working-directory`) + // 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 From dbe4fc23f1260a21484a6c6c008545afc299faa3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 17:48:42 +0200 Subject: [PATCH 24/26] chore: use getBooleanInput --- dist/post_run/index.js | 14 +++++--------- dist/run/index.js | 14 +++++--------- src/cache.ts | 6 +++--- src/run.ts | 10 ++-------- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 06050ea1f0..6f07a5f73c 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -88844,7 +88844,7 @@ async function buildCacheKeys() { return keys; } async function restoreCache() { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-cache`, { required: true })) return; if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); @@ -88882,9 +88882,9 @@ async function restoreCache() { } exports.restoreCache = restoreCache; async function saveCache() { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-cache`, { required: true })) return; - if (core.getInput(`skip-save-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-save-cache`, { required: true })) return; // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { @@ -89150,11 +89150,7 @@ const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); const createTempDir = (0, util_1.promisify)(tmp_1.dir); function isOnlyNewIssues() { - 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"`); - } - return onlyNewIssues === `true`; + return core.getBooleanInput(`only-new-issues`, { required: true }); } async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); @@ -89289,7 +89285,7 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const annotations = core.getInput(`annotations`).trim() !== "false"; + const annotations = core.getBooleanInput(`annotations`); if (annotations) { const formats = (userArgsMap.get("out-format") || "") .trim() diff --git a/dist/run/index.js b/dist/run/index.js index b361fc4f25..b67b479635 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -88844,7 +88844,7 @@ async function buildCacheKeys() { return keys; } async function restoreCache() { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-cache`, { required: true })) return; if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); @@ -88882,9 +88882,9 @@ async function restoreCache() { } exports.restoreCache = restoreCache; async function saveCache() { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-cache`, { required: true })) return; - if (core.getInput(`skip-save-cache`, { required: true }).trim() == "true") + if (core.getBooleanInput(`skip-save-cache`, { required: true })) return; // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { @@ -89150,11 +89150,7 @@ const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); const createTempDir = (0, util_1.promisify)(tmp_1.dir); function isOnlyNewIssues() { - 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"`); - } - return onlyNewIssues === `true`; + return core.getBooleanInput(`only-new-issues`, { required: true }); } async function prepareLint() { const mode = core.getInput("install-mode").toLowerCase(); @@ -89289,7 +89285,7 @@ async function runLint(lintPath, patchPath) { .map(([key, value]) => [key.toLowerCase(), value ?? ""]); const userArgsMap = new Map(userArgsList); const userArgNames = new Set(userArgsList.map(([key]) => key)); - const annotations = core.getInput(`annotations`).trim() !== "false"; + const annotations = core.getBooleanInput(`annotations`); if (annotations) { const formats = (userArgsMap.get("out-format") || "") .trim() diff --git a/src/cache.ts b/src/cache.ts index 75fda9f9a4..314647d6a7 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -65,7 +65,7 @@ async function buildCacheKeys(): Promise { } export async function restoreCache(): Promise { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return + if (core.getBooleanInput(`skip-cache`, { required: true })) return if (!utils.isValidEvent()) { utils.logWarning( @@ -107,8 +107,8 @@ export async function restoreCache(): Promise { } export async function saveCache(): Promise { - if (core.getInput(`skip-cache`, { required: true }).trim() == "true") return - if (core.getInput(`skip-save-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()) { diff --git a/src/run.ts b/src/run.ts index 2d5d3a2ae2..48550d4576 100644 --- a/src/run.ts +++ b/src/run.ts @@ -17,13 +17,7 @@ const writeFile = promisify(fs.writeFile) const createTempDir = promisify(dir) function isOnlyNewIssues(): boolean { - 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"`) - } - - return onlyNewIssues === `true` + return core.getBooleanInput(`only-new-issues`, { required: true }) } async function prepareLint(): Promise { @@ -191,7 +185,7 @@ async function runLint(lintPath: string, patchPath: string): Promise { const userArgsMap = new Map(userArgsList) const userArgNames = new Set(userArgsList.map(([key]) => key)) - const annotations = core.getInput(`annotations`).trim() !== "false" + const annotations = core.getBooleanInput(`annotations`) if (annotations) { const formats = (userArgsMap.get("out-format") || "") From 21e9e6b47f3490b8adcca53fe65c03e2687b503c Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 4 May 2024 18:43:48 +0200 Subject: [PATCH 25/26] feat: use OS and working-directory as cache key (#1032) --- README.md | 5 +++-- dist/post_run/index.js | 13 +++++++++---- dist/run/index.js | 13 +++++++++---- src/cache.ts | 17 ++++++++++++----- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e32a5c0172..5e498a32a7 100644 --- a/README.md +++ b/README.md @@ -308,10 +308,11 @@ Inside our action, we perform 3 steps: ### Caching internals 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}`. +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-{interval_number}-`. +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. diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 6f07a5f73c..23f6c001c0 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -88824,12 +88824,17 @@ const getIntervalKey = (invalidationIntervalDays) => { }; async function buildCacheKeys() { const keys = []; - const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()); - // Periodically invalidate a cache because a new code being added. - let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`; - 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_1.default.join(workingDirectory, `go.mod`); core.info(`Checking for go.mod: ${goModPath}`); diff --git a/dist/run/index.js b/dist/run/index.js index b67b479635..428acc2f77 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -88824,12 +88824,17 @@ const getIntervalKey = (invalidationIntervalDays) => { }; async function buildCacheKeys() { const keys = []; - const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()); - // Periodically invalidate a cache because a new code being added. - let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`; - 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_1.default.join(workingDirectory, `go.mod`); core.info(`Checking for go.mod: ${goModPath}`); diff --git a/src/cache.ts b/src/cache.ts index 314647d6a7..dc6aa06b14 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -38,15 +38,22 @@ const getIntervalKey = (invalidationIntervalDays: number): string => { async function buildCacheKeys(): Promise { const keys = [] - const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim()) - - // Periodically invalidate a cache because a new code being added. - let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-` - 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`) From 38e1018663fa5173f3968ea0777460d3de38f256 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sun, 5 May 2024 01:13:21 +0200 Subject: [PATCH 26/26] feat: improve log about pwd/cwd (#1033) --- dist/post_run/index.js | 4 ++-- dist/run/index.js | 4 ++-- src/run.ts | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 23f6c001c0..87f67815a6 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -89329,8 +89329,8 @@ async function runLint(lintPath, patchPath) { break; } } - const workingDirectory = core.getInput(`working-directory`); const cmdArgs = {}; + const workingDirectory = core.getInput(`working-directory`); if (workingDirectory) { if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`); @@ -89341,7 +89341,7 @@ async function runLint(lintPath, patchPath) { cmdArgs.cwd = path.resolve(workingDirectory); } 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 { const res = await execShellCommand(cmd, cmdArgs); diff --git a/dist/run/index.js b/dist/run/index.js index 428acc2f77..11ef531598 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -89329,8 +89329,8 @@ async function runLint(lintPath, patchPath) { break; } } - const workingDirectory = core.getInput(`working-directory`); const cmdArgs = {}; + const workingDirectory = core.getInput(`working-directory`); if (workingDirectory) { if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`); @@ -89341,7 +89341,7 @@ async function runLint(lintPath, patchPath) { cmdArgs.cwd = path.resolve(workingDirectory); } 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 { const res = await execShellCommand(cmd, cmdArgs); diff --git a/src/run.ts b/src/run.ts index 48550d4576..9cffa9c690 100644 --- a/src/run.ts +++ b/src/run.ts @@ -233,8 +233,9 @@ async function runLint(lintPath: string, patchPath: string): Promise { } } - const workingDirectory = core.getInput(`working-directory`) const cmdArgs: ExecOptions = {} + + const workingDirectory = core.getInput(`working-directory`) if (workingDirectory) { if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`) @@ -247,7 +248,7 @@ async function runLint(lintPath: string, patchPath: string): Promise { 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 {