mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-06-08 23:41:17 +08:00
refactor into a generic outputter
This commit is contained in:
parent
706c369cf1
commit
d95c048983
4 changed files with 36 additions and 30 deletions
|
@ -1,10 +1,11 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { Events, Inputs, State } from "./constants";
|
||||
import { Events, Inputs, Outputs, State } from "./constants";
|
||||
import { IOutputSetter } from "./outputSetter";
|
||||
import * as utils from "./utils/actionUtils";
|
||||
|
||||
async function run(): Promise<string | undefined> {
|
||||
async function run(outputter: IOutputSetter): Promise<string | undefined> {
|
||||
try {
|
||||
if (!utils.isCacheFeatureAvailable()) {
|
||||
utils.setCacheHitOutput(false);
|
||||
|
@ -22,7 +23,7 @@ async function run(): Promise<string | undefined> {
|
|||
}
|
||||
|
||||
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||
outputter.setState(State.CachePrimaryKey, primaryKey);
|
||||
|
||||
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
|
@ -46,6 +47,18 @@ async function run(): Promise<string | undefined> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Store the matched cache key in states
|
||||
//utils.setCacheState(cacheKey);
|
||||
outputter.setState(State.CacheMatchedKey, cacheKey);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||
core.getInput(Inputs.Key, { required: true }),
|
||||
cacheKey
|
||||
);
|
||||
//utils.setCacheHitOutput(isExactKeyMatch);
|
||||
outputter.setOutput(Outputs.CacheHit, isExactKeyMatch.toString());
|
||||
core.info(`Cache restored from key: ${cacheKey}`);
|
||||
|
||||
return cacheKey;
|
||||
} catch (error: unknown) {
|
||||
core.setFailed((error as Error).message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue