Skip to content

Commit 9bfc313

Browse files
author
“gowridurgad”
committed
Add pip-install input
1 parent e797f83 commit 9bfc313

File tree

7 files changed

+167
-0
lines changed

7 files changed

+167
-0
lines changed

.github/workflows/e2e-cache-freethreaded.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,56 @@ jobs:
219219
pip-version: '25.0.1'
220220
- name: Install dependencies
221221
run: pip install numpy pandas requests
222+
223+
python-pip-dependencies-caching-with-pip-install:
224+
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
225+
runs-on: ${{ matrix.os }}
226+
strategy:
227+
fail-fast: false
228+
matrix:
229+
os:
230+
[
231+
ubuntu-latest,
232+
ubuntu-22.04,
233+
ubuntu-24.04-arm,
234+
ubuntu-22.04-arm,
235+
windows-latest,
236+
macos-latest,
237+
macos-13
238+
]
239+
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
240+
steps:
241+
- uses: actions/checkout@v4
242+
- name: Setup Python
243+
uses: ./
244+
with:
245+
python-version: ${{ matrix.python-version }}
246+
cache: 'pip'
247+
pip-install: numpy pandas requests
248+
249+
python-pip-dependencies-caching-path-with-pip-install:
250+
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}, caching path)
251+
runs-on: ${{ matrix.os }}
252+
strategy:
253+
fail-fast: false
254+
matrix:
255+
os:
256+
[
257+
ubuntu-latest,
258+
ubuntu-22.04,
259+
ubuntu-24.04-arm,
260+
ubuntu-22.04-arm,
261+
windows-latest,
262+
macos-latest,
263+
macos-13
264+
]
265+
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
266+
steps:
267+
- uses: actions/checkout@v4
268+
- name: Setup Python
269+
uses: ./
270+
with:
271+
python-version: ${{ matrix.python-version }}
272+
cache: 'pip'
273+
cache-dependency-path: __tests__/data/requirements.txt
274+
pip-install: numpy pandas requests

.github/workflows/e2e-cache.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,56 @@ jobs:
306306
pip-version: '25.0.1'
307307
- name: Install dependencies
308308
run: pip install numpy pandas requests
309+
310+
python-pip-dependencies-caching-with-pip-install:
311+
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
312+
runs-on: ${{ matrix.os }}
313+
strategy:
314+
fail-fast: false
315+
matrix:
316+
os:
317+
[
318+
ubuntu-latest,
319+
ubuntu-24.04-arm,
320+
ubuntu-22.04,
321+
ubuntu-22.04-arm,
322+
windows-latest,
323+
macos-latest,
324+
macos-13
325+
]
326+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
327+
steps:
328+
- uses: actions/checkout@v4
329+
- name: Setup Python
330+
uses: ./
331+
with:
332+
python-version: ${{ matrix.python-version }}
333+
cache: 'pip'
334+
pip-install: numpy pandas requests
335+
336+
python-pip-dependencies-caching-path-with-pip-install:
337+
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}, caching path)
338+
runs-on: ${{ matrix.os }}
339+
strategy:
340+
fail-fast: false
341+
matrix:
342+
os:
343+
[
344+
ubuntu-latest,
345+
ubuntu-24.04-arm,
346+
ubuntu-22.04,
347+
ubuntu-22.04-arm,
348+
windows-latest,
349+
macos-latest,
350+
macos-13
351+
]
352+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
353+
steps:
354+
- uses: actions/checkout@v4
355+
- name: Setup Python
356+
uses: ./
357+
with:
358+
python-version: ${{ matrix.python-version }}
359+
cache: 'pip'
360+
cache-dependency-path: __tests__/data/requirements.txt
361+
pip-install: numpy pandas requests

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poet
111111
- [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes)
112112
- [Allow pre-releases](docs/advanced-usage.md#allow-pre-releases)
113113
- [Using the pip-version input](docs/advanced-usage.md#using-the-pip-version-input)
114+
- [Using the pip-install input](docs/advanced-usage.md#using-the-pip-install-input)
114115

115116
## Recommended permissions
116117

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ inputs:
3131
default: false
3232
pip-version:
3333
description: "Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]."
34+
pip-install:
35+
description: "Used to specify the packages to install with pip after setting up Python. Can be a requirements file or package names."
3436
outputs:
3537
python-version:
3638
description: "The installed Python or PyPy version. Useful when given a version range as input."

dist/setup/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97944,12 +97944,30 @@ const os = __importStar(__nccwpck_require__(857));
9794497944
const fs_1 = __importDefault(__nccwpck_require__(9896));
9794597945
const cache_factory_1 = __nccwpck_require__(665);
9794697946
const utils_1 = __nccwpck_require__(1798);
97947+
const exec_1 = __nccwpck_require__(5236);
9794797948
function isPyPyVersion(versionSpec) {
9794897949
return versionSpec.startsWith('pypy');
9794997950
}
9795097951
function isGraalPyVersion(versionSpec) {
9795197952
return versionSpec.startsWith('graalpy');
9795297953
}
97954+
function installPipPackages() {
97955+
return __awaiter(this, void 0, void 0, function* () {
97956+
const pipInstall = core.getInput('pip-install');
97957+
if (!pipInstall) {
97958+
return;
97959+
}
97960+
core.info(`Installing pip packages: ${pipInstall}`);
97961+
try {
97962+
const installArgs = pipInstall.trim().split(/\s+/);
97963+
yield (0, exec_1.exec)('python', ['-m', 'pip', 'install', ...installArgs]);
97964+
core.info('Successfully installed pip packages');
97965+
}
97966+
catch (error) {
97967+
core.setFailed(`Failed to install pip packages from "${pipInstall}". Please verify that the package names and versions in the requirements file are correct, 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.`);
97968+
}
97969+
});
97970+
}
9795397971
function cacheDependencies(cache, pythonVersion) {
9795497972
return __awaiter(this, void 0, void 0, function* () {
9795597973
const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined;
@@ -98038,6 +98056,7 @@ function run() {
9803898056
if (cache && (0, utils_1.isCacheFeatureAvailable)()) {
9803998057
yield cacheDependencies(cache, pythonVersion);
9804098058
}
98059+
yield installPipPackages();
9804198060
}
9804298061
else {
9804398062
core.warning('The `python-version` input is not set. The version of Python currently in `PATH` will be used.');

docs/advanced-usage.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes)
2424
- [Allow pre-releases](advanced-usage.md#allow-pre-releases)
2525
- [Using the pip-version input](advanced-usage.md#using-the-pip-version-input)
26+
- [Using the pip-install input](advanced-usage.md#using-the-pip-install-input)
2627

2728
## Using the `python-version` input
2829

@@ -672,3 +673,20 @@ The version of Pip should be specified in the format `major`, `major.minor`, or
672673
> The `pip-version` input is supported only with standard Python versions. It is not available when using PyPy or GraalPy.
673674

674675
> Using a specific or outdated version of pip may result in compatibility or security issues and can cause job failures. For best practices and guidance, refer to the official [pip documentation](https://pip.pypa.io/en/stable/).
676+
677+
## Using the pip-install input
678+
679+
The `pip-install` input allows you to install dependencies as part of the Python setup step.
680+
681+
682+
```yaml
683+
steps:
684+
- uses: actions/checkout@v4
685+
- name: Set up Python
686+
uses: actions/setup-python@v5
687+
with:
688+
python-version: '3.13'
689+
pip-install: -r requirements.txt
690+
```
691+
> Note: This feature is intended for standard pip-based dependency installations.
692+
For complex workflows, or alternative package managers (e.g., poetry, pipenv), we recommend using separate steps to maintain clarity and flexibility.

src/setup-python.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getVersionInputFromFile,
1414
getVersionsInputFromPlainFile
1515
} from './utils';
16+
import {exec} from '@actions/exec';
1617

1718
function isPyPyVersion(versionSpec: string) {
1819
return versionSpec.startsWith('pypy');
@@ -22,6 +23,25 @@ function isGraalPyVersion(versionSpec: string) {
2223
return versionSpec.startsWith('graalpy');
2324
}
2425

26+
async function installPipPackages() {
27+
const pipInstall = core.getInput('pip-install');
28+
29+
if (!pipInstall) {
30+
return;
31+
}
32+
core.info(`Installing pip packages: ${pipInstall}`);
33+
34+
try {
35+
const installArgs = pipInstall.trim().split(/\s+/);
36+
await exec('python', ['-m', 'pip', 'install', ...installArgs]);
37+
core.info('Successfully installed pip packages');
38+
} catch (error) {
39+
core.setFailed(
40+
`Failed to install pip packages from "${pipInstall}". Please verify that the package names and versions in the requirements file are correct, 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.`
41+
);
42+
}
43+
}
44+
2545
async function cacheDependencies(cache: string, pythonVersion: string) {
2646
const cacheDependencyPath =
2747
core.getInput('cache-dependency-path') || undefined;
@@ -145,6 +165,7 @@ async function run() {
145165
if (cache && isCacheFeatureAvailable()) {
146166
await cacheDependencies(cache, pythonVersion);
147167
}
168+
await installPipPackages();
148169
} else {
149170
core.warning(
150171
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'

0 commit comments

Comments
 (0)