mirror of
https://gitea.com/actions/cache.git
synced 2024-11-23 04:42:28 +08:00
Fixed inputs
This commit is contained in:
parent
61aa90bfc3
commit
d91f5bd2fd
17
dist/restore-only/index.js
vendored
17
dist/restore-only/index.js
vendored
|
@ -4950,12 +4950,13 @@ var Inputs;
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
|
Inputs["RestoredKey"] = "restored-key"; // Input from save action
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
Outputs["CacheHit"] = "cache-hit";
|
Outputs["CacheHit"] = "cache-hit";
|
||||||
Outputs["Key"] = "key";
|
Outputs["InputtedKey"] = "inputted-key";
|
||||||
Outputs["MatchedKey"] = "matched-key";
|
Outputs["MatchedKey"] = "matched-key"; // Output from restore action
|
||||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||||
var State;
|
var State;
|
||||||
(function (State) {
|
(function (State) {
|
||||||
|
@ -9360,7 +9361,7 @@ const constants_1 = __webpack_require__(196);
|
||||||
class StateProviderBase {
|
class StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
this.setState = (key, value) => { };
|
this.setState = (key, value, outputKey) => { };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -9384,7 +9385,11 @@ exports.StateProvider = StateProvider;
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.setOutput;
|
this.setState = (key, value, outputKey) => {
|
||||||
|
if (outputKey) {
|
||||||
|
core.setOutput(outputKey, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -50462,7 +50467,7 @@ function restoreImpl(stateProvider) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
||||||
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey);
|
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey, constants_1.Outputs.InputtedKey);
|
||||||
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
||||||
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
||||||
required: true
|
required: true
|
||||||
|
@ -50476,7 +50481,7 @@ function restoreImpl(stateProvider) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Store the matched cache key in states
|
// Store the matched cache key in states
|
||||||
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey);
|
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey, constants_1.Outputs.MatchedKey);
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
|
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
|
||||||
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
|
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
|
|
17
dist/restore/index.js
vendored
17
dist/restore/index.js
vendored
|
@ -4950,12 +4950,13 @@ var Inputs;
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
|
Inputs["RestoredKey"] = "restored-key"; // Input from save action
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
Outputs["CacheHit"] = "cache-hit";
|
Outputs["CacheHit"] = "cache-hit";
|
||||||
Outputs["Key"] = "key";
|
Outputs["InputtedKey"] = "inputted-key";
|
||||||
Outputs["MatchedKey"] = "matched-key";
|
Outputs["MatchedKey"] = "matched-key"; // Output from restore action
|
||||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||||
var State;
|
var State;
|
||||||
(function (State) {
|
(function (State) {
|
||||||
|
@ -9360,7 +9361,7 @@ const constants_1 = __webpack_require__(196);
|
||||||
class StateProviderBase {
|
class StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
this.setState = (key, value) => { };
|
this.setState = (key, value, outputKey) => { };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -9384,7 +9385,11 @@ exports.StateProvider = StateProvider;
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.setOutput;
|
this.setState = (key, value, outputKey) => {
|
||||||
|
if (outputKey) {
|
||||||
|
core.setOutput(outputKey, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -50462,7 +50467,7 @@ function restoreImpl(stateProvider) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
||||||
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey);
|
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey, constants_1.Outputs.InputtedKey);
|
||||||
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
||||||
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
||||||
required: true
|
required: true
|
||||||
|
@ -50476,7 +50481,7 @@ function restoreImpl(stateProvider) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Store the matched cache key in states
|
// Store the matched cache key in states
|
||||||
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey);
|
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey, constants_1.Outputs.MatchedKey);
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
|
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
|
||||||
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
|
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
|
|
25
dist/save-only/index.js
vendored
25
dist/save-only/index.js
vendored
|
@ -4979,12 +4979,13 @@ var Inputs;
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
|
Inputs["RestoredKey"] = "restored-key"; // Input from save action
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
Outputs["CacheHit"] = "cache-hit";
|
Outputs["CacheHit"] = "cache-hit";
|
||||||
Outputs["Key"] = "key";
|
Outputs["InputtedKey"] = "inputted-key";
|
||||||
Outputs["MatchedKey"] = "matched-key";
|
Outputs["MatchedKey"] = "matched-key"; // Output from restore action
|
||||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||||
var State;
|
var State;
|
||||||
(function (State) {
|
(function (State) {
|
||||||
|
@ -9389,7 +9390,7 @@ const constants_1 = __webpack_require__(196);
|
||||||
class StateProviderBase {
|
class StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
this.setState = (key, value) => { };
|
this.setState = (key, value, outputKey) => { };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -9413,7 +9414,11 @@ exports.StateProvider = StateProvider;
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.setOutput;
|
this.setState = (key, value, outputKey) => {
|
||||||
|
if (outputKey) {
|
||||||
|
core.setOutput(outputKey, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -41075,6 +41080,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const cache = __importStar(__webpack_require__(692));
|
const cache = __importStar(__webpack_require__(692));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const constants_1 = __webpack_require__(196);
|
const constants_1 = __webpack_require__(196);
|
||||||
|
const stateProvider_1 = __webpack_require__(309);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
||||||
|
@ -41095,13 +41101,18 @@ function saveImpl(stateProvider) {
|
||||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
||||||
core.getInput(constants_1.Inputs.Key);
|
core.getInput(constants_1.Inputs.Key);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
if (stateProvider instanceof stateProvider_1.StateProvider) {
|
||||||
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
utils.logWarning(`Error retrieving key from input.`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If matched restore key is same as primary key, then do not save cache
|
// If matched restore key is same as primary key, then do not save cache
|
||||||
// NO-OP in case of SaveOnly action
|
// NO-OP in case of SaveOnly action
|
||||||
const state = stateProvider.getCacheState();
|
const restoredKey = stateProvider.getCacheState() || core.getInput(constants_1.Inputs.RestoredKey);
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
25
dist/save/index.js
vendored
25
dist/save/index.js
vendored
|
@ -4950,12 +4950,13 @@ var Inputs;
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
Inputs["UploadChunkSize"] = "upload-chunk-size";
|
||||||
|
Inputs["RestoredKey"] = "restored-key"; // Input from save action
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
Outputs["CacheHit"] = "cache-hit";
|
Outputs["CacheHit"] = "cache-hit";
|
||||||
Outputs["Key"] = "key";
|
Outputs["InputtedKey"] = "inputted-key";
|
||||||
Outputs["MatchedKey"] = "matched-key";
|
Outputs["MatchedKey"] = "matched-key"; // Output from restore action
|
||||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||||
var State;
|
var State;
|
||||||
(function (State) {
|
(function (State) {
|
||||||
|
@ -9360,7 +9361,7 @@ const constants_1 = __webpack_require__(196);
|
||||||
class StateProviderBase {
|
class StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
this.setState = (key, value) => { };
|
this.setState = (key, value, outputKey) => { };
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -9384,7 +9385,11 @@ exports.StateProvider = StateProvider;
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.setOutput;
|
this.setState = (key, value, outputKey) => {
|
||||||
|
if (outputKey) {
|
||||||
|
core.setOutput(outputKey, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
@ -41046,6 +41051,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const cache = __importStar(__webpack_require__(692));
|
const cache = __importStar(__webpack_require__(692));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const constants_1 = __webpack_require__(196);
|
const constants_1 = __webpack_require__(196);
|
||||||
|
const stateProvider_1 = __webpack_require__(309);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
||||||
|
@ -41066,13 +41072,18 @@ function saveImpl(stateProvider) {
|
||||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
||||||
core.getInput(constants_1.Inputs.Key);
|
core.getInput(constants_1.Inputs.Key);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
if (stateProvider instanceof stateProvider_1.StateProvider) {
|
||||||
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
utils.logWarning(`Error retrieving key from input.`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If matched restore key is same as primary key, then do not save cache
|
// If matched restore key is same as primary key, then do not save cache
|
||||||
// NO-OP in case of SaveOnly action
|
// NO-OP in case of SaveOnly action
|
||||||
const state = stateProvider.getCacheState();
|
const restoredKey = stateProvider.getCacheState() || core.getInput(constants_1.Inputs.RestoredKey);
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ inputs:
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||||
key:
|
inputted-key:
|
||||||
description: 'Key passed in the input to use in subsequent steps of the workflow'
|
description: 'Key passed in the input to use in subsequent steps of the workflow'
|
||||||
matched-key:
|
matched-key:
|
||||||
description: 'Cache key restored'
|
description: 'Cache key restored'
|
||||||
|
|
|
@ -11,7 +11,7 @@ inputs:
|
||||||
upload-chunk-size:
|
upload-chunk-size:
|
||||||
description: 'The chunk size used to split up large files during upload, in bytes'
|
description: 'The chunk size used to split up large files during upload, in bytes'
|
||||||
required: false
|
required: false
|
||||||
matched-key:
|
restored-key:
|
||||||
description: 'Cache key restored from the restore action'
|
description: 'Cache key restored from the restore action'
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Key = "key",
|
Key = "key", // Input from cache, restore, save action
|
||||||
Path = "path",
|
Path = "path", // Input from cache, restore, save action
|
||||||
RestoreKeys = "restore-keys",
|
RestoreKeys = "restore-keys", // Input from cache, restore action
|
||||||
UploadChunkSize = "upload-chunk-size"
|
UploadChunkSize = "upload-chunk-size", // Input from cache, save action
|
||||||
|
RestoredKey = "restored-key" // Input from save action
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
CacheHit = "cache-hit",
|
CacheHit = "cache-hit", // Output from cache, restore action
|
||||||
Key = "key",
|
InputtedKey = "inputted-key", // Output from restore action
|
||||||
MatchedKey = "matched-key"
|
MatchedKey = "matched-key" // Output from restore action
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum State {
|
export enum State {
|
||||||
|
|
|
@ -25,7 +25,11 @@ async function restoreImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||||
stateProvider.setState(State.CachePrimaryKey, primaryKey);
|
stateProvider.setState(
|
||||||
|
State.CachePrimaryKey,
|
||||||
|
primaryKey,
|
||||||
|
Outputs.InputtedKey
|
||||||
|
);
|
||||||
|
|
||||||
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
||||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||||
|
@ -50,7 +54,11 @@ async function restoreImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the matched cache key in states
|
// Store the matched cache key in states
|
||||||
stateProvider.setState(State.CacheMatchedKey, cacheKey);
|
stateProvider.setState(
|
||||||
|
State.CacheMatchedKey,
|
||||||
|
cacheKey,
|
||||||
|
Outputs.MatchedKey
|
||||||
|
);
|
||||||
|
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||||
core.getInput(Inputs.Key, { required: true }),
|
core.getInput(Inputs.Key, { required: true }),
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
import { Events, Inputs, State } from "./constants";
|
import { Events, Inputs, State } from "./constants";
|
||||||
import { IStateProvider } from "./stateProvider";
|
import { IStateProvider, StateProvider } from "./stateProvider";
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
|
@ -32,14 +32,20 @@ async function saveImpl(stateProvider: IStateProvider): Promise<void> {
|
||||||
core.getInput(Inputs.Key);
|
core.getInput(Inputs.Key);
|
||||||
|
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
if (stateProvider instanceof StateProvider) {
|
||||||
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
|
} else {
|
||||||
|
utils.logWarning(`Error retrieving key from input.`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If matched restore key is same as primary key, then do not save cache
|
// If matched restore key is same as primary key, then do not save cache
|
||||||
// NO-OP in case of SaveOnly action
|
// NO-OP in case of SaveOnly action
|
||||||
const state = stateProvider.getCacheState();
|
const restoredKey =
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
stateProvider.getCacheState() || core.getInput(Inputs.RestoredKey);
|
||||||
|
|
||||||
|
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
||||||
core.info(
|
core.info(
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as core from "@actions/core";
|
||||||
import { State } from "./constants";
|
import { State } from "./constants";
|
||||||
|
|
||||||
export interface IStateProvider {
|
export interface IStateProvider {
|
||||||
setState(key: string, value: string): void;
|
setState(key: string, value: string, outputKey?: string): void;
|
||||||
getState(key: string): string;
|
getState(key: string): string;
|
||||||
|
|
||||||
getCacheState(): string | undefined;
|
getCacheState(): string | undefined;
|
||||||
|
@ -21,7 +21,7 @@ class StateProviderBase implements IStateProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
||||||
setState = (key: string, value: string) => {};
|
setState = (key: string, value: string, outputKey?: string) => {};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
getState = (key: string) => "";
|
getState = (key: string) => "";
|
||||||
|
@ -33,7 +33,11 @@ export class StateProvider extends StateProviderBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NullStateProvider extends StateProviderBase {
|
export class NullStateProvider extends StateProviderBase {
|
||||||
setState = core.setOutput;
|
setState = (key: string, value: string, outputKey?: string) => {
|
||||||
|
if (outputKey) {
|
||||||
|
core.setOutput(outputKey, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
getState = (key: string) => "";
|
getState = (key: string) => "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user