Add the 'always-cache' option

This commit is contained in:
Kevin Minehart 2025-03-11 09:59:40 -05:00
parent 5a083d0e9a
commit e5f5846dc4
3 changed files with 11 additions and 8 deletions

View File

@ -15,6 +15,9 @@ inputs:
cache: cache:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching. description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
default: true default: true
always-cache:
description: If enabled, stores the cache even in the event of a cache hit. This will result in a larger Go build (and test) cache, but less repeated test runs.
default: false
cache-dependency-path: cache-dependency-path:
description: 'Used to specify the path to a dependency file - go.sum' description: 'Used to specify the path to a dependency file - go.sum'
architecture: architecture:

View File

@ -89440,7 +89440,7 @@ function run(earlyExit) {
try { try {
const cacheInput = core.getBooleanInput('cache'); const cacheInput = core.getBooleanInput('cache');
if (cacheInput) { if (cacheInput) {
yield cachePackages(); yield cachePackages(core.getBooleanInput('always-cache'));
if (earlyExit) { if (earlyExit) {
process.exit(0); process.exit(0);
} }
@ -89459,7 +89459,7 @@ function run(earlyExit) {
}); });
} }
exports.run = run; exports.run = run;
const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { const cachePackages = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (alwaysCache = false) {
const packageManager = 'default'; const packageManager = 'default';
const state = core.getState(constants_1.State.CacheMatchedKey); const state = core.getState(constants_1.State.CacheMatchedKey);
const primaryKey = core.getState(constants_1.State.CachePrimaryKey); const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
@ -89477,8 +89477,8 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
core.info('Primary key was not generated. Please check the log messages above for more errors or information'); core.info('Primary key was not generated. Please check the log messages above for more errors or information');
return; return;
} }
if (primaryKey === state) { if (primaryKey === state && !alwaysCache) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); core.info(`Cache hit occurred on the primary key ${primaryKey} and always-cache is 'false', not saving cache.`);
return; return;
} }
const cacheId = yield cache.saveCache(cachePaths, primaryKey); const cacheId = yield cache.saveCache(cachePaths, primaryKey);

View File

@ -19,7 +19,7 @@ export async function run(earlyExit?: boolean) {
try { try {
const cacheInput = core.getBooleanInput('cache'); const cacheInput = core.getBooleanInput('cache');
if (cacheInput) { if (cacheInput) {
await cachePackages(); await cachePackages(core.getBooleanInput('always-cache'));
if (earlyExit) { if (earlyExit) {
process.exit(0); process.exit(0);
@ -37,7 +37,7 @@ export async function run(earlyExit?: boolean) {
} }
} }
const cachePackages = async () => { const cachePackages = async (alwaysCache: boolean = false) => {
const packageManager = 'default'; const packageManager = 'default';
const state = core.getState(State.CacheMatchedKey); const state = core.getState(State.CacheMatchedKey);
@ -71,9 +71,9 @@ const cachePackages = async () => {
return; return;
} }
if (primaryKey === state) { if (primaryKey === state && !alwaysCache) {
core.info( core.info(
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.` `Cache hit occurred on the primary key ${primaryKey} and always-cache is 'false', not saving cache.`
); );
return; return;
} }