mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-22 16:53:57 +08:00
Allow updating caches
This commit is contained in:
parent
36f1e144e1
commit
d69c349a03
7 changed files with 3802 additions and 12803 deletions
|
@ -43,15 +43,38 @@ export async function saveImpl(
|
|||
return;
|
||||
}
|
||||
|
||||
// If matched restore key is same as primary key, then do not save cache
|
||||
// NO-OP in case of SaveOnly action
|
||||
const refreshCache: boolean = utils.getInputAsBool(
|
||||
Inputs.RefreshCache,
|
||||
{ required: false }
|
||||
);
|
||||
|
||||
// If matched restore key is same as primary key, either try to refresh the cache, or just notify and do not save (NO-OP in case of SaveOnly action)
|
||||
|
||||
const restoredKey = stateProvider.getCacheState();
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
const { GITHUB_TOKEN, GITHUB_REPOSITORY } = process.env || null;
|
||||
if (GITHUB_TOKEN && GITHUB_REPOSITORY && refreshCache === true) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, attempting to refresh the contents of the cache.`
|
||||
);
|
||||
const [_owner, _repo] = GITHUB_REPOSITORY.split(`/`);
|
||||
if (_owner && _repo) {
|
||||
await utils.deleteCacheByKey(primaryKey, _owner, _repo);
|
||||
}
|
||||
} else {
|
||||
if (refreshCache === true) {
|
||||
utils.logWarning(
|
||||
`Can't refresh cache, either the repository info or a valid token are missing.`
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue