Add support for pip-version (#1129)

* Add pip-version input

* Update workflow files

* Add documentation

* Update workflow files
This commit is contained in:
Priya Gupta 2025-06-20 08:39:35 +05:30 committed by GitHub
parent 5fa0ee6f38
commit e9c40fbc2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 179 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import * as installer from './install-python';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec';
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
@ -30,6 +31,27 @@ function binDir(installDir: string): string {
}
}
async function installPip(pythonLocation: string) {
const pipVersion = core.getInput('pip-version');
// Validate pip-version format: major[.minor][.patch]
const versionRegex = /^\d+(\.\d+)?(\.\d+)?$/;
if (pipVersion && !versionRegex.test(pipVersion)) {
throw new Error(
`Invalid pip-version "${pipVersion}". Please specify a version in the format major[.minor][.patch].`
);
}
if (pipVersion) {
core.info(
`pip-version input is specified. Installing pip version ${pipVersion}`
);
await exec.exec(
`${pythonLocation}/python -m pip install --upgrade pip==${pipVersion} --disable-pip-version-check --no-warn-script-location`
);
}
}
export async function useCpythonVersion(
version: string,
architecture: string,
@ -179,6 +201,9 @@ export async function useCpythonVersion(
core.setOutput('python-version', pythonVersion);
core.setOutput('python-path', pythonPath);
const binaryPath = IS_WINDOWS ? installDir : _binDir;
await installPip(binaryPath);
return {impl: 'CPython', version: pythonVersion};
}