From ca8befdfb6b98e59b2a2d1d65070c6e66a858ae1 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 4 May 2024 02:36:06 +0200 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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 {