mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 03:45:31 +00:00
Fixed inputs
This commit is contained in:
parent
61aa90bfc3
commit
d91f5bd2fd
10 changed files with 95 additions and 44 deletions
|
@ -1,14 +1,15 @@
|
|||
export enum Inputs {
|
||||
Key = "key",
|
||||
Path = "path",
|
||||
RestoreKeys = "restore-keys",
|
||||
UploadChunkSize = "upload-chunk-size"
|
||||
Key = "key", // Input from cache, restore, save action
|
||||
Path = "path", // Input from cache, restore, save action
|
||||
RestoreKeys = "restore-keys", // Input from cache, restore action
|
||||
UploadChunkSize = "upload-chunk-size", // Input from cache, save action
|
||||
RestoredKey = "restored-key" // Input from save action
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
CacheHit = "cache-hit",
|
||||
Key = "key",
|
||||
MatchedKey = "matched-key"
|
||||
CacheHit = "cache-hit", // Output from cache, restore action
|
||||
InputtedKey = "inputted-key", // Output from restore action
|
||||
MatchedKey = "matched-key" // Output from restore action
|
||||
}
|
||||
|
||||
export enum State {
|
||||
|
|
|
@ -25,7 +25,11 @@ async function restoreImpl(
|
|||
}
|
||||
|
||||
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||
stateProvider.setState(State.CachePrimaryKey, primaryKey);
|
||||
stateProvider.setState(
|
||||
State.CachePrimaryKey,
|
||||
primaryKey,
|
||||
Outputs.InputtedKey
|
||||
);
|
||||
|
||||
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
|
@ -50,7 +54,11 @@ async function restoreImpl(
|
|||
}
|
||||
|
||||
// Store the matched cache key in states
|
||||
stateProvider.setState(State.CacheMatchedKey, cacheKey);
|
||||
stateProvider.setState(
|
||||
State.CacheMatchedKey,
|
||||
cacheKey,
|
||||
Outputs.MatchedKey
|
||||
);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||
core.getInput(Inputs.Key, { required: true }),
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
|
|||
import * as core from "@actions/core";
|
||||
|
||||
import { Events, Inputs, State } from "./constants";
|
||||
import { IStateProvider } from "./stateProvider";
|
||||
import { IStateProvider, StateProvider } from "./stateProvider";
|
||||
import * as utils from "./utils/actionUtils";
|
||||
|
||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||
|
@ -32,14 +32,20 @@ async function saveImpl(stateProvider: IStateProvider): Promise<void> {
|
|||
core.getInput(Inputs.Key);
|
||||
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Error retrieving key from state.`);
|
||||
if (stateProvider instanceof StateProvider) {
|
||||
utils.logWarning(`Error retrieving key from state.`);
|
||||
} else {
|
||||
utils.logWarning(`Error retrieving key from input.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If matched restore key is same as primary key, then do not save cache
|
||||
// NO-OP in case of SaveOnly action
|
||||
const state = stateProvider.getCacheState();
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
const restoredKey =
|
||||
stateProvider.getCacheState() || core.getInput(Inputs.RestoredKey);
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as core from "@actions/core";
|
|||
import { State } from "./constants";
|
||||
|
||||
export interface IStateProvider {
|
||||
setState(key: string, value: string): void;
|
||||
setState(key: string, value: string, outputKey?: string): void;
|
||||
getState(key: string): string;
|
||||
|
||||
getCacheState(): string | undefined;
|
||||
|
@ -21,7 +21,7 @@ class StateProviderBase implements IStateProvider {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||
setState = (key: string, value: string) => {};
|
||||
setState = (key: string, value: string, outputKey?: string) => {};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
getState = (key: string) => "";
|
||||
|
@ -33,7 +33,11 @@ export class StateProvider extends StateProviderBase {
|
|||
}
|
||||
|
||||
export class NullStateProvider extends StateProviderBase {
|
||||
setState = core.setOutput;
|
||||
setState = (key: string, value: string, outputKey?: string) => {
|
||||
if (outputKey) {
|
||||
core.setOutput(outputKey, value);
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
getState = (key: string) => "";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue