8000 Add support to opt-in enable cross-os caching on windows (#1056) · actions/cache@6fd2d45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fd2d45

Browse files
authored
Add support to opt-in enable cross-os caching on windows (#1056)
* Add support to opt-in enable cross-os caching on windows * Fix tests * Address review comments and update tests * Fix tests * Address review comments * Address review comments
1 parent 1f41429 commit 6fd2d45

22 files changed

+1172
-496
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__/actionUtils.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ test("getInputAsInt throws if required and value missing", () => {
174174
).toThrowError();
175175
});
176176

177+
test("getInputAsBool returns false if input not set", () => {
178+
expect(actionUtils.getInputAsBool("undefined")).toBe(false);
179+
});
180+
181+
test("getInputAsBool returns value if input is valid", () => {
182+
testUtils.setInput("foo", "true");
183+
expect(actionUtils.getInputAsBool("foo")).toBe(true);
184+
});
185+
186+
test("getInputAsBool returns false if input is invalid or NaN", () => {
187+
testUtils.setInput("foo", "bar");
188+
expect(actionUtils.getInputAsBool("foo")).toBe(false);
189+
});
190+
191+
test("getInputAsBool throws if required and value missing", () => {
192+
expect(() =>
193+
actionUtils.getInputAsBool("undefined2", { required: true })
194+
).toThrowError();
195+
});
196+
177197
test("isCacheFeatureAvailable for ac enabled", () => {
178198
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);
179199

__tests__/restore.test.ts

Lines changed: 32 additions & 8 deletions
< 10000 td data-grid-cell-id="diff-79e9c65d7bc0c52a974cc3ca32be05e5fd06d175bfa85edbcef3af6df03ffe8d-87-97-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ beforeAll(() => {
2727
return actualUtils.getInputAsArray(name, options);
2828
}
2929
);
30+
31+
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
32+
(name, options) => {
33+
const actualUtils = jest.requireActual("../src/utils/actionUtils");
34+
return actualUtils.getInputAsBool(name, options);
35+
}
36+
);
3037
});
3138

3239
beforeEach(() => {
40+
jest.restoreAllMocks();
3341
process.env[Events.Key] = Events.Push;
3442
process.env[RefKey] = "refs/heads/feature-branch";
3543

@@ -50,7 +58,8 @@ test("restore with no cache found", async () => {
5058
const key = "node-test";
5159
testUtils.setInputs({
5260
path: path,
53-
key
61+
key,
62+
enableCrossOsArchive: false
5463
});
5564

5665
const infoMock = jest.spyOn(core, "info");
@@ -65,7 +74,7 @@ test("restore with no cache found", async () => {
6574
await run();
6675

6776
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
68-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
77+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
6978

7079
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
7180
expect(stateMock).toHaveBeenCalledTimes(1);
@@ -84,7 +93,8 @@ test("restore with restore keys and no cache found", async () => {
8493
testUtils.setInputs({
8594
path: path,
8695
key,
87-
restoreKeys: [restoreKey]
96+
restoreKeys: [restoreKey],
97+
enableCrossOsArchive: false
8898
});
8999

90100
const infoMock = jest.spyOn(core, "info");
@@ -99,7 +109,13 @@ test("restore with restore keys and no cache found", async () => {
99109
await run();
100110

101111
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
102-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
112+
expect(restoreCacheMock).toHaveBeenCalledWith(
113+
[path],
114+
key,
115+
[restoreKey],
116+
{},
117+
false
118+
);
103119

104120
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
105121
expect(stateMock).toHaveBeenCalledTimes(1);
@@ -116,7 +132,8 @@ test("restore with cache found for key", async () => {
116132
const key = "node-test";
117133
testUtils.setInputs({
118134
path: path,
119-
key
135+
key,
136+
enableCrossOsArchive: false
120137
});
121138

122139
const infoMock = jest.spyOn(core, "info");
@@ -132,7 +149,7 @@ test("restore with cache found for key", async () => {
132149
await run();
133150

134151
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
135-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
152+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
136153

137154
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
138155
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
@@ -152,7 +169,8 @@ test("restore with cache found for restore key", async () => {
152169
testUtils.setInputs({
153170
path: path,
154171
key,
155-
restoreKeys: [restoreKey]
172+
restoreKeys: [restoreKey],
173+
enableCrossOsArchive: false
156174
});
157175

158176
const infoMock = jest.spyOn(core, "info");
@@ -168,7 +186,13 @@ test("restore with cache found for restore key", async () => {
168186
await run();
169187

170188
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
171-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
189+
expect(restoreCacheMock).toHaveBeenCalledWith(
190+
[path],
191+
key,
192+
[restoreKey],
193+
{},
194+
false
195+
);
172196

173197
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
174198
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);

__tests__/restoreImpl.test.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ beforeAll(() => {
2828
return actualUtils.getInputAsArray(name, options);
2929
}
3030
);
31+
32+
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
33+
(name, options) => {
34+
const actualUtils = jest.requireActual("../src/utils/actionUtils");
35+
return actualUtils.getInputAsBool(name, options);
36+
}
37+
);
3138
});
3239

3340
beforeEach(() => {
41+
jest.restoreAllMocks();
3442
process.env[Events.Key] = Events.Push;
3543
process.env[RefKey] = "refs/heads/feature-branch";
3644

@@ -97,7 +105,8 @@ test("restore on GHES with AC available ", async () => {
97105
const key = "node-test";
98106
testUtils.setInputs({
99107
path: path,
100-
key
108+
key,
109+
enableCrossOsArchive: false
101110
});
102111

103112
const infoMock = jest.spyOn(core, "info");
@@ -113,7 +122,7 @@ test("restore on GHES with AC available ", async () => {
113122
await run(new StateProvider());
114123

115124
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
116-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
125+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
117126

118127
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
119128
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
@@ -152,13 +161,20 @@ test("restore with too many keys should fail", async () => {
152161
testUtils.setInputs({
153162
path: path,
154163
key,
155-
restoreKeys
164+
restoreKeys,
165+
enableCrossOsArchive: false
156166
});
157167
const failedMock = jest.spyOn(core, "setFailed");
158168
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
159169
await run(new StateProvider());
160170
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
161-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, restoreKeys);
171+
expect(restoreCacheMock).toHaveBeenCalledWith(
172+
[path],
173+
key,
174+
restoreKeys,
175+
{},
176+
false
177+
);
162178
expect(failedMock).toHaveBeenCalledWith(
163179
`Key Validation Error: Keys are limited to a maximum of 10.`
164180
);
@@ -169,13 +185,14 @@ test("restore with large key should fail", async () => {
169185
const key = "foo".repeat(512); // Over the 512 character limit
170186
testUtils.setInputs({
171187
path: path,
172-
key
188+
key,
189+
enableCrossOsArchive: false
173190
});
174191
const failedMock = jest.spyOn(core, "setFailed");
175192
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
176193
await run(new StateProvider());
177194
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
178-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
195+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
179196
expect(failedMock).toHaveBeenCalledWith(
180197
`Key Validation Error: ${key} cannot be larger than 512 characters.`
181198
);
@@ -186,13 +203,14 @@ test("restore with invalid key should fail", async () => {
186203
const key = "comma,comma";
187204
testUtils.setInputs({
188205
path: path,
189-
key
206+
key,
207+
enableCrossOsArchive: false
190208
});
191209
const failedMock = jest.spyOn(core, "setFailed");
192210
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
193211
await run(new StateProvider());
194212
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
195-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
213+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
196214
expect(failedMock).toHaveBeenCalledWith(
197215
`Key Validation Error: ${key} cannot contain commas.`
198216
);
@@ -203,7 +221,8 @@ test("restore with no cache found", async () => {
203221
const key = "node-test";
204222
testUtils.setInputs({
205223
path: path,
206-
key
224+
key,
225+
enableCrossOsArchive: false
207226
});
208227

209228
const infoMock = jest.spyOn(core, "info");
@@ -218,7 +237,7 @@ test("restore with no cache found", async () => {
218237
await run(new StateProvider());
219238

220239
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
221-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
240+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
222241

223242
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
224243
expect(failedMock).toHaveBeenCalledTimes(0);
@@ -235,7 +254,8 @@ test("restore with restore keys and no cache found", async () => {
235254
testUtils.setInputs({
236255
path: path,
237256
key,
238-
restoreKeys: [restoreKey]
257+
restoreKeys: [restoreKey],
258+
enableCrossOsArchive: false
239259
});
240260

241261
const infoMock = jest.spyOn(core, "info");
@@ -250,7 +270,13 @@ test("restore with restore keys and no cache found", async () => {
250270
await run(new StateProvider());
251271

252272
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
253-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
273+
expect(restoreCacheMock).toHaveBeenCalledWith(
274+
[path],
275+
key,
276+
[restoreKey],
277+
{},
278+
false
279+
);
254280

255281
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
256282
expect(failedMock).toHaveBeenCalledTimes(0);
@@ -265,7 +291,8 @@ test("restore with cache found for key", async () => {
265291
const key = "node-test";
266292
testUtils.setInputs({
267293
path: path,
268-
key
294+
key,
295+
enableCrossOsArchive: false
269296
});
270297

271298
const infoMock = jest.spyOn(core, "info");
@@ -281,7 +308,7 @@ test("restore with cache found for key", async () => {
281308
await run(new StateProvider());
282309

283310
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
284-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
311+
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
285312

286313
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
287314
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
@@ -298,7 +325,8 @@ test("restore with cache found for restore key", async () => {
298325
testUtils.setInputs({
299326
path: path,
300327
key,
301-
restoreKeys: [restoreKey]
328+
restoreKeys: [restoreKey],
329+
enableCrossOsArchive: false
302330
});
303331

304332
const infoMock = jest.spyOn(core, "info");
@@ -314,7 +342,13 @@ test("restore with cache found for restore key", async () => {
314342
await run(new StateProvider());
315343

316344
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
317-
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
345+
expect(restoreCacheMock).toHaveBeenCalledWith(
346+
[path],
347+
key,
348+
[restoreKey],
349+
{},
350+
false
351+
);
318352

319353
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
320354
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)
0