mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-18 16:38:27 +00:00
use working-directory as cache key
This commit is contained in:
parent
92ba55cf0d
commit
9773a70155
2 changed files with 12 additions and 5 deletions
|
|
@ -167,9 +167,10 @@ Inside our action we perform 3 steps:
|
||||||
### Caching internals
|
### Caching internals
|
||||||
|
|
||||||
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
|
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
|
||||||
2. The primary caching key looks like `golangci-lint.cache-{platform-arch}-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
|
2. The primary caching key looks like `golangci-lint.cache-{interval_number}-{go.mod_hash}` (with `working-directory`, key will be `golangci-lint.cache-${working-directory}-{interval_number}-{go.mod_hash}`).
|
||||||
our cache (every 7 days). `go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed.
|
Interval number ensures that we periodically invalidate our cache (every 7 days). `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}-`, `golangci-lint.cache-`. GitHub matches keys by prefix if we have no exact match for the primary cache.
|
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}-` (with `working-directory`, `golangci-lint.cache-${working-directory}-{interval_number}-`).
|
||||||
|
GitHub matches keys by prefix if we have no exact match for the primary cache.
|
||||||
|
|
||||||
This scheme is basic and needs improvements. Pull requests and ideas are welcome.
|
This scheme is basic and needs improvements. Pull requests and ideas are welcome.
|
||||||
|
|
||||||
|
|
|
||||||
10
src/cache.ts
10
src/cache.ts
|
|
@ -54,10 +54,16 @@ async function buildCacheKeys(): Promise<string[]> {
|
||||||
const keys = []
|
const keys = []
|
||||||
// Periodically invalidate a cache because a new code being added.
|
// Periodically invalidate a cache because a new code being added.
|
||||||
// TODO: configure it via inputs.
|
// TODO: configure it via inputs.
|
||||||
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`
|
let cacheKey = `golangci-lint.cache-`
|
||||||
keys.push(cacheKey)
|
|
||||||
// Get working directory from input
|
// Get working directory from input
|
||||||
const workingDirectory = core.getInput(`working-directory`)
|
const workingDirectory = core.getInput(`working-directory`)
|
||||||
|
if (workingDirectory) {
|
||||||
|
cacheKey += `${workingDirectory}-`
|
||||||
|
}
|
||||||
|
cacheKey += `${getIntervalKey(7)}-`
|
||||||
|
|
||||||
|
keys.push(cacheKey)
|
||||||
|
|
||||||
// create path to go.mod prepending the workingDirectory if it exists
|
// create path to go.mod prepending the workingDirectory if it exists
|
||||||
const goModPath = path.join(workingDirectory, `go.mod`)
|
const goModPath = path.join(workingDirectory, `go.mod`)
|
||||||
core.info(`Checking for go.mod: ${goModPath}`)
|
core.info(`Checking for go.mod: ${goModPath}`)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue