Skip to content

Commit

Permalink
Add an action output for cache size
Browse files Browse the repository at this point in the history
  • Loading branch information
tvthatsme authored and jackieli-tes committed Jun 30, 2023
1 parent e46c9c5 commit 6064a1c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ inputs:
outputs:
cache-hit:
description: "A boolean value to indicate an exact match was found for the primary key"
cache-size:
description: "A integer value denoting the size of the cache object found (measured in bytes)"
runs:
using: node16
main: "dist/restore/index.js"
Expand Down
7 changes: 6 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6329,7 +6329,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
const utils = __importStar(__webpack_require__(15));
const core = __importStar(__webpack_require__(470));
const minio = __importStar(__webpack_require__(223));
Expand Down Expand Up @@ -6385,6 +6385,10 @@ function setCacheHitOutput(isCacheHit) {
core.setOutput("cache-hit", isCacheHit.toString());
}
exports.setCacheHitOutput = setCacheHitOutput;
function setCacheSizeOutput(cacheSize) {
core.setOutput("cache-size", cacheSize.toString());
}
exports.setCacheSizeOutput = setCacheSizeOutput;
function findObject(mc, bucket, key, restoreKeys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
core.debug("Key: " + JSON.stringify(key));
Expand Down Expand Up @@ -84143,6 +84147,7 @@ function restoreCache() {
core.info(`Cache Size: ${utils_1.formatSize(obj.size)} (${obj.size} bytes)`);
yield tar_1.extractTar(archivePath, compressionMethod);
utils_1.setCacheHitOutput(matchingKey === key);
utils_1.setCacheSizeOutput(obj.size);
core.info("Cache restored from s3 successfully");
}
catch (e) {
Expand Down
6 changes: 5 additions & 1 deletion dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6329,7 +6329,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
const utils = __importStar(__webpack_require__(15));
const core = __importStar(__webpack_require__(470));
const minio = __importStar(__webpack_require__(223));
Expand Down Expand Up @@ -6385,6 +6385,10 @@ function setCacheHitOutput(isCacheHit) {
core.setOutput("cache-hit", isCacheHit.toString());
}
exports.setCacheHitOutput = setCacheHitOutput;
function setCacheSizeOutput(cacheSize) {
core.setOutput("cache-size", cacheSize.toString());
}
exports.setCacheSizeOutput = setCacheSizeOutput;
function findObject(mc, bucket, key, restoreKeys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
core.debug("Key: " + JSON.stringify(key));
Expand Down
2 changes: 2 additions & 0 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isGhes,
newMinio,
setCacheHitOutput,
setCacheSizeOutput,
saveMatchedKey,
} from "./utils";

Expand Down Expand Up @@ -63,6 +64,7 @@ async function restoreCache() {

await extractTar(archivePath, compressionMethod);
setCacheHitOutput(matchingKey === key);
setCacheSizeOutput(obj.size)
core.info("Cache restored from s3 successfully");
} catch (e) {
core.info("Restore s3 cache failed: " + e.message);
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export function setCacheHitOutput(isCacheHit: boolean): void {
core.setOutput("cache-hit", isCacheHit.toString());
}

export function setCacheSizeOutput(cacheSize: number): void {
core.setOutput("cache-size", cacheSize.toString())
}

type FindObjectResult = {
item: minio.BucketItem;
matchingKey: string;
Expand Down

0 comments on commit 6064a1c

Please sign in to comment.