mirror of
				https://gitea.com/actions/cache.git
				synced 2025-10-29 07:47:12 +00:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
			testEnable
			...
			resolve-de
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 7f8b9fe1f0 | ||
|   | 0ac93353cd | ||
|   | 051d7bc106 | ||
|   | 934cc8fa30 | ||
|   | 35dd74a1a0 | ||
|   | 869d93f182 | ||
|   | a848fb313f | 
| @@ -9,15 +9,14 @@ | ||||
|     "plugin:import/errors", | ||||
|     "plugin:import/warnings", | ||||
|     "plugin:import/typescript", | ||||
|     "plugin:prettier/recommended", | ||||
|     "prettier/@typescript-eslint" | ||||
|     "plugin:prettier/recommended" | ||||
|   ], | ||||
|   "plugins": ["@typescript-eslint", "simple-import-sort", "jest"], | ||||
|   "rules": { | ||||
|     "import/first": "error", | ||||
|     "import/newline-after-import": "error", | ||||
|     "import/no-duplicates": "error", | ||||
|     "simple-import-sort/sort": "error", | ||||
|     "simple-import-sort/imports": "error", | ||||
|     "sort-imports": "off" | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										3
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							| @@ -1 +1,2 @@ | ||||
| .licenses/** -diff linguist-generated=true | ||||
| .licenses/** -diff linguist-generated=true | ||||
| * text=auto eol=lf | ||||
| @@ -34,6 +34,8 @@ Refer [here](https://github.com/actions/cache/blob/v1/README.md) for previous ve | ||||
| ### Pre-requisites | ||||
| Create a workflow `.yml` file in your repositories `.github/workflows` directory. An [example workflow](#example-workflow) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). | ||||
|  | ||||
| If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible in the execution path. | ||||
|  | ||||
| ### Inputs | ||||
|  | ||||
| * `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns.  | ||||
|   | ||||
| @@ -17,6 +17,24 @@ afterEach(() => { | ||||
|     delete process.env[RefKey]; | ||||
| }); | ||||
|  | ||||
| test("isGhes returns true if server url is not github.com", () => { | ||||
|     try { | ||||
|         process.env["GITHUB_SERVER_URL"] = "http://example.com"; | ||||
|         expect(actionUtils.isGhes()).toBe(true); | ||||
|     } finally { | ||||
|         process.env["GITHUB_SERVER_URL"] = undefined; | ||||
|     } | ||||
| }); | ||||
|  | ||||
| test("isGhes returns true when server url is github.com", () => { | ||||
|     try { | ||||
|         process.env["GITHUB_SERVER_URL"] = "http://github.com"; | ||||
|         expect(actionUtils.isGhes()).toBe(false); | ||||
|     } finally { | ||||
|         process.env["GITHUB_SERVER_URL"] = undefined; | ||||
|     } | ||||
| }); | ||||
|  | ||||
| test("isExactKeyMatch with undefined cache key returns false", () => { | ||||
|     const key = "linux-rust"; | ||||
|     const cacheKey = undefined; | ||||
|   | ||||
| @@ -32,6 +32,8 @@ beforeAll(() => { | ||||
| beforeEach(() => { | ||||
|     process.env[Events.Key] = Events.Push; | ||||
|     process.env[RefKey] = "refs/heads/feature-branch"; | ||||
|  | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
| }); | ||||
|  | ||||
| afterEach(() => { | ||||
| @@ -53,6 +55,23 @@ 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); | ||||
|  | ||||
|     const logWarningMock = jest.spyOn(actionUtils, "logWarning"); | ||||
|     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); | ||||
|     expect(logWarningMock).toHaveBeenCalledWith( | ||||
|         "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|     ); | ||||
| }); | ||||
|  | ||||
| test("restore with no path should fail", async () => { | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|   | ||||
| @@ -52,6 +52,8 @@ beforeAll(() => { | ||||
| beforeEach(() => { | ||||
|     process.env[Events.Key] = Events.Push; | ||||
|     process.env[RefKey] = "refs/heads/feature-branch"; | ||||
|  | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
| }); | ||||
|  | ||||
| afterEach(() => { | ||||
| @@ -99,6 +101,20 @@ 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); | ||||
|  | ||||
|     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 with exact match returns early", async () => { | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|   | ||||
							
								
								
									
										12
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -36328,9 +36328,14 @@ 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 = void 0; | ||||
| exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; | ||||
| const core = __importStar(__webpack_require__(470)); | ||||
| const constants_1 = __webpack_require__(196); | ||||
| function isGhes() { | ||||
|     const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); | ||||
|     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; | ||||
| } | ||||
| exports.isGhes = isGhes; | ||||
| function isExactKeyMatch(key, cacheKey) { | ||||
|     return !!(cacheKey && | ||||
|         cacheKey.localeCompare(key, undefined, { | ||||
| @@ -46714,6 +46719,11 @@ 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"); | ||||
|                 utils.setCacheHitOutput(false); | ||||
|                 return; | ||||
|             } | ||||
|             // Validate inputs, this can cause task failure
 | ||||
|             if (!utils.isValidEvent()) { | ||||
|                 utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); | ||||
|   | ||||
							
								
								
									
										11
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -36328,9 +36328,14 @@ 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 = void 0; | ||||
| exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; | ||||
| const core = __importStar(__webpack_require__(470)); | ||||
| const constants_1 = __webpack_require__(196); | ||||
| function isGhes() { | ||||
|     const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); | ||||
|     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; | ||||
| } | ||||
| exports.isGhes = isGhes; | ||||
| function isExactKeyMatch(key, cacheKey) { | ||||
|     return !!(cacheKey && | ||||
|         cacheKey.localeCompare(key, undefined, { | ||||
| @@ -44900,6 +44905,10 @@ 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"); | ||||
|                 return; | ||||
|             } | ||||
|             if (!utils.isValidEvent()) { | ||||
|                 utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); | ||||
|                 return; | ||||
|   | ||||
| @@ -17,7 +17,7 @@ const processStdoutWrite = process.stdout.write.bind(process.stdout); | ||||
| process.stdout.write = (str, encoding, cb) => { | ||||
|     // Core library will directly call process.stdout.write for commands | ||||
|     // We don't want :: commands to be executed by the runner during tests | ||||
|     if (!str.match(/^::/)) { | ||||
|     if (!String(str).match(/^::/)) { | ||||
|         return processStdoutWrite(str, encoding, cb); | ||||
|     } | ||||
| }; | ||||
|   | ||||
							
								
								
									
										9221
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9221
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										28
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								package.json
									
									
									
									
									
								
							| @@ -29,23 +29,23 @@ | ||||
|     "@actions/io": "^1.1.0" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@types/jest": "^24.0.13", | ||||
|     "@types/jest": "^27.4.0", | ||||
|     "@types/nock": "^11.1.0", | ||||
|     "@types/node": "^12.20.7", | ||||
|     "@typescript-eslint/eslint-plugin": "^2.7.0", | ||||
|     "@typescript-eslint/parser": "^2.7.0", | ||||
|     "@types/node": "^12.20.42", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.10.1", | ||||
|     "@typescript-eslint/parser": "^5.10.1", | ||||
|     "@zeit/ncc": "^0.20.5", | ||||
|     "eslint": "^6.6.0", | ||||
|     "eslint-config-prettier": "^6.15.0", | ||||
|     "eslint-plugin-import": "^2.22.1", | ||||
|     "eslint-plugin-jest": "^23.20.0", | ||||
|     "eslint-plugin-prettier": "^3.3.1", | ||||
|     "eslint-plugin-simple-import-sort": "^5.0.2", | ||||
|     "jest": "^24.8.0", | ||||
|     "jest-circus": "^24.7.1", | ||||
|     "eslint": "^8.8.0", | ||||
|     "eslint-config-prettier": "^8.3.0", | ||||
|     "eslint-plugin-import": "^2.25.4", | ||||
|     "eslint-plugin-jest": "^26.0.0", | ||||
|     "eslint-plugin-prettier": "^4.0.0", | ||||
|     "eslint-plugin-simple-import-sort": "^7.0.0", | ||||
|     "jest": "^27.4.7", | ||||
|     "jest-circus": "^27.4.6", | ||||
|     "nock": "^11.7.0", | ||||
|     "prettier": "^1.19.1", | ||||
|     "ts-jest": "^26.5.4", | ||||
|     "prettier": "^2.5.1", | ||||
|     "ts-jest": "^27.1.3", | ||||
|     "typescript": "^3.9.9" | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,14 @@ 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" | ||||
|             ); | ||||
|             utils.setCacheHitOutput(false); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // Validate inputs, this can cause task failure | ||||
|         if (!utils.isValidEvent()) { | ||||
|             utils.logWarning( | ||||
|   | ||||
| @@ -11,6 +11,13 @@ 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" | ||||
|             ); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (!utils.isValidEvent()) { | ||||
|             utils.logWarning( | ||||
|                 `Event Validation Error: The event type ${ | ||||
|   | ||||
| @@ -2,6 +2,13 @@ import * as core from "@actions/core"; | ||||
|  | ||||
| import { Outputs, RefKey, State } from "../constants"; | ||||
|  | ||||
| export function isGhes(): boolean { | ||||
|     const ghUrl = new URL( | ||||
|         process.env["GITHUB_SERVER_URL"] || "https://github.com" | ||||
|     ); | ||||
|     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; | ||||
| } | ||||
|  | ||||
| export function isExactKeyMatch(key: string, cacheKey?: string): boolean { | ||||
|     return !!( | ||||
|         cacheKey && | ||||
|   | ||||
		Reference in New Issue
	
	Block a user