From 738db5298d89078a0a69a3f63badcec7d4018cf4 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Tue, 30 Jan 2024 17:13:47 -0500 Subject: [PATCH] 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 --- src/buildx/install.ts | 4 ++-- src/index.ts | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/buildx/install.ts b/src/buildx/install.ts index e359e1a..88e891e 100644 --- a/src/buildx/install.ts +++ b/src/buildx/install.ts @@ -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; diff --git a/src/index.ts b/src/index.ts index 8d02199..da4122f 100644 --- a/src/index.ts +++ b/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, post?: () => Promise) } 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); + } } }