use the key in state to save caches in the post process

This commit is contained in:
Kengo TODA 2021-07-16 07:28:13 +08:00
parent 6977c031ae
commit 7fe6c4d631
5 changed files with 102 additions and 17 deletions

View file

@ -90,9 +90,15 @@ export async function restore(id: string) {
*/
export async function save(id: string) {
const packageManager = findPackageManager(id);
const primaryKey = await computeCacheKey(packageManager);
const matchedKey = core.getState(CACHE_MATCHED_KEY);
if (matchedKey === primaryKey) {
// Inputs are re-evaluted before the post action, so we want the original key used for restore
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
if (!primaryKey) {
core.warning('Error retrieving key from state.');
return;
} else if (matchedKey === primaryKey) {
// no change in target directories
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
return;