Compare commits

...

23 Commits

Author SHA1 Message Date
Shubham Tiwari 7852e58f8c resolved conflicts 2022-03-30 15:42:54 +05:30
Shubham Tiwari c31528629d typo 2022-03-28 18:17:18 +05:30
Shubham Tiwari 0137340fba
Update package-lock.json 2022-03-28 17:57:00 +05:30
Shubham Tiwari 90e5189d64
Update package.json 2022-03-28 17:55:18 +05:30
Shubham Tiwari 5c8d224b05
Update RELEASES.md 2022-03-28 17:54:41 +05:30
Shubham Tiwari d21804b55f
Create RELEASES.md 2022-03-28 17:50:46 +05:30
Shubham Tiwari 587260d98f
Update README.md 2022-03-28 16:06:13 +05:30
Shubham Tiwari f4b8916a4f
Update package.json 2022-03-28 15:46:17 +05:30
Shubham Tiwari 6bf3948635
Update cache.dep.yml 2022-03-28 15:39:05 +05:30
Shubham Tiwari 31da19523d
Update actionUtils.test.ts 2022-03-28 15:27:12 +05:30
Shubham Tiwari e093ab00fc linting errors 2022-03-28 14:25:43 +05:30
Shubham Tiwari c5862e209e ran code format 2022-03-28 13:20:40 +05:30
Shubham Tiwari 9fae644795 changed with public released package 2022-03-28 10:08:34 +05:30
Shubham Tiwari 7e4d931f67 updated with 2.0 2022-03-25 01:57:45 +05:30
Shubham Tiwari bc53ec57f3 changed tookit 2022-03-24 17:34:39 +05:30
Shubham Tiwari 234b8019b9 added new line 2022-03-24 15:15:46 +05:30
Shubham Tiwari 770facace5 changed name 2022-03-24 15:11:17 +05:30
Shubham Tiwari 0be029b716 Merge branch 'testGheswithACFlag' of github.com:actions/cache into testGheswithACFlag 2022-03-24 15:08:17 +05:30
Shubham Tiwari 85665c5247 package.json 2022-03-24 15:01:19 +05:30
Shubham Tiwari c29e204c9f review comments and updated test cases 2022-03-24 14:59:36 +05:30
Shubham Tiwari 998cb51251
Update package-lock.json 2022-03-23 18:47:48 +05:30
Shubham Tiwari 824f444748
Update package-lock.json 2022-03-23 18:43:25 +05:30
Shubham Tiwari 1a306b5b35 initial changes 2022-03-23 18:39:24 +05:30
13 changed files with 7679 additions and 104 deletions

Binary file not shown.

View File

@ -10,6 +10,7 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu
## What's New
### v3
* Added support for caching from GHES 3.5.
* Fixed download issue for files > 2GB during restore.
* Updated the minimum runner version support from node 12 -> node 16.
@ -176,18 +177,6 @@ steps:
> Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`)
## Known limitation
- `action/cache` is currently not supported on GitHub Enterprise Server. <https://github.com/github/roadmap/issues/273> is tracking this.
Since GitHub Enterprise Server uses self-hosted runners, dependencies are typically cached on the runner by whatever dependency management tool is being used (npm, maven, etc.). This eliminates the need for explicit caching in some scenarios.
## Changelog schedule and history
| Status | Version | Date | Highlights |
|:---|:---|:---|:---|
| Published | v3.0.0 | Mar 21st, 2022 | - Updated minimum runner version support from node 12 -> node 16 <br> |
## Contributing
We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

8
RELEASES.md Normal file
View File

@ -0,0 +1,8 @@
# Releases
### 3.0.0
- Updated minimum runner version support from node 12 -> node 16
### 3.0.1
- Added support for caching from GHES 3.5.
- Fixed download issue for files > 2GB during restore.

View File

@ -1,3 +1,4 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Outputs, RefKey, State } from "../src/constants";
@ -5,6 +6,7 @@ import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
jest.mock("@actions/core");
jest.mock("@actions/cache");
beforeAll(() => {
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
@ -232,3 +234,41 @@ test("getInputAsInt throws if required and value missing", () => {
actionUtils.getInputAsInt("undefined", { required: true })
).toThrowError();
});
test("isCacheFeatureAvailable for ac enabled", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
});
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
const message =
"Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.";
const infoMock = jest.spyOn(core, "info");
try {
process.env["GITHUB_SERVER_URL"] = "http://example.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
} finally {
delete process.env["GITHUB_SERVER_URL"];
}
});
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
const message =
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";
const infoMock = jest.spyOn(core, "info");
try {
process.env["GITHUB_SERVER_URL"] = "http://github.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
} finally {
delete process.env["GITHUB_SERVER_URL"];
}
});

View File

@ -34,6 +34,9 @@ beforeEach(() => {
process.env[RefKey] = "refs/heads/feature-branch";
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => true
);
});
afterEach(() => {
@ -55,10 +58,12 @@ test("restore with invalid event outputs warning", async () => {
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("restore on GHES should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
test("restore without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
);
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
@ -67,9 +72,54 @@ test("restore on GHES should no-op", async () => {
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
expect(logWarningMock).toHaveBeenCalledWith(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
});
test("restore on GHES without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
);
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
await run();
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
});
test("restore on GHES with AC available ", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
const path = "node_modules";
const key = "node-test";
testUtils.setInputs({
path: path,
key
});
const infoMock = jest.spyOn(core, "info");
const failedMock = jest.spyOn(core, "setFailed");
const stateMock = jest.spyOn(core, "saveState");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
const restoreCacheMock = jest
.spyOn(cache, "restoreCache")
.mockImplementationOnce(() => {
return Promise.resolve(key);
});
await run();
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("restore with no path should fail", async () => {

View File

@ -54,6 +54,9 @@ beforeEach(() => {
process.env[RefKey] = "refs/heads/feature-branch";
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => true
);
});
afterEach(() => {
@ -101,18 +104,67 @@ test("save with no primary key in state outputs warning", async () => {
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("save on GHES should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
test("save without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
);
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run();
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(logWarningMock).toHaveBeenCalledWith(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
});
test("save on ghes without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
);
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run();
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
test("save on GHES with AC available", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
const failedMock = jest.spyOn(core, "setFailed");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
// Cache Entry State
.mockImplementationOnce(() => {
return savedCacheKey;
})
// Cache Key State
.mockImplementationOnce(() => {
return primaryKey;
});
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
const cacheId = 4;
const saveCacheMock = jest
.spyOn(cache, "saveCache")
.mockImplementationOnce(() => {
return Promise.resolve(cacheId);
});
await run();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, {
uploadChunkSize: 4000000
});
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("save with exact match returns early", async () => {

33
dist/restore/index.js vendored
View File

@ -3221,10 +3221,7 @@ const options_1 = __webpack_require__(538);
const requestUtils_1 = __webpack_require__(899);
const versionSalt = '1.0';
function getCacheApiUrl(resource) {
// Ideally we just use ACTIONS_CACHE_URL
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
'').replace('pipelines', 'artifactcache');
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
if (!baseUrl) {
throw new Error('Cache Service Url not found, unable to restore cache.');
}
@ -37460,7 +37457,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__webpack_require__(692));
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(196);
function isGhes() {
@ -37525,6 +37523,19 @@ function getInputAsInt(name, options) {
return value;
}
exports.getInputAsInt = getInputAsInt;
function isCacheFeatureAvailable() {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.");
}
else {
logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.");
}
return false;
}
return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
/***/ }),
@ -46440,6 +46451,15 @@ function checkKey(key) {
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
}
}
/**
* isFeatureAvailable to check the presence of Actions cache service
*
* @returns boolean return true if Actions cache service feature is available, otherwise false
*/
function isFeatureAvailable() {
return !!process.env['ACTIONS_CACHE_URL'];
}
exports.isFeatureAvailable = isFeatureAvailable;
/**
* Restores cache from keys
*
@ -48101,8 +48121,7 @@ const utils = __importStar(__webpack_require__(443));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
if (utils.isGhes()) {
utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details");
if (!utils.isCacheFeatureAvailable()) {
utils.setCacheHitOutput(false);
return;
}

33
dist/save/index.js vendored
View File

@ -3221,10 +3221,7 @@ const options_1 = __webpack_require__(538);
const requestUtils_1 = __webpack_require__(899);
const versionSalt = '1.0';
function getCacheApiUrl(resource) {
// Ideally we just use ACTIONS_CACHE_URL
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
'').replace('pipelines', 'artifactcache');
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
if (!baseUrl) {
throw new Error('Cache Service Url not found, unable to restore cache.');
}
@ -37460,7 +37457,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__webpack_require__(692));
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(196);
function isGhes() {
@ -37525,6 +37523,19 @@ function getInputAsInt(name, options) {
return value;
}
exports.getInputAsInt = getInputAsInt;
function isCacheFeatureAvailable() {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.");
}
else {
logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.");
}
return false;
}
return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
/***/ }),
@ -46389,8 +46400,7 @@ process.on("uncaughtException", e => utils.logWarning(e.message));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
if (utils.isGhes()) {
utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details");
if (!utils.isCacheFeatureAvailable()) {
return;
}
if (!utils.isValidEvent()) {
@ -46534,6 +46544,15 @@ function checkKey(key) {
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
}
}
/**
* isFeatureAvailable to check the presence of Actions cache service
*
* @returns boolean return true if Actions cache service feature is available, otherwise false
*/
function isFeatureAvailable() {
return !!process.env['ACTIONS_CACHE_URL'];
}
exports.isFeatureAvailable = isFeatureAvailable;
/**
* Restores cache from keys
*

7504
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/cache": "^1.0.11",
"@actions/cache": "^2.0.0",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2"

View File

@ -6,10 +6,7 @@ import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
try {
if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
if (!utils.isCacheFeatureAvailable()) {
utils.setCacheHitOutput(false);
return;
}

View File

@ -11,10 +11,7 @@ process.on("uncaughtException", e => utils.logWarning(e.message));
async function run(): Promise<void> {
try {
if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
if (!utils.isCacheFeatureAvailable()) {
return;
}

View File

@ -1,3 +1,4 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Outputs, RefKey, State } from "../constants";
@ -74,3 +75,20 @@ export function getInputAsInt(
}
return value;
}
export function isCacheFeatureAvailable(): boolean {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
logWarning(
"Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not."
);
} else {
logWarning(
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."
);
}
return false;
}
return true;
}