resolving comments

This commit is contained in:
Dmitry Shibanov 2021-11-15 13:31:32 +03:00
parent 07c09af2d5
commit 1918fc78fb
7 changed files with 42 additions and 36 deletions

View file

@ -11,6 +11,8 @@ on:
paths-ignore: paths-ignore:
- '**.md' - '**.md'
permissions:
contents: read
jobs: jobs:
python-pip-depencies-caching: python-pip-depencies-caching:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
@ -30,7 +32,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pip install numpy pandas requests run: pip install numpy pandas requests
python-pipenv-depencies-caching: python-pipenv-dependencies-caching:
name: Test pipenv (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test pipenv (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
@ -50,7 +52,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pipenv install flake8 run: pipenv install flake8
python-pip-depencies-caching-path: python-pip-dependencies-caching-path:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
@ -69,7 +71,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pip install numpy pandas requests 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 }}) name: Test pipenv (Python ${{ matrix.python-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:

View file

@ -209,12 +209,16 @@ pypy-3.7-nightly # Python 3.7 and nightly PyPy
# Caching packages dependencies # 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 pip, action will cache global cache directory
- For pipenv action will cache virtuenv 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:** **Caching pip dependencies:**

View file

@ -26,7 +26,7 @@ describe('restore-cache', () => {
beforeEach(() => { beforeEach(() => {
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux'; process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
// process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
infoSpy = jest.spyOn(core, 'info'); infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(input => undefined); infoSpy.mockImplementation(input => undefined);

View file

@ -31,7 +31,7 @@ describe('run', () => {
beforeEach(() => { beforeEach(() => {
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux'; process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
// process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
infoSpy = jest.spyOn(core, 'info'); infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(input => undefined); infoSpy.mockImplementation(input => undefined);

View file

@ -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. 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 }} default: ${{ github.token }}
cache-dependency-path: 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: outputs:
python-version: python-version:
description: "The installed python version. Useful when given a version range as input." description: "The installed python version. Useful when given a version range as input."

10
dist/setup/index.js vendored
View file

@ -6633,17 +6633,14 @@ const utils_1 = __webpack_require__(163);
function isPyPyVersion(versionSpec) { function isPyPyVersion(versionSpec) {
return versionSpec.startsWith('pypy-'); return versionSpec.startsWith('pypy-');
} }
function cacheDepencies(pythonVersion) { function cacheDepencies(cache, pythonVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const cache = core.getInput('cache');
if (cache) {
if (utils_1.isGhes()) { if (utils_1.isGhes()) {
throw new Error('Caching is not supported on GHES'); throw new Error('Caching is not supported on GHES');
} }
const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined; const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined;
const cacheDistributor = cache_factory_1.getCacheDistributor(cache, pythonVersion, cacheDependencyPath); const cacheDistributor = cache_factory_1.getCacheDistributor(cache, pythonVersion, cacheDependencyPath);
yield cacheDistributor.restoreCache(); yield cacheDistributor.restoreCache();
}
}); });
} }
function run() { function run() {
@ -6663,7 +6660,10 @@ function run() {
pythonVersion = installed.version; pythonVersion = installed.version;
core.info(`Successfully setup ${installed.impl} (${pythonVersion})`); 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'); const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);

View file

@ -10,9 +10,7 @@ function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith('pypy-'); return versionSpec.startsWith('pypy-');
} }
async function cacheDepencies(pythonVersion: string) { async function cacheDepencies(cache: string, pythonVersion: string) {
const cache = core.getInput('cache');
if (cache) {
if (isGhes()) { if (isGhes()) {
throw new Error('Caching is not supported on GHES'); throw new Error('Caching is not supported on GHES');
} }
@ -25,7 +23,6 @@ async function cacheDepencies(pythonVersion: string) {
); );
await cacheDistributor.restoreCache(); await cacheDistributor.restoreCache();
} }
}
async function run() { async function run() {
try { try {
@ -45,7 +42,10 @@ async function run() {
core.info(`Successfully setup ${installed.impl} (${pythonVersion})`); 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'); const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);