mirror of
https://kkgithub.com/actions/cache.git
synced 2025-10-27 16:56:12 +08:00
stateinputprovider with pending test cases fix
This commit is contained in:
@ -28,9 +28,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
|
||||
|
||||
// If restore has stored a primary key in state, reuse that
|
||||
// Else re-evaluate from inputs
|
||||
const primaryKey =
|
||||
stateProvider.getState(State.CachePrimaryKey) ||
|
||||
core.getInput(Inputs.Key);
|
||||
const primaryKey = stateProvider.getState(State.CachePrimaryKey);
|
||||
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Key is not specified.`);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { Outputs, State } from "./constants";
|
||||
import { Inputs, Outputs, State } from "./constants";
|
||||
|
||||
export interface IStateProvider {
|
||||
setState(key: string, value: string): void;
|
||||
@ -33,6 +33,10 @@ export class StateProvider extends StateProviderBase {
|
||||
}
|
||||
|
||||
export class NullStateProvider extends StateProviderBase {
|
||||
stateToInputMap = new Map<string, string>([
|
||||
[State.CachePrimaryKey, Inputs.Key]
|
||||
]);
|
||||
|
||||
stateToOutputMap = new Map<string, string>([
|
||||
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
||||
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
||||
@ -41,6 +45,8 @@ export class NullStateProvider extends StateProviderBase {
|
||||
setState = (key: string, value: string) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key) as string, value);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
getState = (key: string) => "";
|
||||
|
||||
getState = (key: string) => {
|
||||
return core.getInput(this.stateToInputMap.get(key) as string);
|
||||
};
|
||||
}
|
||||
|
||||
@ -9,6 +9,10 @@ export function setInput(name: string, value: string): void {
|
||||
process.env[getInputName(name)] = value;
|
||||
}
|
||||
|
||||
export function getInput(name: string): string {
|
||||
return process.env[getInputName(name)] as string;
|
||||
}
|
||||
|
||||
interface CacheInput {
|
||||
path: string;
|
||||
key: string;
|
||||
|
||||
Reference in New Issue
Block a user