Cache on ghes (#363) · python-machine-lrn/setup-python@05fb98d · GitHub
Skip to content

Commit 05fb98d

Browse files
tiwarishubbrcrista
andauthored
Cache on ghes (actions#363)
* initial changes * updated version * format check * refactored code * updated test cases * Update src/utils.ts Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> * Update utils.ts * Update utils.test.ts * review comments * dist update * Review comment * update version * updated version Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
1 parent 6c56602 commit 05fb98d

8 files changed

Lines changed: 1869 additions & 1784 deletions

File tree

‎.licenses/npm/@actions/cache.dep.yml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎__tests__/utils.test.ts‎

Lines changed: 43 additions & 1 deletion

‎dist/cache-save/index.js‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,10 +3728,7 @@ const options_1 = __webpack_require__(538);
37283728
const requestUtils_1 = __webpack_require__(899);
37293729
const versionSalt = '1.0';
37303730
function getCacheApiUrl(resource) {
3731-
// Ideally we just use ACTIONS_CACHE_URL
3732-
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
3733-
process.env['ACTIONS_RUNTIME_URL'] ||
3734-
'').replace('pipelines', 'artifactcache');
3731+
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
37353732
if (!baseUrl) {
37363733
throw new Error('Cache Service Url not found, unable to restore cache.');
37373734
}
@@ -5920,7 +5917,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
59205917
//
59215918
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
59225919
// on 64-bit systems), split the download into multiple segments
5923-
const maxSegmentSize = buffer.constants.MAX_LENGTH;
5920+
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
5921+
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
59245922
const downloadProgress = new DownloadProgress(contentLength);
59255923
const fd = fs.openSync(archivePath, 'w');
59265924
try {
@@ -41451,6 +41449,15 @@ function checkKey(key) {
4145141449
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
4145241450
}
4145341451
}
41452+
/**
41453+
* isFeatureAvailable to check the presence of Actions cache service
41454+
*
41455+
* @returns boolean return true if Actions cache service feature is available, otherwise false
41456+
*/
41457+
function isFeatureAvailable() {
41458+
return !!process.env['ACTIONS_CACHE_URL'];
41459+
}
41460+
exports.isFeatureAvailable = isFeatureAvailable;
4145441461
/**
4145541462
* Restores cache from keys
4145641463
*

‎dist/setup/index.js‎

Lines changed: 1776 additions & 1757 deletions
Large diffs are not rendered by default.

‎package-lock.json‎

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-python",
3-
"version": "2.2.2",
3+
"version": "3.1.0",
44
"private": true,
55
"description": "Setup python action",
66
"main": "dist/index.js",
@@ -23,7 +23,7 @@
2323
"author": "GitHub",
2424
"license": "MIT",
2525
"dependencies": {
26-
"@actions/cache": "^1.0.8",
26+
"@actions/cache": "^2.0.0",
2727
"@actions/core": "^1.2.3",
2828
"@actions/exec": "^1.1.0",
2929
"@actions/glob": "^0.2.0",

‎src/setup-python.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import * as finderPyPy from './find-pypy';
44
import * as path from 'path';
55
import * as os from 'os';
66
import {getCacheDistributor} from './cache-distributions/cache-factory';
7-
import {isGhes} from './utils';
7+
import {isCacheFeatureAvailable} from './utils';
88

99
function isPyPyVersion(versionSpec: string) {
1010
return versionSpec.startsWith('pypy-');
1111
}
1212

1313
async function cacheDependencies(cache: string, pythonVersion: string) {
14-
if (isGhes()) {
15-
throw new Error('Caching is not supported on GHES');
16-
}
1714
const cacheDependencyPath =
1815
core.getInput('cache-dependency-path') || undefined;
1916
const cacheDistributor = getCacheDistributor(
@@ -43,7 +40,7 @@ async function run() {
4340
}
4441

4542
const cache = core.getInput('cache');
46-
if (cache) {
43+
if (cache && isCacheFeatureAvailable()) {
4744
await cacheDependencies(cache, pythonVersion);
4845
}
4946
}

‎src/utils.ts‎

Lines changed: 20 additions & 0 deletions

0 commit comments

Comments
 (0)