Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ To check if cache hits and size is not zero without downloading:
`restore-keys` works similar to how github's `@actions/cache@v2` works: It search each item in `restore-keys`
as prefix in object names and use the latest one

To restore from the cache using a `restore-key` prefix if the `key` restore fails:

```yaml
- uses: tespkg/actions-cache/restore@v1
with:
accessKey: "Q3AM3UQ867SPQQA43P2F" # required
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" # required
bucket: actions-cache # required
# actions/cache compatible properties: https://github.com/actions/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-
path: |
node_modules
```

If a match is found using one of the `restore-keys` options, then `cache-hit` will be FALSE but the
`cache-matched-key` output will be set to the key that matched. See the
[actions/cache](https://github.com/actions/cache/blob/main/restore/README.md#outputs) notes.

## Amazon S3 permissions

When using this with Amazon S3, the following permissions are necessary:
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ outputs:
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)"
cache-matched-key:
description: "The key of the cache object found, if any"
runs:
using: node20
main: "dist/restore/index.js"
Expand Down
8 changes: 7 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109661,6 +109661,7 @@ function restoreCache() {
const cacheHit = matchingKey === key;
(0, utils_1.setCacheHitOutput)(cacheHit);
(0, utils_1.setCacheSizeOutput)(obj.size);
(0, utils_1.setCacheMatchedKeyOutput)(matchingKey);
if (lookupOnly) {
if (cacheHit && obj.size > 0) {
core.info(`Cache Hit. NOT Downloading cache from s3 because lookup-only is set. bucket: ${bucket}, object: ${obj.name}`);
Expand Down Expand Up @@ -109692,6 +109693,7 @@ function restoreCache() {
const fallbackMatchingKey = yield cache.restoreCache(paths, key, restoreKeys);
if (fallbackMatchingKey) {
(0, utils_1.setCacheHitOutput)(fallbackMatchingKey === key);
(0, utils_1.setCacheMatchedKeyOutput)(fallbackMatchingKey);
core.info("Fallback cache restored successfully");
}
else {
Expand Down Expand Up @@ -109772,7 +109774,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheMatchedKeyOutput = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
Expand Down Expand Up @@ -109846,6 +109848,10 @@ function setCacheSizeOutput(cacheSize) {
core.setOutput("cache-size", cacheSize.toString());
}
exports.setCacheSizeOutput = setCacheSizeOutput;
function setCacheMatchedKeyOutput(cacheMatchedKey) {
core.setOutput("cache-matched-key", cacheMatchedKey);
}
exports.setCacheMatchedKeyOutput = setCacheMatchedKeyOutput;
function findObject(mc, bucket, key, restoreKeys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
core.debug("Key: " + JSON.stringify(key));
Expand Down
6 changes: 5 additions & 1 deletion dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109687,7 +109687,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheMatchedKeyOutput = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
Expand Down Expand Up @@ -109761,6 +109761,10 @@ function setCacheSizeOutput(cacheSize) {
core.setOutput("cache-size", cacheSize.toString());
}
exports.setCacheSizeOutput = setCacheSizeOutput;
function setCacheMatchedKeyOutput(cacheMatchedKey) {
core.setOutput("cache-matched-key", cacheMatchedKey);
}
exports.setCacheMatchedKeyOutput = setCacheMatchedKeyOutput;
function findObject(mc, bucket, key, restoreKeys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
core.debug("Key: " + JSON.stringify(key));
Expand Down
6 changes: 5 additions & 1 deletion dist/saveOnly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109687,7 +109687,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheMatchedKeyOutput = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
Expand Down Expand Up @@ -109761,6 +109761,10 @@ function setCacheSizeOutput(cacheSize) {
core.setOutput("cache-size", cacheSize.toString());
}
exports.setCacheSizeOutput = setCacheSizeOutput;
function setCacheMatchedKeyOutput(cacheMatchedKey) {
core.setOutput("cache-matched-key", cacheMatchedKey);
}
exports.setCacheMatchedKeyOutput = setCacheMatchedKeyOutput;
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 restore/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ outputs:
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)"
cache-matched-key:
description: "The key of the cache object found, if any"
runs:
using: node20
main: "../dist/restore/index.js"
Expand Down
3 changes: 3 additions & 0 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
newMinio,
setCacheHitOutput,
setCacheSizeOutput,
setCacheMatchedKeyOutput,
saveMatchedKey,
getInput,
} from "./utils";
Expand Down Expand Up @@ -66,6 +67,7 @@ async function restoreCache() {
const cacheHit = matchingKey === key;
setCacheHitOutput(cacheHit);
setCacheSizeOutput(obj.size);
setCacheMatchedKeyOutput(matchingKey);
if (lookupOnly) {
if (cacheHit && obj.size > 0) {
core.info(
Expand Down Expand Up @@ -106,6 +108,7 @@ async function restoreCache() {
);
if (fallbackMatchingKey) {
setCacheHitOutput(fallbackMatchingKey === key);
setCacheMatchedKeyOutput(fallbackMatchingKey);
core.info("Fallback cache restored successfully");
} else {
core.info("Fallback cache restore failed");
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export function setCacheSizeOutput(cacheSize: number): void {
core.setOutput("cache-size", cacheSize.toString())
}

export function setCacheMatchedKeyOutput(cacheMatchedKey: string): void {
core.setOutput("cache-matched-key", cacheMatchedKey)
}

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