Skip to content

Commit 2c59ebd

Browse files
committed
Add configurable compression support
1 parent fd0dc93 commit 2c59ebd

9 files changed

Lines changed: 218 additions & 69 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Local file caching for self-hosted GitHub Actions runners. Made specifically for
55
- [x] Relative, absolute, and tilde path support.
66
- [x] Multiple path caching support – cache several related paths in one step.
77
- [x] Default cache location via `SELF_CACHED_DIR` environment variable.
8-
- [ ] Configurable cache compression for fine-tuning the performance.
8+
- [x] Configurable cache compression for fine-tuning the performance.
99
- [ ] Glob support – not sure how it would work, but sounds useful…
1010

1111
## 💡 Usage

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
dir:
1111
description: A directory path for storing (to) and restoring (from) the cache. Defaults to $SELF_CACHED_DIR or $RUNNER_TOOL_CACHE if not set.
1212
required: false
13+
compress:
14+
description: Specifies whether to compress cache using tar. Defaults to $SELF_CACHED_COMPRESS or true if not set.
15+
required: false
1316
outputs:
1417
cache-hit:
1518
description: Specifies whether the cache was restored or not.

product/dist/Restore.js

Lines changed: 44 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

product/dist/Store.js

Lines changed: 43 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/Restore.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as core from '@actions/core';
2-
import { getDirInput, Input, Output, restore, State } from './Util';
2+
import { getCompressInput, getDirInput, Input, Output, restore, State } from './Util';
33

44
(async (): Promise<void> => {
55
try {
66
const paths = core.getInput(Input.Path, { required: true }).split(/\r?\n/).map(p => p.trim()).filter(p => p.length > 0);
77
const key = core.getInput(Input.Key, { required: true });
88
const dir = getDirInput(core.getInput(Input.Dir, { required: false }));
9+
const compress = getCompressInput(core.getInput(Input.Compress, { required: false }));
910

1011
if (!paths.length || !key || !dir) {
1112
core.info('Missing inputs, skipping cache restore.');
@@ -16,8 +17,9 @@ import { getDirInput, Input, Output, restore, State } from './Util';
1617
core.saveState(State.CacheKey, key);
1718
core.saveState(State.CacheDir, dir);
1819
core.saveState(State.CachePaths, JSON.stringify(paths));
20+
core.saveState(State.CacheCompress, compress.toString());
1921

20-
const isRestored = await restore(paths, key, dir);
22+
const isRestored = await restore(paths, key, dir, compress);
2123
core.setOutput(Output.CacheHit, isRestored.toString());
2224

2325
if (isRestored) {

source/Store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { State, store } from './Util';
66
const paths = JSON.parse(core.getState(State.CachePaths) || '[]');
77
const key = core.getState(State.CacheKey);
88
const dir = core.getState(State.CacheDir);
9+
const compress = core.getState(State.CacheCompress) === 'true';
910

1011
if (!paths.length || !key || !dir) {
1112
core.info('Missing state inputs, skipping cache store.');
1213
return;
1314
}
1415

15-
await store(paths, key, dir);
16+
await store(paths, key, dir, compress);
1617
} catch (error) {
1718
core.setFailed(error instanceof Error ? error.message : `Unknown error occurred during restore: ${error}`);
1819
}

0 commit comments

Comments
 (0)