mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-22 19:06:09 +08:00
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:
parent
9282d3e13b
commit
738db5298d
@ -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;
|
||||
|
20
src/index.ts
20
src/index.ts
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user