mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-11-24 04:29:16 +01:00
2ebdcff279
* Add "see more" link to GHE-not-supported warning I lived for several months thinking that support for caching action on GHE is just a matter of time, because it's such an important thing to have. Only today, I discovered that originally it was not planned at all. And that people already created some workarounds. So I hope that linking the issue from the warning message will save other people from what happened to me :-) * Update new GHE-not-supported message in tests * Update generated dist files
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import * as cache from "@actions/cache";
|
|
import * as core from "@actions/core";
|
|
|
|
import { Events, Inputs, State } from "./constants";
|
|
import * as utils from "./utils/actionUtils";
|
|
|
|
async function run(): Promise<void> {
|
|
try {
|
|
if (utils.isGhes()) {
|
|
utils.logWarning(
|
|
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
|
|
);
|
|
utils.setCacheHitOutput(false);
|
|
return;
|
|
}
|
|
|
|
// Validate inputs, this can cause task failure
|
|
if (!utils.isValidEvent()) {
|
|
utils.logWarning(
|
|
`Event Validation Error: The event type ${
|
|
process.env[Events.Key]
|
|
} is not supported because it's not tied to a branch or tag ref.`
|
|
);
|
|
return;
|
|
}
|
|
|
|
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
|
|
|
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
|
required: true
|
|
});
|
|
|
|
try {
|
|
const cacheKey = await cache.restoreCache(
|
|
cachePaths,
|
|
primaryKey,
|
|
restoreKeys
|
|
);
|
|
if (!cacheKey) {
|
|
core.info(
|
|
`Cache not found for input keys: ${[
|
|
primaryKey,
|
|
...restoreKeys
|
|
].join(", ")}`
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Store the matched cache key
|
|
utils.setCacheState(cacheKey);
|
|
|
|
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
|
utils.setCacheHitOutput(isExactKeyMatch);
|
|
|
|
core.info(`Cache restored from key: ${cacheKey}`);
|
|
} catch (error) {
|
|
if (error.name === cache.ValidationError.name) {
|
|
throw error;
|
|
} else {
|
|
utils.logWarning(error.message);
|
|
utils.setCacheHitOutput(false);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
}
|
|
}
|
|
|
|
run();
|
|
|
|
export default run;
|