Skip to content

Commit dc1a9f2

Browse files
authored
Caching on GHES (#308)
* initial changes * review comments * updated with correct message * linting * update version * updated version
1 parent e886040 commit dc1a9f2

File tree

8 files changed

+1792
-1678
lines changed

8 files changed

+1792
-1678
lines changed

.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__/util.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { isVersionSatisfies } from '../src/util';
1+
import * as cache from '@actions/cache';
2+
import * as core from '@actions/core';
3+
import { isVersionSatisfies, isCacheFeatureAvailable } from '../src/util';
4+
5+
jest.mock('@actions/cache');
6+
jest.mock('@actions/core');
27

38
describe('isVersionSatisfies', () => {
49
it.each([
@@ -20,3 +25,38 @@ describe('isVersionSatisfies', () => {
2025
expect(actual).toBe(expected);
2126
});
2227
});
28+
29+
describe('isCacheFeatureAvailable', () => {
30+
it('isCacheFeatureAvailable disabled on GHES', () => {
31+
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
32+
try {
33+
process.env['GITHUB_SERVER_URL'] = 'http://example.com';
34+
isCacheFeatureAvailable();
35+
} catch (error) {
36+
expect(error).toHaveProperty(
37+
'message',
38+
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
39+
);
40+
} finally {
41+
delete process.env['GITHUB_SERVER_URL'];
42+
}
43+
});
44+
45+
it('isCacheFeatureAvailable disabled on dotcom', () => {
46+
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
47+
const infoMock = jest.spyOn(core, 'warning');
48+
const message = 'The runner was not able to contact the cache service. Caching will be skipped';
49+
try {
50+
process.env['GITHUB_SERVER_URL'] = 'http://github.com';
51+
expect(isCacheFeatureAvailable()).toBe(false);
52+
expect(infoMock).toHaveBeenCalledWith(message);
53+
} finally {
54+
delete process.env['GITHUB_SERVER_URL'];
55+
}
56+
});
57+
58+
it('isCacheFeatureAvailable is enabled', () => {
59+
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => true);
60+
expect(isCacheFeatureAvailable()).toBe(true);
61+
});
62+
});

dist/cleanup/index.js

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,10 +3730,7 @@ const options_1 = __webpack_require__(538);
37303730
const requestUtils_1 = __webpack_require__(899);
37313731
const versionSalt = '1.0';
37323732
function getCacheApiUrl(resource) {
3733-
// Ideally we just use ACTIONS_CACHE_URL
3734-
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
3735-
process.env['ACTIONS_RUNTIME_URL'] ||
3736-
'').replace('pipelines', 'artifactcache');
3733+
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
37373734
if (!baseUrl) {
37383735
throw new Error('Cache Service Url not found, unable to restore cache.');
37393736
}
@@ -5932,7 +5929,35 @@ module.exports = {
59325929
/* 193 */,
59335930
/* 194 */,
59345931
/* 195 */,
5935-
/* 196 */,
5932+
/* 196 */
5933+
/***/ (function(__unusedmodule, exports) {
5934+
5935+
"use strict";
5936+
5937+
Object.defineProperty(exports, "__esModule", { value: true });
5938+
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
5939+
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
5940+
exports.INPUT_JAVA_VERSION = 'java-version';
5941+
exports.INPUT_ARCHITECTURE = 'architecture';
5942+
exports.INPUT_JAVA_PACKAGE = 'java-package';
5943+
exports.INPUT_DISTRIBUTION = 'distribution';
5944+
exports.INPUT_JDK_FILE = 'jdkFile';
5945+
exports.INPUT_CHECK_LATEST = 'check-latest';
5946+
exports.INPUT_SERVER_ID = 'server-id';
5947+
exports.INPUT_SERVER_USERNAME = 'server-username';
5948+
exports.INPUT_SERVER_PASSWORD = 'server-password';
5949+
exports.INPUT_SETTINGS_PATH = 'settings-path';
5950+
exports.INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
5951+
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
5952+
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
5953+
exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
5954+
exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
5955+
exports.INPUT_CACHE = 'cache';
5956+
exports.INPUT_JOB_STATUS = 'job-status';
5957+
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
5958+
5959+
5960+
/***/ }),
59365961
/* 197 */
59375962
/***/ (function(__unusedmodule, exports, __webpack_require__) {
59385963

@@ -6092,7 +6117,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
60926117
exports.run = void 0;
60936118
const core = __importStar(__webpack_require__(470));
60946119
const gpg = __importStar(__webpack_require__(884));
6095-
const constants = __importStar(__webpack_require__(694));
6120+
const constants = __importStar(__webpack_require__(196));
60966121
const util_1 = __webpack_require__(322);
60976122
const cache_1 = __webpack_require__(913);
60986123
function removePrivateKeyFromKeychain() {
@@ -6889,7 +6914,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
68896914
//
68906915
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
68916916
// on 64-bit systems), split the download into multiple segments
6892-
const maxSegmentSize = buffer.constants.MAX_LENGTH;
6917+
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
6918+
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
68936919
const downloadProgress = new DownloadProgress(contentLength);
68946920
const fd = fs.openSync(archivePath, 'w');
68956921
try {
@@ -9110,14 +9136,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
91109136
return (mod && mod.__esModule) ? mod : { "default": mod };
91119137
};
91129138
Object.defineProperty(exports, "__esModule", { value: true });
9113-
exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
9139+
exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
91149140
const os_1 = __importDefault(__webpack_require__(87));
91159141
const path_1 = __importDefault(__webpack_require__(622));
91169142
const fs = __importStar(__webpack_require__(747));
91179143
const semver = __importStar(__webpack_require__(876));
9144+
const cache = __importStar(__webpack_require__(692));
91189145
const core = __importStar(__webpack_require__(470));
91199146
const tc = __importStar(__webpack_require__(533));
9120-
const constants_1 = __webpack_require__(694);
9147+
const constants_1 = __webpack_require__(196);
91219148
function getTempDir() {
91229149
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
91239150
return tempDirectory;
@@ -9187,6 +9214,24 @@ function isJobStatusSuccess() {
91879214
return jobStatus === 'success';
91889215
}
91899216
exports.isJobStatusSuccess = isJobStatusSuccess;
9217+
function isGhes() {
9218+
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
9219+
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
9220+
}
9221+
exports.isGhes = isGhes;
9222+
function isCacheFeatureAvailable() {
9223+
if (!cache.isFeatureAvailable()) {
9224+
if (isGhes()) {
9225+
throw new Error('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.');
9226+
}
9227+
else {
9228+
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
9229+
}
9230+
return false;
9231+
}
9232+
return true;
9233+
}
9234+
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
91909235

91919236

91929237
/***/ }),
@@ -41953,7 +41998,7 @@ __exportStar(__webpack_require__(220), exports);
4195341998
__exportStar(__webpack_require__(932), exports);
4195441999
__exportStar(__webpack_require__(975), exports);
4195542000
__exportStar(__webpack_require__(207), exports);
41956-
__exportStar(__webpack_require__(773), exports);
42001+
__exportStar(__webpack_require__(694), exports);
4195742002
__exportStar(__webpack_require__(695), exports);
4195842003
var spancontext_utils_1 = __webpack_require__(629);
4195942004
Object.defineProperty(exports, "isSpanContextValid", { enumerable: true, get: function () { return spancontext_utils_1.isSpanContextValid; } });
@@ -53506,6 +53551,15 @@ function checkKey(key) {
5350653551
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
5350753552
}
5350853553
}
53554+
/**
53555+
* isFeatureAvailable to check the presence of Actions cache service
53556+
*
53557+
* @returns boolean return true if Actions cache service feature is available, otherwise false
53558+
*/
53559+
function isFeatureAvailable() {
53560+
return !!process.env['ACTIONS_CACHE_URL'];
53561+
}
53562+
exports.isFeatureAvailable = isFeatureAvailable;
5350953563
/**
5351053564
* Restores cache from keys
5351153565
*
@@ -53626,28 +53680,23 @@ exports.saveCache = saveCache;
5362653680

5362753681
"use strict";
5362853682

53683+
/*
53684+
* Copyright The OpenTelemetry Authors
53685+
*
53686+
* Licensed under the Apache License, Version 2.0 (the "License");
53687+
* you may not use this file except in compliance with the License.
53688+
* You may obtain a copy of the License at
53689+
*
53690+
* https://www.apache.org/licenses/LICENSE-2.0
53691+
*
53692+
* Unless required by applicable law or agreed to in writing, software
53693+
* distributed under the License is distributed on an "AS IS" BASIS,
53694+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53695+
* See the License for the specific language governing permissions and
53696+
* limitations under the License.
53697+
*/
5362953698
Object.defineProperty(exports, "__esModule", { value: true });
53630-
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
53631-
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
53632-
exports.INPUT_JAVA_VERSION = 'java-version';
53633-
exports.INPUT_ARCHITECTURE = 'architecture';
53634-
exports.INPUT_JAVA_PACKAGE = 'java-package';
53635-
exports.INPUT_DISTRIBUTION = 'distribution';
53636-
exports.INPUT_JDK_FILE = 'jdkFile';
53637-
exports.INPUT_CHECK_LATEST = 'check-latest';
53638-
exports.INPUT_SERVER_ID = 'server-id';
53639-
exports.INPUT_SERVER_USERNAME = 'server-username';
53640-
exports.INPUT_SERVER_PASSWORD = 'server-password';
53641-
exports.INPUT_SETTINGS_PATH = 'settings-path';
53642-
exports.INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
53643-
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
53644-
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
53645-
exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
53646-
exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
53647-
exports.INPUT_CACHE = 'cache';
53648-
exports.INPUT_JOB_STATUS = 'job-status';
53649-
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
53650-
53699+
//# sourceMappingURL=tracer_provider.js.map
5365153700

5365253701
/***/ }),
5365353702
/* 695 */
@@ -55714,30 +55763,7 @@ module.exports = function(dst, src) {
5571455763
/* 770 */,
5571555764
/* 771 */,
5571655765
/* 772 */,
55717-
/* 773 */
55718-
/***/ (function(__unusedmodule, exports) {
55719-
55720-
"use strict";
55721-
55722-
/*
55723-
* Copyright The OpenTelemetry Authors
55724-
*
55725-
* Licensed under the Apache License, Version 2.0 (the "License");
55726-
* you may not use this file except in compliance with the License.
55727-
* You may obtain a copy of the License at
55728-
*
55729-
* https://www.apache.org/licenses/LICENSE-2.0
55730-
*
55731-
* Unless required by applicable law or agreed to in writing, software
55732-
* distributed under the License is distributed on an "AS IS" BASIS,
55733-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55734-
* See the License for the specific language governing permissions and
55735-
* limitations under the License.
55736-
*/
55737-
Object.defineProperty(exports, "__esModule", { value: true });
55738-
//# sourceMappingURL=tracer_provider.js.map
55739-
55740-
/***/ }),
55766+
/* 773 */,
5574155767
/* 774 */,
5574255768
/* 775 */,
5574355769
/* 776 */,

0 commit comments

Comments
 (0)