Skip to content

Commit b692820

Browse files
committed
PR feedback
1 parent 6074912 commit b692820

5 files changed

Lines changed: 38 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
1818
### ⚠️ Important changes
1919

2020
> [!IMPORTANT]
21-
> `actions/cache@v6` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
21+
> `actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
2222
> If you are using self-hosted runners, ensure they are updated before upgrading.
2323
2424
The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.

__tests__/actionUtils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let pristineEnv: NodeJS.ProcessEnv;
5050
beforeEach(() => {
5151
pristineEnv = { ...process.env };
5252
jest.clearAllMocks();
53-
(core.getInput as jest.Mock).mockImplementation(
53+
jest.mocked(core.getInput).mockImplementation(
5454
(name: string, options?: { required?: boolean }) => {
5555
const val =
5656
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
@@ -217,12 +217,12 @@ test("getInputAsBool throws if required and value missing", () => {
217217
});
218218

219219
test("isCacheFeatureAvailable for ac enabled", () => {
220-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
220+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
221221
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
222222
});
223223

224224
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
225-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
225+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
226226

227227
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.
228228
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`;
@@ -237,7 +237,7 @@ Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github
237237
});
238238

239239
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
240-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
240+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
241241

242242
const message =
243243
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";

__tests__/restoreImpl.test.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const testUtils = await import("../src/utils/testUtils");
4848

4949
beforeEach(() => {
5050
jest.clearAllMocks();
51-
(core.getInput as jest.Mock).mockImplementation(
51+
jest.mocked(core.getInput).mockImplementation(
5252
(name: string, options?: { required?: boolean }) => {
5353
const val =
5454
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
@@ -59,8 +59,8 @@ beforeEach(() => {
5959
return val.trim();
6060
}
6161
);
62-
(core.getState as jest.Mock).mockReturnValue("");
63-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
62+
jest.mocked(core.getState).mockReturnValue("");
63+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
6464
process.env[Events.Key] = Events.Push;
6565
process.env[RefKey] = "refs/heads/feature-branch";
6666
});
@@ -83,7 +83,7 @@ test("restore with invalid event outputs warning", async () => {
8383
});
8484

8585
test("restore without AC available should no-op", async () => {
86-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
86+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
8787

8888
await restoreImpl(new StateProvider());
8989

@@ -93,13 +93,21 @@ test("restore without AC available should no-op", async () => {
9393
});
9494

9595
test("restore on GHES without AC available should no-op", async () => {
96-
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
96+
process.env["GITHUB_SERVER_URL"] = "https://my-ghes-server.com";
97+
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
9798

9899
await restoreImpl(new StateProvider());
99100

100101
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
101102
expect(core.setOutput).toHaveBeenCalledTimes(1);
102103
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
104+
expect(core.info).toHaveBeenCalledWith(
105+
expect.stringContaining(
106+
"Cache action is only supported on GHES version >= 3.5"
107+
)
108+
);
109+
110+
delete process.env["GITHUB_SERVER_URL"];
103111
});
104112

105113
test("restore on GHES with AC available ", async () => {
@@ -111,7 +119,7 @@ test("restore on GHES with AC available ", async () => {
111119
enableCrossOsArchive: false
112120
});
113121

114-
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
122+
jest.mocked(cache.restoreCache).mockResolvedValue(key);
115123

116124
await restoreImpl(new StateProvider());
117125

@@ -160,7 +168,7 @@ test("restore with too many keys should fail", async () => {
160168
restoreKeys,
161169
enableCrossOsArchive: false
162170
});
163-
(cache.restoreCache as jest.Mock).mockRejectedValue(
171+
jest.mocked(cache.restoreCache).mockRejectedValue(
164172
new Error("Key Validation Error: Keys are limited to a maximum of 10.")
165173
);
166174
await restoreImpl(new StateProvider());
@@ -178,7 +186,7 @@ test("restore with large key should fail", async () => {
178186
key,
179187
enableCrossOsArchive: false
180188
});
181-
(cache.restoreCache as jest.Mock).mockRejectedValue(
189+
jest.mocked(cache.restoreCache).mockRejectedValue(
182190
new Error(
183191
`Key Validation Error: ${key} cannot be larger than 512 characters.`
184192
)
@@ -198,7 +206,7 @@ test("restore with invalid key should fail", async () => {
198206
key,
199207
enableCrossOsArchive: false
200208
});
201-
(cache.restoreCache as jest.Mock).mockRejectedValue(
209+
jest.mocked(cache.restoreCache).mockRejectedValue(
202210
new Error(`Key Validation Error: ${key} cannot contain commas.`)
203211
);
204212
await restoreImpl(new StateProvider());
@@ -217,7 +225,7 @@ test("restore with no cache found", async () => {
217225
enableCrossOsArchive: false
218226
});
219227

220-
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
228+
jest.mocked(cache.restoreCache).mockResolvedValue(undefined);
221229

222230
await restoreImpl(new StateProvider());
223231

@@ -240,7 +248,7 @@ test("restore with restore keys and no cache found", async () => {
240248
enableCrossOsArchive: false
241249
});
242250

243-
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
251+
jest.mocked(cache.restoreCache).mockResolvedValue(undefined);
244252

245253
await restoreImpl(new StateProvider());
246254

@@ -261,7 +269,7 @@ test("restore with cache found for key", async () => {
261269
enableCrossOsArchive: false
262270
});
263271

264-
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
272+
jest.mocked(cache.restoreCache).mockResolvedValue(key);
265273

266274
await restoreImpl(new StateProvider());
267275

@@ -284,7 +292,7 @@ test("restore with cache found for restore key", async () => {
284292
enableCrossOsArchive: false
285293
});
286294

287-
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
295+
jest.mocked(cache.restoreCache).mockResolvedValue(restoreKey);
288296

289297
await restoreImpl(new StateProvider());
290298

@@ -307,7 +315,7 @@ test("restore with lookup-only set", async () => {
307315
lookupOnly: true
308316
});
309317

310-
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
318+
jest.mocked(cache.restoreCache).mockResolvedValue(key);
311319

312320
await restoreImpl(new StateProvider());
313321

__tests__/saveImpl.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,19 @@ test("save without AC available should no-op", async () => {
101101
});
102102

103103
test("save on ghes without AC available should no-op", async () => {
104+
process.env["GITHUB_SERVER_URL"] = "https://my-ghes-server.com";
104105
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
105106

106107
await saveImpl(new StateProvider());
107108

108109
expect(cache.saveCache).toHaveBeenCalledTimes(0);
110+
expect(core.info).toHaveBeenCalledWith(
111+
expect.stringContaining(
112+
"Cache action is only supported on GHES version >= 3.5"
113+
)
114+
);
115+
116+
delete process.env["GITHUB_SERVER_URL"];
109117
});
110118

111119
test("save on GHES with AC available", async () => {
@@ -159,8 +167,8 @@ test("save with missing input outputs warning", async () => {
159167
const savedCacheKey = "Linux-node-";
160168

161169
(core.getState as jest.Mock)
162-
.mockReturnValueOnce(savedCacheKey)
163-
.mockReturnValueOnce(primaryKey);
170+
.mockReturnValueOnce(primaryKey)
171+
.mockReturnValueOnce(savedCacheKey);
164172

165173
await saveImpl(new StateProvider());
166174

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"main": "dist/restore/index.js",
88
"scripts": {
99
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
10-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
10+
"test": "tsc --noEmit && node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
1111
"lint": "eslint **/*.ts --cache",
1212
"format": "prettier --write **/*.ts",
1313
"format-check": "prettier --check **/*.ts"

0 commit comments

Comments
 (0)