mirror of
https://github.com/actions/setup-python.git
synced 2025-12-20 15:27:09 +00:00
add first clean up work
Signed-off-by: jylenhof <jygithub@lenhof.eu.org>
This commit is contained in:
parent
97aeb3efb8
commit
b2cf62bdce
5 changed files with 50 additions and 6 deletions
18
src/clean-pip.ts
Normal file
18
src/clean-pip.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import * as core from '@actions/core';
|
||||
import {exec} from '@actions/exec';
|
||||
|
||||
// Shared helper to uninstall all pip packages in the current environment.
|
||||
export async function cleanPipPackages() {
|
||||
core.info('Cleaning up pip packages');
|
||||
try {
|
||||
// uninstall all currently installed packages (if any)
|
||||
// Use a shell so we can pipe the output of pip freeze into xargs
|
||||
await exec('bash', [
|
||||
'-c',
|
||||
'python -m pip freeze | xargs python -m pip uninstall'
|
||||
]);
|
||||
core.info('Successfully cleaned up pip packages');
|
||||
} catch (error) {
|
||||
core.setFailed(`Failed to clean up pip packages.`);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,34 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
import {cleanPipPackages} from './clean-pip';
|
||||
|
||||
import fs from 'fs';
|
||||
import {State} from './cache-distributions/cache-distributor';
|
||||
|
||||
// Added early exit to resolve issue with slow post action step:
|
||||
// - https://github.com/actions/setup-node/issues/878
|
||||
// https://github.com/actions/cache/pull/1217
|
||||
// See: https://github.com/actions/setup-node/issues/878
|
||||
// See: https://github.com/actions/cache/pull/1217
|
||||
export async function run(earlyExit?: boolean) {
|
||||
try {
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
await saveCache(cache);
|
||||
|
||||
// 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.
|
||||
if (earlyExit) {
|
||||
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.
|
||||
try {
|
||||
const postcleanPip = core.getBooleanInput('postclean-pip');
|
||||
if (postcleanPip) {
|
||||
await cleanPipPackages();
|
||||
}
|
||||
} catch (err) {
|
||||
// getBooleanInput throws if input missing in some contexts; ignore and continue
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
|
|
@ -84,4 +97,6 @@ function isCacheDirectoryExists(cacheDirectory: string[]) {
|
|||
return result;
|
||||
}
|
||||
|
||||
run(true);
|
||||
// Invoke the post action runner. No early-exit — this must complete so the cache
|
||||
// can be saved during the post step.
|
||||
run();
|
||||
|
|
@ -14,6 +14,7 @@ import {
|
|||
getVersionsInputFromPlainFile
|
||||
} from './utils';
|
||||
import {exec} from '@actions/exec';
|
||||
import {cleanPipPackages} from './clean-pip';
|
||||
|
||||
function isPyPyVersion(versionSpec: string) {
|
||||
return versionSpec.startsWith('pypy');
|
||||
|
|
@ -159,6 +160,10 @@ async function run() {
|
|||
if (cache && isCacheFeatureAvailable()) {
|
||||
await cacheDependencies(cache, pythonVersion);
|
||||
}
|
||||
const precleanPip = core.getBooleanInput('preclean-pip');
|
||||
if (precleanPip) {
|
||||
await cleanPipPackages();
|
||||
}
|
||||
const pipInstall = core.getInput('pip-install');
|
||||
if (pipInstall) {
|
||||
await installPipPackages(pipInstall);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue