cache: allow to skip state to send cache directly to gha

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-01-21 10:53:55 +01:00
parent 5bc1041760
commit 2ecc3150d2
2 changed files with 31 additions and 11 deletions

View File

@@ -55,7 +55,7 @@ export class Cache {
}
}
public async save(file: string): Promise<string> {
public async save(file: string, skipState?: boolean): Promise<string> {
core.debug(`Cache.save ${file}`);
const cachePath = this.copyToCache(file);
@@ -63,14 +63,19 @@ export class Cache {
core.debug(`Cache.save cached to hosted tool cache ${htcPath}`);
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
core.debug(`Cache.save sending ${this.ghaCacheKey} to post state`);
core.saveState(
Cache.POST_CACHE_KEY,
JSON.stringify({
dir: this.cacheDir,
key: this.ghaCacheKey
} as CachePostState)
);
if (skipState) {
core.debug(`Cache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
} else {
core.debug(`Cache.save sending ${this.ghaCacheKey} to post state`);
core.saveState(
Cache.POST_CACHE_KEY,
JSON.stringify({
dir: this.cacheDir,
key: this.ghaCacheKey
} as CachePostState)
);
}
}
return cachePath;