Skip to content

Commit d2e3f41

Browse files
authored
Set output cache-hit to indicate if cache was hit (#275)
1 parent 0aa6f2a commit d2e3f41

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ The action has a built-in functionality for caching and restoring dependencies.
7070
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`
7171
- maven: `**/pom.xml`
7272

73+
The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).
74+
7375
The cache input is optional, and caching is turned off by default.
7476

7577
#### Caching gradle dependencies

dist/cleanup/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61925,9 +61925,11 @@ function restore(id) {
6192561925
]);
6192661926
if (matchedKey) {
6192761927
core.saveState(CACHE_MATCHED_KEY, matchedKey);
61928+
core.setOutput('cache-hit', matchedKey === primaryKey);
6192861929
core.info(`Cache restored from key: ${matchedKey}`);
6192961930
}
6193061931
else {
61932+
core.setOutput('cache-hit', false);
6193161933
core.info(`${packageManager.id} cache is not found`);
6193261934
}
6193361935
});

dist/setup/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18662,9 +18662,11 @@ function restore(id) {
1866218662
]);
1866318663
if (matchedKey) {
1866418664
core.saveState(CACHE_MATCHED_KEY, matchedKey);
18665+
core.setOutput('cache-hit', matchedKey === primaryKey);
1866518666
core.info(`Cache restored from key: ${matchedKey}`);
1866618667
}
1866718668
else {
18669+
core.setOutput('cache-hit', false);
1866818670
core.info(`${packageManager.id} cache is not found`);
1866918671
}
1867018672
});

src/cache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export async function restore(id: string) {
7777
]);
7878
if (matchedKey) {
7979
core.saveState(CACHE_MATCHED_KEY, matchedKey);
80+
core.setOutput('cache-hit', matchedKey === primaryKey);
8081
core.info(`Cache restored from key: ${matchedKey}`);
8182
} else {
83+
core.setOutput('cache-hit', false);
8284
core.info(`${packageManager.id} cache is not found`);
8385
}
8486
}

0 commit comments

Comments
 (0)