diff --git a/src/clean-pip.ts b/src/clean-pip.ts index fa0d6770..2e01ada0 100644 --- a/src/clean-pip.ts +++ b/src/clean-pip.ts @@ -13,6 +13,6 @@ export async function cleanPipPackages() { ]); core.info('Successfully cleaned up pip packages'); } catch (error) { - core.setFailed(`Failed to clean up pip packages.`); + core.setFailed('Failed to clean up pip packages.'); } } diff --git a/src/post-python.ts b/src/post-python.ts index 02600b66..1fb96556 100644 --- a/src/post-python.ts +++ b/src/post-python.ts @@ -11,8 +11,17 @@ import {State} from './cache-distributions/cache-distributor'; export async function run(earlyExit?: boolean) { try { const cache = core.getInput('cache'); - if (cache) { - await saveCache(cache); + // Optionally clean up pip packages after the post-action if requested. + // This mirrors the `preclean` behavior used in the main action. + const postcleanPip = core.getBooleanInput('postclean'); + + if (cache || postcleanPip) { + if (cache) { + await saveCache(cache); + } + if (postcleanPip) { + await cleanPipPackages(); + } // Preserve early-exit behavior for the post action when requested. // Some CI setups may want the post step to exit early to avoid long-running // processes during cleanup. If enabled, exit with success immediately. @@ -20,12 +29,6 @@ export async function run(earlyExit?: boolean) { process.exit(0); } } - // Optionally clean up pip packages after the post-action if requested. - // This mirrors the `preclean-pip` behavior used in the main action. - const postcleanPip = core.getBooleanInput('postclean'); - if (postcleanPip) { - await cleanPipPackages(); - } } catch (error) { const err = error as Error; core.setFailed(err.message);