mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-22 16:53:57 +08:00
Add outputs.cache-key
This commit is contained in:
parent
dbb732b211
commit
dde36b38ea
8 changed files with 58 additions and 12 deletions
23
dist/restore/index.js
vendored
23
dist/restore/index.js
vendored
|
@ -4609,6 +4609,7 @@ var Inputs;
|
|||
var Outputs;
|
||||
(function (Outputs) {
|
||||
Outputs["CacheHit"] = "cache-hit";
|
||||
Outputs["CacheKey"] = "cache-key";
|
||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||
var State;
|
||||
(function (State) {
|
||||
|
@ -36343,8 +36344,9 @@ function isExactKeyMatch(key, cacheKey) {
|
|||
}) === 0);
|
||||
}
|
||||
exports.isExactKeyMatch = isExactKeyMatch;
|
||||
function setCacheState(state) {
|
||||
function setCacheState(state, key) {
|
||||
core.saveState(constants_1.State.CacheMatchedKey, state);
|
||||
core.setOutput(constants_1.Outputs.CacheKey, key);
|
||||
}
|
||||
exports.setCacheState = setCacheState;
|
||||
function setCacheHitOutput(isCacheHit) {
|
||||
|
@ -36354,7 +36356,7 @@ exports.setCacheHitOutput = setCacheHitOutput;
|
|||
function setOutputAndState(key, cacheKey) {
|
||||
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
|
||||
// Store the matched cache key if it exists
|
||||
cacheKey && setCacheState(cacheKey);
|
||||
cacheKey && setCacheState(cacheKey, key);
|
||||
}
|
||||
exports.setOutputAndState = setOutputAndState;
|
||||
function getCacheState() {
|
||||
|
@ -46748,7 +46750,22 @@ function run() {
|
|||
utils.setCacheState(cacheKey);
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
||||
utils.setCacheHitOutput(isExactKeyMatch);
|
||||
core.info(`Cache restored from key: ${cacheKey}`);
|
||||
let foundKey;
|
||||
if (isExactKeyMatch) {
|
||||
foundKey = primaryKey;
|
||||
core.info(`Cache restored for key: ${foundKey}`);
|
||||
}
|
||||
else {
|
||||
let i;
|
||||
for (i = 0; i < restoreKeys.length - 1; i++) {
|
||||
const fallbackCacheKey = yield cache.restoreCache(cachePaths, restoreKeys[i]);
|
||||
if (cacheKey) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
foundKey = restoreKeys[i];
|
||||
core.info(`Cache restored from key: ${foundKey}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
|
|
6
dist/save/index.js
vendored
6
dist/save/index.js
vendored
|
@ -4609,6 +4609,7 @@ var Inputs;
|
|||
var Outputs;
|
||||
(function (Outputs) {
|
||||
Outputs["CacheHit"] = "cache-hit";
|
||||
Outputs["CacheKey"] = "cache-key";
|
||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||
var State;
|
||||
(function (State) {
|
||||
|
@ -36343,8 +36344,9 @@ function isExactKeyMatch(key, cacheKey) {
|
|||
}) === 0);
|
||||
}
|
||||
exports.isExactKeyMatch = isExactKeyMatch;
|
||||
function setCacheState(state) {
|
||||
function setCacheState(state, key) {
|
||||
core.saveState(constants_1.State.CacheMatchedKey, state);
|
||||
core.setOutput(constants_1.Outputs.CacheKey, key);
|
||||
}
|
||||
exports.setCacheState = setCacheState;
|
||||
function setCacheHitOutput(isCacheHit) {
|
||||
|
@ -36354,7 +36356,7 @@ exports.setCacheHitOutput = setCacheHitOutput;
|
|||
function setOutputAndState(key, cacheKey) {
|
||||
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
|
||||
// Store the matched cache key if it exists
|
||||
cacheKey && setCacheState(cacheKey);
|
||||
cacheKey && setCacheState(cacheKey, key);
|
||||
}
|
||||
exports.setOutputAndState = setOutputAndState;
|
||||
function getCacheState() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue