3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-22 11:25:31 +00:00

React to feeback and change to use 0.2.0 cache package

This commit is contained in:
Aiqiao Yan 2020-05-19 13:46:58 -04:00
parent 249a22026d
commit bcc23b930f
10 changed files with 5098 additions and 5604 deletions

View file

@ -9,8 +9,8 @@ export enum Outputs {
}
export enum State {
CacheKey = "CACHE_KEY",
CacheResult = "CACHE_RESULT"
CachePrimaryKey = "CACHE_KEY",
CacheMatchedKey = "CACHE_RESULT"
}
export enum Events {

View file

@ -17,7 +17,7 @@ async function run(): Promise<void> {
}
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CacheKey, primaryKey);
core.saveState(State.CachePrimaryKey, primaryKey);
const restoreKeys = core
.getInput(Inputs.RestoreKeys)
@ -45,7 +45,7 @@ async function run(): Promise<void> {
return;
}
// Store the cache result
// Store the matched cache key
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);

View file

@ -18,7 +18,7 @@ async function run(): Promise<void> {
const state = utils.getCacheState();
// Inputs are re-evaluted before the post action, so we want the original key used for restore
const primaryKey = core.getState(State.CacheKey);
const primaryKey = core.getState(State.CachePrimaryKey);
if (!primaryKey) {
utils.logWarning(`Error retrieving key from state.`);
return;

View file

@ -12,7 +12,7 @@ export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
}
export function setCacheState(state: string): void {
core.saveState(State.CacheResult, state);
core.saveState(State.CacheMatchedKey, state);
}
export function setCacheHitOutput(isCacheHit: boolean): void {
@ -21,12 +21,12 @@ export function setCacheHitOutput(isCacheHit: boolean): void {
export function setOutputAndState(key: string, cacheKey?: string): void {
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
// Store the cache result if it exists
// Store the matched cache key if it exists
cacheKey && setCacheState(cacheKey);
}
export function getCacheState(): string | undefined {
const cacheKey = core.getState(State.CacheResult);
const cacheKey = core.getState(State.CacheMatchedKey);
if (cacheKey) {
core.debug(`Cache state/key: ${cacheKey}`);
return cacheKey;