Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source_up
use node v16
use node v24
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: "20.x"
node-version: "24.x"
- name: Install Yarn
run: npm install -g yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
- uses: actions/cache@v5
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lookup-only.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Lookup cache
id: lookup
uses: ./
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Restore cache
uses: ./
env:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Restore cache
uses: ./
with:
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Restore cache
uses: ./
with:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Restore cache
uses: ./restore/
with:
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This action enables caching dependencies to s3 compatible storage, e.g. minio, AWS S3

It also has github [actions/cache@v2](https://github.com/actions/cache) fallback if s3 save & restore fails
It also has github [actions/cache@v5](https://github.com/actions/cache) fallback if s3 save & restore fails

## Usage

Expand Down Expand Up @@ -113,9 +113,30 @@ To check if cache hits and size is not zero without downloading:

## Restore keys

`restore-keys` works similar to how github's `@actions/cache@v2` works: It search each item in `restore-keys`
`restore-keys` works similar to how github's `@actions/cache@v5` 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
6 changes: 4 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "s3 cache"
author: tespkg
description: "S3 actions cache with actions/cache@v2 passthrough"
description: "S3 actions cache with actions/cache@v5 passthrough"
inputs:
endpoint:
description: "s3 / minio endpoint, see: https://docs.min.io/docs/javascript-client-api-reference.html"
Expand Down Expand Up @@ -57,8 +57,10 @@ 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
using: node24
main: "dist/restore/index.js"
post: "dist/save/index.js"
post-if: "success()"
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
6 changes: 4 additions & 2 deletions restore/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "s3 cache"
author: tespkg
description: "S3 actions cache with actions/cache@v2 passthrough"
description: "S3 actions cache with actions/cache@v5 passthrough"
inputs:
endpoint:
description: "s3 / minio endpoint, see: https://docs.min.io/docs/javascript-client-api-reference.html"
Expand Down Expand Up @@ -57,8 +57,10 @@ 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
using: node24
main: "../dist/restore/index.js"
branding:
icon: "archive"
Expand Down
4 changes: 2 additions & 2 deletions save/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "s3 cache"
author: tespkg
description: "S3 actions cache with actions/cache@v2 passthrough"
description: "S3 actions cache with actions/cache@v5 passthrough"
inputs:
endpoint:
description: "s3 / minio endpoint, see: https://docs.min.io/docs/javascript-client-api-reference.html"
Expand Down Expand Up @@ -46,7 +46,7 @@ inputs:
# required: false
# default: -n
runs:
using: node20
using: node24
main: "../dist/saveOnly/index.js"
branding:
icon: "archive"
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