Skip to content

Commit

Permalink
proof of concept: move saveCache to the post-action phase
Browse files Browse the repository at this point in the history
i mocked this up while investigating
docker/setup-buildx-action#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 <[email protected]>
  • Loading branch information
nicks committed Jan 30, 2024
1 parent 9282d3e commit 3532767
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/buildx/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as core from '@actions/core';
import * as cache from '@actions/cache';

const isPost = !!process.env['STATE_isPost'];
if (!isPost) {
Expand All @@ -36,7 +37,18 @@ 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) {}
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);
}
}
}

0 comments on commit 3532767

Please sign in to comment.