feat: add option to control cache invalidation interval (#1031)
This commit is contained in:
parent
ecb32920c6
commit
dbb7ebcd4c
17
README.md
17
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`
|
### `annotations`
|
||||||
|
|
||||||
(optional)
|
(optional)
|
||||||
|
@ -44,6 +44,10 @@ inputs:
|
|||||||
description: "golangci-lint command line arguments"
|
description: "golangci-lint command line arguments"
|
||||||
default: ""
|
default: ""
|
||||||
required: false
|
required: false
|
||||||
|
cache-invalidation-interval:
|
||||||
|
description: "Periodically invalidate a cache because a new code being added. (number of days)"
|
||||||
|
default: '7'
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node20"
|
||||||
main: "dist/run/index.js"
|
main: "dist/run/index.js"
|
||||||
|
7
dist/post_run/index.js
generated
vendored
7
dist/post_run/index.js
generated
vendored
@ -88815,15 +88815,18 @@ const getLintCacheDir = () => {
|
|||||||
};
|
};
|
||||||
const getIntervalKey = (invalidationIntervalDays) => {
|
const getIntervalKey = (invalidationIntervalDays) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
if (invalidationIntervalDays <= 0) {
|
||||||
|
return `${now.getTime()}`;
|
||||||
|
}
|
||||||
const secondsSinceEpoch = now.getTime() / 1000;
|
const secondsSinceEpoch = now.getTime() / 1000;
|
||||||
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400));
|
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400));
|
||||||
return intervalNumber.toString();
|
return intervalNumber.toString();
|
||||||
};
|
};
|
||||||
async function buildCacheKeys() {
|
async function buildCacheKeys() {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
|
const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim());
|
||||||
// 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.
|
let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`;
|
||||||
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`;
|
|
||||||
keys.push(cacheKey);
|
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`);
|
||||||
|
7
dist/run/index.js
generated
vendored
7
dist/run/index.js
generated
vendored
@ -88815,15 +88815,18 @@ const getLintCacheDir = () => {
|
|||||||
};
|
};
|
||||||
const getIntervalKey = (invalidationIntervalDays) => {
|
const getIntervalKey = (invalidationIntervalDays) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
if (invalidationIntervalDays <= 0) {
|
||||||
|
return `${now.getTime()}`;
|
||||||
|
}
|
||||||
const secondsSinceEpoch = now.getTime() / 1000;
|
const secondsSinceEpoch = now.getTime() / 1000;
|
||||||
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400));
|
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400));
|
||||||
return intervalNumber.toString();
|
return intervalNumber.toString();
|
||||||
};
|
};
|
||||||
async function buildCacheKeys() {
|
async function buildCacheKeys() {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
|
const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim());
|
||||||
// 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.
|
let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`;
|
||||||
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`;
|
|
||||||
keys.push(cacheKey);
|
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`);
|
||||||
|
16
src/cache.ts
16
src/cache.ts
@ -25,6 +25,11 @@ const getLintCacheDir = (): string => {
|
|||||||
|
|
||||||
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
|
if (invalidationIntervalDays <= 0) {
|
||||||
|
return `${now.getTime()}`
|
||||||
|
}
|
||||||
|
|
||||||
const secondsSinceEpoch = now.getTime() / 1000
|
const secondsSinceEpoch = now.getTime() / 1000
|
||||||
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400))
|
const intervalNumber = Math.floor(secondsSinceEpoch / (invalidationIntervalDays * 86400))
|
||||||
return intervalNumber.toString()
|
return intervalNumber.toString()
|
||||||
@ -32,21 +37,28 @@ const getIntervalKey = (invalidationIntervalDays: number): string => {
|
|||||||
|
|
||||||
async function buildCacheKeys(): Promise<string[]> {
|
async function buildCacheKeys(): Promise<string[]> {
|
||||||
const keys = []
|
const keys = []
|
||||||
|
|
||||||
|
const invalidationIntervalDays = parseInt(core.getInput(`cache-invalidation-interval`, { required: true }).trim())
|
||||||
|
|
||||||
// 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.
|
let cacheKey = `golangci-lint.cache-${getIntervalKey(invalidationIntervalDays)}-`
|
||||||
let cacheKey = `golangci-lint.cache-${getIntervalKey(7)}-`
|
|
||||||
keys.push(cacheKey)
|
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`)
|
||||||
|
|
||||||
// create path to go.mod prepending the workingDirectory if it exists
|
// create path to go.mod prepending the workingDirectory if it exists
|
||||||
const goModPath = path.join(workingDirectory, `go.mod`)
|
const goModPath = path.join(workingDirectory, `go.mod`)
|
||||||
|
|
||||||
core.info(`Checking for go.mod: ${goModPath}`)
|
core.info(`Checking for go.mod: ${goModPath}`)
|
||||||
|
|
||||||
if (await pathExists(goModPath)) {
|
if (await pathExists(goModPath)) {
|
||||||
// Add checksum to key to invalidate a cache when dependencies change.
|
// Add checksum to key to invalidate a cache when dependencies change.
|
||||||
cacheKey += await checksumFile(`sha1`, goModPath)
|
cacheKey += await checksumFile(`sha1`, goModPath)
|
||||||
} else {
|
} else {
|
||||||
cacheKey += `nogomod`
|
cacheKey += `nogomod`
|
||||||
}
|
}
|
||||||
|
|
||||||
keys.push(cacheKey)
|
keys.push(cacheKey)
|
||||||
|
|
||||||
return keys
|
return keys
|
||||||
|
Loading…
x
Reference in New Issue
Block a user