Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f46bb21315 | ||
|
|
58c146cc91 | ||
|
|
2d5e079d9e | ||
|
|
667e98af5a | ||
|
|
5b7eeecaeb | ||
|
|
0769f2e443 | ||
|
|
515d10b4fd | ||
|
|
669e7536d9 | ||
|
|
29dbbce762 | ||
|
|
ea5981db97 |
@@ -28,6 +28,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
||||
* Fix zstd not working for windows on gnu tar in issues.
|
||||
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes.
|
||||
* Two new actions available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml)
|
||||
* Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info.
|
||||
|
||||
Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions
|
||||
|
||||
@@ -43,6 +44,7 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in
|
||||
* `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.
|
||||
* `key` - An explicit key for restoring and saving the cache
|
||||
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.
|
||||
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false
|
||||
|
||||
#### Environment Variables
|
||||
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `60`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout)
|
||||
@@ -245,7 +247,7 @@ Following are some of the known practices/workarounds which community has used t
|
||||
- [Cache segment restore timeout](./tips-and-workarounds.md#cache-segment-restore-timeout)
|
||||
- [Update a cache](./tips-and-workarounds.md#update-a-cache)
|
||||
- [Use cache across feature branches](./tips-and-workarounds.md#use-cache-across-feature-branches)
|
||||
- [Improving cache restore performance on Windows/Using cross-os caching](./tips-and-workarounds.md#improving-cache-restore-performance-on-windows-using-cross-os-caching)
|
||||
- [Cross OS cache](./tips-and-workarounds.md#cross-os-cache)
|
||||
- [Force deletion of caches overriding default cache eviction policy](./tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy)
|
||||
|
||||
#### Windows environment variables
|
||||
|
||||
+5
-1
@@ -62,4 +62,8 @@
|
||||
- Added logs for cache version in case of a cache miss.
|
||||
|
||||
### 3.2.2
|
||||
- Reverted the changes made in 3.2.1 to use gnu tar and zstd by default on windows.
|
||||
- Reverted the changes made in 3.2.1 to use gnu tar and zstd by default on windows.
|
||||
|
||||
### 3.2.3
|
||||
- Support cross os caching on Windows as an opt-in feature.
|
||||
- Fix issue with symlink restoration on Windows for cross-os caches.
|
||||
@@ -11,12 +11,12 @@ jest.mock("@actions/cache");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
jest.spyOn(core, "getInput").mockImplementation(name => {
|
||||
return testUtils.getInput(name);
|
||||
});
|
||||
|
||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").getInput(key, value);
|
||||
jest.spyOn(core, "getState").mockImplementation(name => {
|
||||
return jest.requireActual("@actions/core").getState(name);
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { Events, RefKey, State } from "../src/constants";
|
||||
import { Events, Inputs, RefKey, State } from "../src/constants";
|
||||
import {
|
||||
IStateProvider,
|
||||
NullStateProvider,
|
||||
StateProvider
|
||||
} from "../src/stateProvider";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
|
||||
@@ -58,32 +59,43 @@ test("StateProvider saves states", async () => {
|
||||
});
|
||||
|
||||
test("NullStateProvider saves outputs", async () => {
|
||||
const states = new Map<string, string>();
|
||||
|
||||
const getInputMock = jest
|
||||
.spyOn(core, "getInput")
|
||||
.mockImplementation(key => testUtils.getInput(key));
|
||||
|
||||
const getStateMock = jest
|
||||
.spyOn(core, "getState")
|
||||
.mockImplementation(name =>
|
||||
jest.requireActual("@actions/core").getState(name)
|
||||
);
|
||||
.mockImplementation(key => {
|
||||
return jest.requireActual("@actions/core").getState(key);
|
||||
});
|
||||
|
||||
const setOutputMock = jest
|
||||
.spyOn(core, "setOutput")
|
||||
.mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
||||
states.set(key, value);
|
||||
});
|
||||
|
||||
const saveStateMock = jest
|
||||
.spyOn(core, "saveState")
|
||||
.mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").saveState(key, value);
|
||||
states.set(key, value);
|
||||
});
|
||||
|
||||
const cacheMatchedKey = "node-cache";
|
||||
const cachePrimaryKey = "primary-key";
|
||||
const nullStateProvider: IStateProvider = new NullStateProvider();
|
||||
nullStateProvider.setState(State.CacheMatchedKey, "outputValue");
|
||||
nullStateProvider.setState(State.CachePrimaryKey, cacheMatchedKey);
|
||||
nullStateProvider.getState("outputKey");
|
||||
nullStateProvider.getCacheState();
|
||||
testUtils.setInput(Inputs.Key, cachePrimaryKey);
|
||||
nullStateProvider.setState(State.CachePrimaryKey, cachePrimaryKey);
|
||||
nullStateProvider.setState(State.CacheMatchedKey, cacheMatchedKey);
|
||||
const output1 = nullStateProvider.getState(State.CachePrimaryKey);
|
||||
const output2 = nullStateProvider.getCacheState();
|
||||
|
||||
expect(getStateMock).toHaveBeenCalledTimes(0);
|
||||
expect(getInputMock).toHaveBeenCalledTimes(1);
|
||||
expect(output1).toBe("primary-key");
|
||||
expect(output2).toBe(undefined);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
||||
expect(saveStateMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
Vendored
+12
-3
@@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.stateToInputMap = new Map([
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||
]);
|
||||
this.stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
this.setState = (key, value) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
if (this.stateToOutputMap.has(key)) {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
}
|
||||
};
|
||||
this.getState = (key) => {
|
||||
if (!this.stateToInputMap.has(key)) {
|
||||
return "";
|
||||
}
|
||||
return core.getInput(this.stateToInputMap.get(key));
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
}
|
||||
exports.NullStateProvider = NullStateProvider;
|
||||
|
||||
Vendored
+12
-3
@@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.stateToInputMap = new Map([
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||
]);
|
||||
this.stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
this.setState = (key, value) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
if (this.stateToOutputMap.has(key)) {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
}
|
||||
};
|
||||
this.getState = (key) => {
|
||||
if (!this.stateToInputMap.has(key)) {
|
||||
return "";
|
||||
}
|
||||
return core.getInput(this.stateToInputMap.get(key));
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
}
|
||||
exports.NullStateProvider = NullStateProvider;
|
||||
|
||||
Vendored
+13
-5
@@ -9469,15 +9469,24 @@ exports.StateProvider = StateProvider;
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.stateToInputMap = new Map([
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||
]);
|
||||
this.stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
this.setState = (key, value) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
if (this.stateToOutputMap.has(key)) {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
}
|
||||
};
|
||||
this.getState = (key) => {
|
||||
if (!this.stateToInputMap.has(key)) {
|
||||
return "";
|
||||
}
|
||||
return core.getInput(this.stateToInputMap.get(key));
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
}
|
||||
exports.NullStateProvider = NullStateProvider;
|
||||
@@ -41164,8 +41173,7 @@ function saveImpl(stateProvider) {
|
||||
}
|
||||
// If restore has stored a primary key in state, reuse that
|
||||
// Else re-evaluate from inputs
|
||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
||||
core.getInput(constants_1.Inputs.Key);
|
||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey);
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Key is not specified.`);
|
||||
return;
|
||||
|
||||
Vendored
+13
-5
@@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.stateToInputMap = new Map([
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||
]);
|
||||
this.stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
this.setState = (key, value) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
if (this.stateToOutputMap.has(key)) {
|
||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
||||
}
|
||||
};
|
||||
this.getState = (key) => {
|
||||
if (!this.stateToInputMap.has(key)) {
|
||||
return "";
|
||||
}
|
||||
return core.getInput(this.stateToInputMap.get(key));
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
}
|
||||
exports.NullStateProvider = NullStateProvider;
|
||||
@@ -41108,8 +41117,7 @@ function saveImpl(stateProvider) {
|
||||
}
|
||||
// If restore has stored a primary key in state, reuse that
|
||||
// Else re-evaluate from inputs
|
||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
||||
core.getInput(constants_1.Inputs.Key);
|
||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey);
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Key is not specified.`);
|
||||
return;
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cache",
|
||||
"version": "3.2.2",
|
||||
"version": "3.2.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cache",
|
||||
"version": "3.2.2",
|
||||
"version": "3.2.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.1.2",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cache",
|
||||
"version": "3.2.2",
|
||||
"version": "3.2.3",
|
||||
"private": true,
|
||||
"description": "Cache dependencies and build outputs",
|
||||
"main": "dist/restore/index.js",
|
||||
|
||||
+1
-3
@@ -28,9 +28,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
|
||||
|
||||
// If restore has stored a primary key in state, reuse that
|
||||
// Else re-evaluate from inputs
|
||||
const primaryKey =
|
||||
stateProvider.getState(State.CachePrimaryKey) ||
|
||||
core.getInput(Inputs.Key);
|
||||
const primaryKey = stateProvider.getState(State.CachePrimaryKey);
|
||||
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Key is not specified.`);
|
||||
|
||||
+15
-4
@@ -1,6 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { Outputs, State } from "./constants";
|
||||
import { Inputs, Outputs, State } from "./constants";
|
||||
|
||||
export interface IStateProvider {
|
||||
setState(key: string, value: string): void;
|
||||
@@ -33,14 +33,25 @@ export class StateProvider extends StateProviderBase {
|
||||
}
|
||||
|
||||
export class NullStateProvider extends StateProviderBase {
|
||||
stateToInputMap = new Map<string, string>([
|
||||
[State.CachePrimaryKey, Inputs.Key]
|
||||
]);
|
||||
|
||||
stateToOutputMap = new Map<string, string>([
|
||||
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
||||
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
||||
]);
|
||||
|
||||
setState = (key: string, value: string) => {
|
||||
core.setOutput(this.stateToOutputMap.get(key) as string, value);
|
||||
if (this.stateToOutputMap.has(key)) {
|
||||
core.setOutput(this.stateToOutputMap.get(key) as string, value);
|
||||
}
|
||||
};
|
||||
|
||||
getState = (key: string) => {
|
||||
if (!this.stateToInputMap.has(key)) {
|
||||
return "";
|
||||
}
|
||||
return core.getInput(this.stateToInputMap.get(key) as string);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
getState = (key: string) => "";
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ export function setInput(name: string, value: string): void {
|
||||
process.env[getInputName(name)] = value;
|
||||
}
|
||||
|
||||
export function getInput(name: string): string {
|
||||
return process.env[getInputName(name)] as string;
|
||||
}
|
||||
|
||||
interface CacheInput {
|
||||
path: string;
|
||||
key: string;
|
||||
|
||||
+4
-17
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user