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); + } } }