mirror of
https://github.com/actions/cache.git
synced 2025-06-28 21:30:50 +02:00
Compare commits
11 Commits
phantsure/
...
kotewar/st
Author | SHA1 | Date | |
---|---|---|---|
f46bb21315 | |||
58c146cc91 | |||
6fd2d4538c | |||
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.
|
* 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.
|
* 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)
|
* 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
|
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.
|
* `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
|
* `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.
|
* `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
|
#### 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)
|
* `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)
|
- [Cache segment restore timeout](./tips-and-workarounds.md#cache-segment-restore-timeout)
|
||||||
- [Update a cache](./tips-and-workarounds.md#update-a-cache)
|
- [Update a cache](./tips-and-workarounds.md#update-a-cache)
|
||||||
- [Use cache across feature branches](./tips-and-workarounds.md#use-cache-across-feature-branches)
|
- [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)
|
- [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
|
#### Windows environment variables
|
||||||
|
@ -63,3 +63,7 @@
|
|||||||
|
|
||||||
### 3.2.2
|
### 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");
|
jest.mock("../src/utils/actionUtils");
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
jest.spyOn(core, "getInput").mockImplementation(name => {
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
return testUtils.getInput(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
jest.spyOn(core, "getState").mockImplementation(name => {
|
||||||
return jest.requireActual("@actions/core").getInput(key, value);
|
return jest.requireActual("@actions/core").getState(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
import { Events, RefKey, State } from "../src/constants";
|
import { Events, Inputs, RefKey, State } from "../src/constants";
|
||||||
import {
|
import {
|
||||||
IStateProvider,
|
IStateProvider,
|
||||||
NullStateProvider,
|
NullStateProvider,
|
||||||
StateProvider
|
StateProvider
|
||||||
} from "../src/stateProvider";
|
} from "../src/stateProvider";
|
||||||
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
|
|
||||||
jest.mock("@actions/core");
|
jest.mock("@actions/core");
|
||||||
|
|
||||||
@ -58,32 +59,43 @@ test("StateProvider saves states", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("NullStateProvider saves outputs", 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
|
const getStateMock = jest
|
||||||
.spyOn(core, "getState")
|
.spyOn(core, "getState")
|
||||||
.mockImplementation(name =>
|
.mockImplementation(key => {
|
||||||
jest.requireActual("@actions/core").getState(name)
|
return jest.requireActual("@actions/core").getState(key);
|
||||||
);
|
});
|
||||||
|
|
||||||
const setOutputMock = jest
|
const setOutputMock = jest
|
||||||
.spyOn(core, "setOutput")
|
.spyOn(core, "setOutput")
|
||||||
.mockImplementation((key, value) => {
|
.mockImplementation((key, value) => {
|
||||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
states.set(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const saveStateMock = jest
|
const saveStateMock = jest
|
||||||
.spyOn(core, "saveState")
|
.spyOn(core, "saveState")
|
||||||
.mockImplementation((key, value) => {
|
.mockImplementation((key, value) => {
|
||||||
return jest.requireActual("@actions/core").saveState(key, value);
|
states.set(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const cacheMatchedKey = "node-cache";
|
const cacheMatchedKey = "node-cache";
|
||||||
|
const cachePrimaryKey = "primary-key";
|
||||||
const nullStateProvider: IStateProvider = new NullStateProvider();
|
const nullStateProvider: IStateProvider = new NullStateProvider();
|
||||||
nullStateProvider.setState(State.CacheMatchedKey, "outputValue");
|
testUtils.setInput(Inputs.Key, cachePrimaryKey);
|
||||||
nullStateProvider.setState(State.CachePrimaryKey, cacheMatchedKey);
|
nullStateProvider.setState(State.CachePrimaryKey, cachePrimaryKey);
|
||||||
nullStateProvider.getState("outputKey");
|
nullStateProvider.setState(State.CacheMatchedKey, cacheMatchedKey);
|
||||||
nullStateProvider.getCacheState();
|
const output1 = nullStateProvider.getState(State.CachePrimaryKey);
|
||||||
|
const output2 = nullStateProvider.getCacheState();
|
||||||
|
|
||||||
expect(getStateMock).toHaveBeenCalledTimes(0);
|
expect(getStateMock).toHaveBeenCalledTimes(0);
|
||||||
|
expect(getInputMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(output1).toBe("primary-key");
|
||||||
|
expect(output2).toBe(undefined);
|
||||||
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
||||||
expect(saveStateMock).toHaveBeenCalledTimes(0);
|
expect(saveStateMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
13
dist/restore-only/index.js
vendored
13
dist/restore-only/index.js
vendored
@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
|||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
this.stateToInputMap = new Map([
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||||
|
]);
|
||||||
this.stateToOutputMap = new Map([
|
this.stateToOutputMap = new Map([
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
]);
|
]);
|
||||||
this.setState = (key, value) => {
|
this.setState = (key, value) => {
|
||||||
|
if (this.stateToOutputMap.has(key)) {
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
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;
|
exports.NullStateProvider = NullStateProvider;
|
||||||
|
13
dist/restore/index.js
vendored
13
dist/restore/index.js
vendored
@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
|||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
this.stateToInputMap = new Map([
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||||
|
]);
|
||||||
this.stateToOutputMap = new Map([
|
this.stateToOutputMap = new Map([
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
]);
|
]);
|
||||||
this.setState = (key, value) => {
|
this.setState = (key, value) => {
|
||||||
|
if (this.stateToOutputMap.has(key)) {
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
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;
|
exports.NullStateProvider = NullStateProvider;
|
||||||
|
16
dist/save-only/index.js
vendored
16
dist/save-only/index.js
vendored
@ -9469,15 +9469,24 @@ exports.StateProvider = StateProvider;
|
|||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
this.stateToInputMap = new Map([
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||||
|
]);
|
||||||
this.stateToOutputMap = new Map([
|
this.stateToOutputMap = new Map([
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
]);
|
]);
|
||||||
this.setState = (key, value) => {
|
this.setState = (key, value) => {
|
||||||
|
if (this.stateToOutputMap.has(key)) {
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
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;
|
exports.NullStateProvider = NullStateProvider;
|
||||||
@ -41164,8 +41173,7 @@ function saveImpl(stateProvider) {
|
|||||||
}
|
}
|
||||||
// If restore has stored a primary key in state, reuse that
|
// If restore has stored a primary key in state, reuse that
|
||||||
// Else re-evaluate from inputs
|
// Else re-evaluate from inputs
|
||||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey);
|
||||||
core.getInput(constants_1.Inputs.Key);
|
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Key is not specified.`);
|
utils.logWarning(`Key is not specified.`);
|
||||||
return;
|
return;
|
||||||
|
16
dist/save/index.js
vendored
16
dist/save/index.js
vendored
@ -9413,15 +9413,24 @@ exports.StateProvider = StateProvider;
|
|||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
this.stateToInputMap = new Map([
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Inputs.Key]
|
||||||
|
]);
|
||||||
this.stateToOutputMap = new Map([
|
this.stateToOutputMap = new Map([
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
]);
|
]);
|
||||||
this.setState = (key, value) => {
|
this.setState = (key, value) => {
|
||||||
|
if (this.stateToOutputMap.has(key)) {
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
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;
|
exports.NullStateProvider = NullStateProvider;
|
||||||
@ -41108,8 +41117,7 @@ function saveImpl(stateProvider) {
|
|||||||
}
|
}
|
||||||
// If restore has stored a primary key in state, reuse that
|
// If restore has stored a primary key in state, reuse that
|
||||||
// Else re-evaluate from inputs
|
// Else re-evaluate from inputs
|
||||||
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||
|
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey);
|
||||||
core.getInput(constants_1.Inputs.Key);
|
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Key is not specified.`);
|
utils.logWarning(`Key is not specified.`);
|
||||||
return;
|
return;
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "3.2.2",
|
"version": "3.2.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "3.2.2",
|
"version": "3.2.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.1.2",
|
"@actions/cache": "^3.1.2",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "3.2.2",
|
"version": "3.2.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
|
@ -28,9 +28,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
|
|||||||
|
|
||||||
// If restore has stored a primary key in state, reuse that
|
// If restore has stored a primary key in state, reuse that
|
||||||
// Else re-evaluate from inputs
|
// Else re-evaluate from inputs
|
||||||
const primaryKey =
|
const primaryKey = stateProvider.getState(State.CachePrimaryKey);
|
||||||
stateProvider.getState(State.CachePrimaryKey) ||
|
|
||||||
core.getInput(Inputs.Key);
|
|
||||||
|
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Key is not specified.`);
|
utils.logWarning(`Key is not specified.`);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
import { Outputs, State } from "./constants";
|
import { Inputs, Outputs, State } from "./constants";
|
||||||
|
|
||||||
export interface IStateProvider {
|
export interface IStateProvider {
|
||||||
setState(key: string, value: string): void;
|
setState(key: string, value: string): void;
|
||||||
@ -33,14 +33,25 @@ export class StateProvider extends StateProviderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class NullStateProvider extends StateProviderBase {
|
export class NullStateProvider extends StateProviderBase {
|
||||||
|
stateToInputMap = new Map<string, string>([
|
||||||
|
[State.CachePrimaryKey, Inputs.Key]
|
||||||
|
]);
|
||||||
|
|
||||||
stateToOutputMap = new Map<string, string>([
|
stateToOutputMap = new Map<string, string>([
|
||||||
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
||||||
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setState = (key: string, value: string) => {
|
setState = (key: string, value: string) => {
|
||||||
|
if (this.stateToOutputMap.has(key)) {
|
||||||
core.setOutput(this.stateToOutputMap.get(key) as string, value);
|
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;
|
process.env[getInputName(name)] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getInput(name: string): string {
|
||||||
|
return process.env[getInputName(name)] as string;
|
||||||
|
}
|
||||||
|
|
||||||
interface CacheInput {
|
interface CacheInput {
|
||||||
path: string;
|
path: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
@ -19,23 +19,10 @@ A cache today is immutable and cannot be updated. But some use cases require the
|
|||||||
## Use cache across feature branches
|
## Use cache across feature branches
|
||||||
Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches.
|
Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches.
|
||||||
|
|
||||||
## Improving cache restore performance on Windows/Using cross-os caching
|
## Cross OS cache
|
||||||
Currently, cache restore is slow on Windows due to tar being inherently slow and the compression algorithm `gzip` in use. `zstd` is the default algorithm in use on linux and macos. It was disabled on Windows due to issues with bsd tar(libarchive), the tar implementation in use on Windows.
|
From `v3.2.3` cache is cross-os compatible when `enableCrossOsArchive` input is passed as true. This means that a cache created on `ubuntu-latest` or `mac-latest` can be used by `windows-latest` and vice versa, provided the workflow which runs on `windows-latest` have input `enableCrossOsArchive` as true. This is useful to cache dependencies which are independent of the runner platform. This will help reduce the consumption of the cache quota and help build for multiple platforms from the same cache. Things to keep in mind while using this feature:
|
||||||
|
- Only cache those files which are compatible across OSs.
|
||||||
To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround. Add the following step to your workflow before the cache step:
|
- Caching symlinks might cause issues while restoration as they work differently on different OSs.
|
||||||
|
|
||||||
```yaml
|
|
||||||
- if: ${{ runner.os == 'Windows' }}
|
|
||||||
name: Use GNU tar
|
|
||||||
shell: cmd
|
|
||||||
run: |
|
|
||||||
echo "Adding GNU tar to PATH"
|
|
||||||
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
|
|
||||||
```
|
|
||||||
|
|
||||||
The `cache` action will use GNU tar instead of bsd tar on Windows. This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed.
|
|
||||||
|
|
||||||
The above workaround is also needed if you wish to use cross-os caching since difference of compression algorithms will result in different cache versions for the same cache key. So the above workaround will ensure `zstd` is used for caching on all platforms thus resulting in the same cache version for the same cache key.
|
|
||||||
|
|
||||||
## Force deletion of caches overriding default cache eviction policy
|
## Force deletion of caches overriding default cache eviction policy
|
||||||
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches.
|
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches.
|
||||||
|
Reference in New Issue
Block a user