mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 15:32:13 +00:00
resolving comments
This commit is contained in:
parent
07c09af2d5
commit
1918fc78fb
7 changed files with 42 additions and 36 deletions
8
.github/workflows/e2e-cache.yml
vendored
8
.github/workflows/e2e-cache.yml
vendored
|
@ -11,6 +11,8 @@ on:
|
|||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
python-pip-depencies-caching:
|
||||
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
||||
|
@ -30,7 +32,7 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: pip install numpy pandas requests
|
||||
|
||||
python-pipenv-depencies-caching:
|
||||
python-pipenv-dependencies-caching:
|
||||
name: Test pipenv (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
@ -50,7 +52,7 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: pipenv install flake8
|
||||
|
||||
python-pip-depencies-caching-path:
|
||||
python-pip-dependencies-caching-path:
|
||||
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
@ -69,7 +71,7 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: pip install numpy pandas requests
|
||||
|
||||
python-pipenv-depencies-caching-path:
|
||||
python-pipenv-dependencies-caching-path:
|
||||
name: Test pipenv (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
|
12
README.md
12
README.md
|
@ -209,12 +209,16 @@ pypy-3.7-nightly # Python 3.7 and nightly PyPy
|
|||
|
||||
# Caching packages dependencies
|
||||
|
||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are `pip` and `pipenv`. The `cache` input is optional, and caching is turned off by default.
|
||||
The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip` and `pipenv`. The `cache` input is optional, and caching is turned off by default.
|
||||
|
||||
The action defaults to search for the dependency file (`requirements.txt` for pip or `Pipfile.lock` for pipenv) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, they are located in different subdirectories or different files for hash want to be used.
|
||||
The action defaults to searching for a dependency file (`requirements.txt` for pip or `Pipfile.lock` for pipenv) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used.
|
||||
|
||||
- For pip action will cache global cache ditrectory
|
||||
- For pipenv action will cache virtuenv directory
|
||||
- For pip, action will cache global cache directory
|
||||
- For pipenv, action will cache virtuenv directory
|
||||
|
||||
**Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time.
|
||||
|
||||
The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary.
|
||||
|
||||
**Caching pip dependencies:**
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ describe('restore-cache', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
|
||||
// process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||
|
||||
infoSpy = jest.spyOn(core, 'info');
|
||||
infoSpy.mockImplementation(input => undefined);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ describe('run', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
|
||||
// process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||
|
||||
infoSpy = jest.spyOn(core, 'info');
|
||||
infoSpy.mockImplementation(input => undefined);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ inputs:
|
|||
description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.
|
||||
default: ${{ github.token }}
|
||||
cache-dependency-path:
|
||||
description: 'Used to specify the path to a dependency files. Supports wildcards or a list of file names for caching multiple dependencies.'
|
||||
description: 'Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.'
|
||||
outputs:
|
||||
python-version:
|
||||
description: "The installed python version. Useful when given a version range as input."
|
||||
|
|
20
dist/setup/index.js
vendored
20
dist/setup/index.js
vendored
|
@ -6633,17 +6633,14 @@ const utils_1 = __webpack_require__(163);
|
|||
function isPyPyVersion(versionSpec) {
|
||||
return versionSpec.startsWith('pypy-');
|
||||
}
|
||||
function cacheDepencies(pythonVersion) {
|
||||
function cacheDepencies(cache, pythonVersion) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
if (utils_1.isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined;
|
||||
const cacheDistributor = cache_factory_1.getCacheDistributor(cache, pythonVersion, cacheDependencyPath);
|
||||
yield cacheDistributor.restoreCache();
|
||||
if (utils_1.isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined;
|
||||
const cacheDistributor = cache_factory_1.getCacheDistributor(cache, pythonVersion, cacheDependencyPath);
|
||||
yield cacheDistributor.restoreCache();
|
||||
});
|
||||
}
|
||||
function run() {
|
||||
|
@ -6663,7 +6660,10 @@ function run() {
|
|||
pythonVersion = installed.version;
|
||||
core.info(`Successfully setup ${installed.impl} (${pythonVersion})`);
|
||||
}
|
||||
yield cacheDepencies(pythonVersion);
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
yield cacheDepencies(cache, pythonVersion);
|
||||
}
|
||||
}
|
||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);
|
||||
|
|
|
@ -10,21 +10,18 @@ function isPyPyVersion(versionSpec: string) {
|
|||
return versionSpec.startsWith('pypy-');
|
||||
}
|
||||
|
||||
async function cacheDepencies(pythonVersion: string) {
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath =
|
||||
core.getInput('cache-dependency-path') || undefined;
|
||||
const cacheDistributor = getCacheDistributor(
|
||||
cache,
|
||||
pythonVersion,
|
||||
cacheDependencyPath
|
||||
);
|
||||
await cacheDistributor.restoreCache();
|
||||
async function cacheDepencies(cache: string, pythonVersion: string) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath =
|
||||
core.getInput('cache-dependency-path') || undefined;
|
||||
const cacheDistributor = getCacheDistributor(
|
||||
cache,
|
||||
pythonVersion,
|
||||
cacheDependencyPath
|
||||
);
|
||||
await cacheDistributor.restoreCache();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
|
@ -45,7 +42,10 @@ async function run() {
|
|||
core.info(`Successfully setup ${installed.impl} (${pythonVersion})`);
|
||||
}
|
||||
|
||||
await cacheDepencies(pythonVersion);
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
await cacheDepencies(cache, pythonVersion);
|
||||
}
|
||||
}
|
||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);
|
||||
|
|
Loading…
Add table
Reference in a new issue