Add support for pip-install input (#1201)

* Add pip-install input

* Improve error message

* Logic update

---------

Co-authored-by: “gowridurgad” <“hgowridurgad@github.com>
This commit is contained in:
gowridurgad
2025-09-26 08:31:19 +05:30
committed by GitHub
parent 4267e283df
commit 2e3e4b15a8
7 changed files with 163 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import {
getVersionInputFromFile,
getVersionsInputFromPlainFile
} from './utils';
import {exec} from '@actions/exec';
function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith('pypy');
@ -22,6 +23,19 @@ function isGraalPyVersion(versionSpec: string) {
return versionSpec.startsWith('graalpy');
}
async function installPipPackages(pipInstall: string) {
core.info(`Installing pip packages: ${pipInstall}`);
try {
const installArgs = pipInstall.trim().split(/\s+/);
await exec('python', ['-m', 'pip', 'install', ...installArgs]);
core.info('Successfully installed pip packages');
} catch (error) {
core.setFailed(
`Failed to install pip packages from "${pipInstall}". Please verify that the package names, versions, or requirements files provided are correct and installable, that the specified packages and versions can be resolved from PyPI or the configured package index, and that your network connection is stable and allows access to the package index.`
);
}
}
async function cacheDependencies(cache: string, pythonVersion: string) {
const cacheDependencyPath =
core.getInput('cache-dependency-path') || undefined;
@ -145,6 +159,10 @@ async function run() {
if (cache && isCacheFeatureAvailable()) {
await cacheDependencies(cache, pythonVersion);
}
const pipInstall = core.getInput('pip-install');
if (pipInstall) {
await installPipPackages(pipInstall);
}
} else {
core.warning(
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'