Compare commits

..

2 Commits

Author SHA1 Message Date
dependabot[bot]
c3739a195c Bump typescript from 5.4.2 to 5.8.3
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.4.2 to 5.8.3.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release-publish.yml)
- [Commits](https://github.com/microsoft/TypeScript/compare/v5.4.2...v5.8.3)

---
updated-dependencies:
- dependency-name: typescript
  dependency-version: 5.8.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-06 06:56:44 +00:00
gowridurgad
2e3e4b15a8 Add support for pip-install input (#1201)
* Add pip-install input

* Improve error message

* Logic update

---------

Co-authored-by: “gowridurgad” <“hgowridurgad@github.com>
2025-09-25 22:01:19 -05:00
11 changed files with 1304 additions and 1055 deletions

View File

@@ -219,3 +219,56 @@ jobs:
pip-version: '25.0.1' pip-version: '25.0.1'
- name: Install dependencies - name: Install dependencies
run: pip install numpy pandas requests run: pip install numpy pandas requests
python-pip-dependencies-caching-with-pip-install:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
ubuntu-latest,
ubuntu-22.04,
ubuntu-24.04-arm,
ubuntu-22.04-arm,
windows-latest,
macos-latest,
macos-13
]
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
steps:
- uses: actions/checkout@v5
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
pip-install: numpy pandas requests
python-pip-dependencies-caching-path-with-pip-install:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}, caching path)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
ubuntu-latest,
ubuntu-22.04,
ubuntu-24.04-arm,
ubuntu-22.04-arm,
windows-latest,
macos-latest,
macos-13
]
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
steps:
- uses: actions/checkout@v5
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: __tests__/data/requirements.txt
pip-install: numpy pandas requests

View File

@@ -311,3 +311,56 @@ jobs:
pip-version: '25.0.1' pip-version: '25.0.1'
- name: Install dependencies - name: Install dependencies
run: pip install numpy pandas requests run: pip install numpy pandas requests
python-pip-dependencies-caching-with-pip-install:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
ubuntu-latest,
ubuntu-24.04-arm,
ubuntu-22.04,
ubuntu-22.04-arm,
windows-latest,
macos-latest,
macos-13
]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v5
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
pip-install: numpy pandas requests
python-pip-dependencies-caching-path-with-pip-install:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}, caching path)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
ubuntu-latest,
ubuntu-24.04-arm,
ubuntu-22.04,
ubuntu-22.04-arm,
windows-latest,
macos-latest,
macos-13
]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v5
- name: Setup Python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: __tests__/data/requirements.txt
pip-install: numpy pandas requests

View File

@@ -118,6 +118,7 @@ See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poet
- [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes) - [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes)
- [Allow pre-releases](docs/advanced-usage.md#allow-pre-releases) - [Allow pre-releases](docs/advanced-usage.md#allow-pre-releases)
- [Using the pip-version input](docs/advanced-usage.md#using-the-pip-version-input) - [Using the pip-version input](docs/advanced-usage.md#using-the-pip-version-input)
- [Using the pip-install input](docs/advanced-usage.md#using-the-pip-install-input)
## Recommended permissions ## Recommended permissions

View File

@@ -31,6 +31,8 @@ inputs:
default: false default: false
pip-version: pip-version:
description: "Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]." description: "Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]."
pip-install:
description: "Used to specify the packages to install with pip after setting up Python. Can be a requirements file or package names."
outputs: outputs:
python-version: python-version:
description: "The installed Python or PyPy version. Useful when given a version range as input." description: "The installed Python or PyPy version. Useful when given a version range as input."

View File

@@ -87714,23 +87714,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
}) : function(o, v) { }) : function(o, v) {
o["default"] = v; o["default"] = v;
}); });
var __importStar = (this && this.__importStar) || (function () { var __importStar = (this && this.__importStar) || function (mod) {
var ownKeys = function(o) { if (mod && mod.__esModule) return mod;
ownKeys = Object.getOwnPropertyNames || function (o) { var result = {};
var ar = []; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; __setModuleDefault(result, mod);
return ar; return result;
}; };
return ownKeys(o); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
}; function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return function (mod) { return new (P || (P = Promise))(function (resolve, reject) {
if (mod && mod.__esModule) return mod; function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
var result = {}; function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
__setModuleDefault(result, mod); step((generator = generator.apply(thisArg, _arguments || [])).next());
return result; });
}; };
})();
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.State = void 0; exports.State = void 0;
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
@@ -87748,32 +87747,36 @@ class CacheDistributor {
this.cacheDependencyPath = cacheDependencyPath; this.cacheDependencyPath = cacheDependencyPath;
this.CACHE_KEY_PREFIX = 'setup-python'; this.CACHE_KEY_PREFIX = 'setup-python';
} }
async handleLoadedCache() { } handleLoadedCache() {
async restoreCache() { return __awaiter(this, void 0, void 0, function* () { });
const { primaryKey, restoreKey } = await this.computeKeys(); }
if (primaryKey.endsWith('-')) { restoreCache() {
const file = this.packageManager === 'pip' return __awaiter(this, void 0, void 0, function* () {
? `${this.cacheDependencyPath const { primaryKey, restoreKey } = yield this.computeKeys();
.split('\n') if (primaryKey.endsWith('-')) {
.join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}` const file = this.packageManager === 'pip'
: this.cacheDependencyPath.split('\n').join(','); ? `${this.cacheDependencyPath
throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`); .split('\n')
} .join(',')} or ${constants_1.CACHE_DEPENDENCY_BACKUP_PATH}`
const cachePath = await this.getCacheGlobalDirectories(); : this.cacheDependencyPath.split('\n').join(',');
core.saveState(State.CACHE_PATHS, cachePath); throw new Error(`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`);
let matchedKey; }
try { const cachePath = yield this.getCacheGlobalDirectories();
matchedKey = await cache.restoreCache(cachePath, primaryKey, restoreKey); core.saveState(State.CACHE_PATHS, cachePath);
} let matchedKey;
catch (err) { try {
const message = err.message; matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
core.info(`[warning]${message}`); }
core.setOutput('cache-hit', false); catch (err) {
return; const message = err.message;
} core.info(`[warning]${message}`);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); core.setOutput('cache-hit', false);
await this.handleLoadedCache(); return;
this.handleMatchResult(matchedKey, primaryKey); }
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
yield this.handleLoadedCache();
this.handleMatchResult(matchedKey, primaryKey);
});
} }
handleMatchResult(matchedKey, primaryKey) { handleMatchResult(matchedKey, primaryKey) {
if (matchedKey) { if (matchedKey) {
@@ -87824,28 +87827,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
}) : function(o, v) { }) : function(o, v) {
o["default"] = v; o["default"] = v;
}); });
var __importStar = (this && this.__importStar) || (function () { var __importStar = (this && this.__importStar) || function (mod) {
var ownKeys = function(o) { if (mod && mod.__esModule) return mod;
ownKeys = Object.getOwnPropertyNames || function (o) { var result = {};
var ar = []; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; __setModuleDefault(result, mod);
return ar; return result;
}; };
return ownKeys(o); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
}; function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return function (mod) { return new (P || (P = Promise))(function (resolve, reject) {
if (mod && mod.__esModule) return mod; function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
var result = {}; function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
__setModuleDefault(result, mod); step((generator = generator.apply(thisArg, _arguments || [])).next());
return result; });
}; };
})();
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = run; exports.run = void 0;
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
const fs_1 = __importDefault(__nccwpck_require__(9896)); const fs_1 = __importDefault(__nccwpck_require__(9896));
@@ -87853,57 +87855,62 @@ const cache_distributor_1 = __nccwpck_require__(2326);
// Added early exit to resolve issue with slow post action step: // Added early exit to resolve issue with slow post action step:
// - https://github.com/actions/setup-node/issues/878 // - https://github.com/actions/setup-node/issues/878
// https://github.com/actions/cache/pull/1217 // https://github.com/actions/cache/pull/1217
async function run(earlyExit) { function run(earlyExit) {
try { return __awaiter(this, void 0, void 0, function* () {
const cache = core.getInput('cache'); try {
if (cache) { const cache = core.getInput('cache');
await saveCache(cache); if (cache) {
if (earlyExit) { yield saveCache(cache);
process.exit(0); if (earlyExit) {
process.exit(0);
}
} }
} }
} catch (error) {
catch (error) { const err = error;
const err = error; core.setFailed(err.message);
core.setFailed(err.message); }
} });
} }
async function saveCache(packageManager) { exports.run = run;
const cachePathState = core.getState(cache_distributor_1.State.CACHE_PATHS); function saveCache(packageManager) {
if (!cachePathState) { return __awaiter(this, void 0, void 0, function* () {
core.warning('Cache paths are empty. Please check the previous logs and make sure that the python version is specified'); const cachePathState = core.getState(cache_distributor_1.State.CACHE_PATHS);
return; if (!cachePathState) {
} core.warning('Cache paths are empty. Please check the previous logs and make sure that the python version is specified');
const cachePaths = JSON.parse(cachePathState); return;
core.debug(`paths for caching are ${cachePaths.join(', ')}`); }
if (!isCacheDirectoryExists(cachePaths)) { const cachePaths = JSON.parse(cachePathState);
core.warning(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePaths.join(', ')}. This likely indicates that there are no dependencies to cache. Consider removing the cache step if it is not needed.`); core.debug(`paths for caching are ${cachePaths.join(', ')}`);
return; if (!isCacheDirectoryExists(cachePaths)) {
} core.warning(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePaths.join(', ')}. This likely indicates that there are no dependencies to cache. Consider removing the cache step if it is not needed.`);
const primaryKey = core.getState(cache_distributor_1.State.STATE_CACHE_PRIMARY_KEY); return;
const matchedKey = core.getState(cache_distributor_1.State.CACHE_MATCHED_KEY); }
if (!primaryKey) { const primaryKey = core.getState(cache_distributor_1.State.STATE_CACHE_PRIMARY_KEY);
core.warning('Error retrieving key from state.'); const matchedKey = core.getState(cache_distributor_1.State.CACHE_MATCHED_KEY);
return; if (!primaryKey) {
} core.warning('Error retrieving key from state.');
else if (matchedKey === primaryKey) { return;
// no change in target directories }
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); else if (matchedKey === primaryKey) {
return; // no change in target directories
} core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
let cacheId = 0; return;
try { }
cacheId = await cache.saveCache(cachePaths, primaryKey); let cacheId = 0;
} try {
catch (err) { cacheId = yield cache.saveCache(cachePaths, primaryKey);
const message = err.message; }
core.info(`[warning]${message}`); catch (err) {
return; const message = err.message;
} core.info(`[warning]${message}`);
if (cacheId == -1) { return;
return; }
} if (cacheId == -1) {
core.info(`Cache saved with the key: ${primaryKey}`); return;
}
core.info(`Cache saved with the key: ${primaryKey}`);
});
} }
function isCacheDirectoryExists(cacheDirectory) { function isCacheDirectoryExists(cacheDirectory) {
const result = cacheDirectory.reduce((previousValue, currentValue) => { const result = cacheDirectory.reduce((previousValue, currentValue) => {

1977
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@
- [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes) - [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes)
- [Allow pre-releases](advanced-usage.md#allow-pre-releases) - [Allow pre-releases](advanced-usage.md#allow-pre-releases)
- [Using the pip-version input](advanced-usage.md#using-the-pip-version-input) - [Using the pip-version input](advanced-usage.md#using-the-pip-version-input)
- [Using the pip-install input](advanced-usage.md#using-the-pip-install-input)
## Using the `python-version` input ## Using the `python-version` input
@@ -672,3 +673,20 @@ The version of Pip should be specified in the format `major`, `major.minor`, or
> The `pip-version` input is supported only with standard Python versions. It is not available when using PyPy or GraalPy. > The `pip-version` input is supported only with standard Python versions. It is not available when using PyPy or GraalPy.
> 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/). > 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/).
## Using the pip-install input
The `pip-install` input allows you to install dependencies as part of the Python setup step.
```yaml
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
pip-install: -r requirements.txt
```
> Note: This feature is intended for standard pip-based dependency installations.
For complex workflows, or alternative package managers (e.g., poetry, pipenv), we recommend using separate steps to maintain clarity and flexibility.

8
package-lock.json generated
View File

@@ -34,7 +34,7 @@
"jest-circus": "^29.7.0", "jest-circus": "^29.7.0",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"ts-jest": "^29.3.2", "ts-jest": "^29.3.2",
"typescript": "^5.9.2" "typescript": "^5.9.3"
}, },
"engines": { "engines": {
"node": ">=24.0.0" "node": ">=24.0.0"
@@ -5446,9 +5446,9 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.9.2", "version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true, "dev": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"bin": { "bin": {

View File

@@ -53,6 +53,6 @@
"jest-circus": "^29.7.0", "jest-circus": "^29.7.0",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"ts-jest": "^29.3.2", "ts-jest": "^29.3.2",
"typescript": "^5.9.2" "typescript": "^5.9.3"
} }
} }

View File

@@ -13,6 +13,7 @@ import {
getVersionInputFromFile, getVersionInputFromFile,
getVersionsInputFromPlainFile getVersionsInputFromPlainFile
} from './utils'; } from './utils';
import {exec} from '@actions/exec';
function isPyPyVersion(versionSpec: string) { function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith('pypy'); return versionSpec.startsWith('pypy');
@@ -22,6 +23,19 @@ function isGraalPyVersion(versionSpec: string) {
return versionSpec.startsWith('graalpy'); 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) { async function cacheDependencies(cache: string, pythonVersion: string) {
const cacheDependencyPath = const cacheDependencyPath =
core.getInput('cache-dependency-path') || undefined; core.getInput('cache-dependency-path') || undefined;
@@ -145,6 +159,10 @@ async function run() {
if (cache && isCacheFeatureAvailable()) { if (cache && isCacheFeatureAvailable()) {
await cacheDependencies(cache, pythonVersion); await cacheDependencies(cache, pythonVersion);
} }
const pipInstall = core.getInput('pip-install');
if (pipInstall) {
await installPipPackages(pipInstall);
}
} else { } else {
core.warning( core.warning(
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.' 'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'

View File

@@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ // "incremental": true, /* Enable incremental compilation */
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */