mirror of https://github.com/actions/cache.git
refactor into a generic outputter
parent
706c369cf1
commit
d95c048983
@ -0,0 +1,16 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
|
export interface IOutputSetter {
|
||||||
|
setOutput(key: string, value: string): void;
|
||||||
|
setState(key: string, value: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class StateOutputSetter implements IOutputSetter {
|
||||||
|
setOutput = core.setOutput;
|
||||||
|
setState = core.saveState;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NonStateOuputSetter implements IOutputSetter {
|
||||||
|
setOutput = core.setOutput;
|
||||||
|
setState = core.setOutput;
|
||||||
|
}
|
@ -1,22 +1,8 @@
|
|||||||
import * as core from "@actions/core";
|
import { StateOutputSetter } from "./outputSetter";
|
||||||
|
|
||||||
import { Inputs } from "./constants";
|
|
||||||
import run from "./restoreImpl";
|
import run from "./restoreImpl";
|
||||||
import * as utils from "./utils/actionUtils";
|
|
||||||
|
|
||||||
async function restore(): Promise<void> {
|
async function restore(): Promise<void> {
|
||||||
const cacheKey = await run();
|
await run(new StateOutputSetter());
|
||||||
if (cacheKey) {
|
|
||||||
// Store the matched cache key in states
|
|
||||||
utils.setCacheState(cacheKey);
|
|
||||||
|
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
|
||||||
core.getInput(Inputs.Key, { required: true }),
|
|
||||||
cacheKey
|
|
||||||
);
|
|
||||||
utils.setCacheHitOutput(isExactKeyMatch);
|
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default restore;
|
export default restore;
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
import * as core from "@actions/core";
|
import { NonStateOuputSetter } from "./outputSetter";
|
||||||
|
|
||||||
import { Outputs } from "./constants";
|
|
||||||
import run from "./restoreImpl";
|
import run from "./restoreImpl";
|
||||||
import * as utils from "./utils/actionUtils";
|
|
||||||
|
|
||||||
async function restoreOnly(): Promise<void> {
|
async function restoreOnly(): Promise<void> {
|
||||||
const cacheKey = await run();
|
await run(new NonStateOuputSetter());
|
||||||
if (cacheKey) {
|
|
||||||
// Store the matched cache key in output
|
|
||||||
core.setOutput(Outputs.Key, utils.getCacheState());
|
|
||||||
|
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default restoreOnly;
|
export default restoreOnly;
|
||||||
|
Loading…
Reference in New Issue