diff --git a/src/restore/index.ts b/src/restore/index.ts index 4c810ba..5180cba 100644 --- a/src/restore/index.ts +++ b/src/restore/index.ts @@ -9,6 +9,23 @@ import { } from '../utils/cache' async function run(): Promise { + try { + /* + clean up caches + */ + const cacheBase = core.getState('cache-base') + const cleanKey = core.getInput('clean-key') + const CLEAN_TIME = 7 + + if (cleanKey) { + await exec( + `/bin/bash -c "find ${cacheBase} -maxdepth 1 -name '${cleanKey}*' -type d -atime +${CLEAN_TIME} -exec rm -rf {} +"` + ) + } + } catch (error) { + if (error instanceof Error) core.warning(error.message) + } + try { const key = core.getInput('key') const base = core.getInput('base') diff --git a/src/save/index.ts b/src/save/index.ts index dfecec0..506edea 100644 --- a/src/save/index.ts +++ b/src/save/index.ts @@ -21,21 +21,9 @@ async function run(): Promise { core.info(`,not saving cache`) } - /* - clean up caches - */ - const cacheBase = core.getState('cache-base') - const cleanKey = core.getInput('clean-key') - const CLEAN_TIME = 7 - - if (cleanKey) { - await exec( - `/bin/bash -c "find ${cacheBase} -maxdepth 1 -name '${cleanKey}*' -type d -atime +${CLEAN_TIME} -exec rm -rf {} +"` - ) - } } catch (error) { if (error instanceof Error) core.setFailed(error.message) } } -run() +run() \ No newline at end of file