proof of concept: move saveCache to the post-action phase

i mocked this up while investigating
https://github.com/docker/setup-buildx-action/issues/293

i guess this is SLIGHTLY better in that it makes the 2 minutes pause
that i'm seeing happen AFTER tests, but the pause is still there.

Signed-off-by: Nick Santos <nick.santos@docker.com>
This commit is contained in:
Nick Santos 2024-01-30 17:13:47 -05:00
parent 9282d3e13b
commit 738db5298d
No known key found for this signature in database
GPG Key ID: 4339957B1E99CE1F
2 changed files with 20 additions and 4 deletions

View File

@ -330,8 +330,8 @@ class InstallCache {
core.debug(`InstallCache.save cached to hosted tool cache ${htcPath}`);
if (cache.isFeatureAvailable()) {
core.debug(`InstallCache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
core.debug(`InstallCache.save sending ${this.ghaCacheKey} to cache in post-action`);
core.saveState('post-save-cache', JSON.stringify({dir: this.cacheDir, key: this.ghaCacheKey}));
}
return cachePath;

View File

@ -15,6 +15,7 @@
*/
import * as core from '@actions/core';
import * as cache from '@actions/cache';
const isPost = !!process.env['STATE_isPost'];
if (!isPost) {
@ -36,7 +37,22 @@ export async function run(main: () => Promise<void>, post?: () => Promise<void>)
} catch (e) {
core.setFailed(e.message);
}
} else if (post) {
await post();
} else {
if (post) {
await post();
}
// Post-step, cache any created files.
let cacheObj = {dir: '', key: ''};
try {
cacheObj = JSON.parse(core.getState('post-save-cache'));
} catch (e) {
// do nothing
}
if (cacheObj && cacheObj.dir && cacheObj.key) {
core.info(`Cache dir: ${cacheObj.dir}`);
core.info(`Cache with the key: ${cacheObj.key}`);
await cache.saveCache([cacheObj.dir], cacheObj.key);
}
}
}