mirror of
https://github.com/actions/cache.git
synced 2026-06-20 17:34:01 +08:00
Compare commits
3 Commits
23a08d8e80
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa463d1c18 | ||
|
|
5656298164 | ||
|
|
4e380d19e1 |
@@ -100,8 +100,6 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
|
||||
* `cache-hit` - A string value to indicate an exact match was found for the key.
|
||||
* If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
|
||||
* If there's a cache miss, this will be an empty string.
|
||||
* `cache-primary-key` - Cache primary key passed in the input to use in subsequent steps of the workflow.
|
||||
* `cache-matched-key` - Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys.
|
||||
|
||||
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ test("restore with cache found for key", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -173,10 +173,8 @@ test("restore with cache found for key", async () => {
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
@@ -196,7 +194,7 @@ test("restore with cache found for restore key", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -220,10 +218,8 @@ test("restore with cache found for restore key", async () => {
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
@@ -243,7 +239,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
||||
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -264,8 +260,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
|
||||
@@ -287,7 +282,7 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -311,10 +306,8 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
|
||||
@@ -112,7 +112,7 @@ test("restore on GHES with AC available ", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -133,10 +133,8 @@ test("restore on GHES with AC available ", async () => {
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
@@ -336,7 +334,7 @@ test("restore with cache found for key", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -357,10 +355,8 @@ test("restore with cache found for key", async () => {
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
@@ -380,7 +376,7 @@ test("restore with cache found for restore key", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -401,10 +397,8 @@ test("restore with cache found for restore key", async () => {
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
@@ -423,7 +417,7 @@ test("restore with lookup-only set", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
@@ -447,10 +441,8 @@ test("restore with lookup-only set", async () => {
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache found and can be restored from key: ${key}`
|
||||
|
||||
@@ -54,7 +54,7 @@ test("StateProvider saves states", async () => {
|
||||
expect(cacheStateValue).toBe(cacheMatchedKey);
|
||||
expect(getStateMock).toHaveBeenCalledTimes(2);
|
||||
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("NullStateProvider saves outputs", async () => {
|
||||
|
||||
@@ -37,10 +37,6 @@ inputs:
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
cache-primary-key:
|
||||
description: 'A resolved cache key for which cache match was attempted'
|
||||
cache-matched-key:
|
||||
description: 'Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys'
|
||||
runs:
|
||||
using: 'node24'
|
||||
main: 'dist/restore/index.js'
|
||||
|
||||
17
dist/restore-only/index.js
vendored
17
dist/restore-only/index.js
vendored
@@ -46382,22 +46382,21 @@ class StateProviderBase {
|
||||
class StateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||
this.setState = core.saveState;
|
||||
this.getState = core.getState;
|
||||
}
|
||||
}
|
||||
exports.StateProvider = StateProvider;
|
||||
const stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
function stateToOutput(key, value) {
|
||||
core.setOutput(stateToOutputMap.get(key), value);
|
||||
}
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = stateToOutput;
|
||||
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);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
|
||||
17
dist/restore/index.js
vendored
17
dist/restore/index.js
vendored
@@ -46382,22 +46382,21 @@ class StateProviderBase {
|
||||
class StateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||
this.setState = core.saveState;
|
||||
this.getState = core.getState;
|
||||
}
|
||||
}
|
||||
exports.StateProvider = StateProvider;
|
||||
const stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
function stateToOutput(key, value) {
|
||||
core.setOutput(stateToOutputMap.get(key), value);
|
||||
}
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = stateToOutput;
|
||||
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);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
|
||||
17
dist/save-only/index.js
vendored
17
dist/save-only/index.js
vendored
@@ -46395,22 +46395,21 @@ class StateProviderBase {
|
||||
class StateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||
this.setState = core.saveState;
|
||||
this.getState = core.getState;
|
||||
}
|
||||
}
|
||||
exports.StateProvider = StateProvider;
|
||||
const stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
function stateToOutput(key, value) {
|
||||
core.setOutput(stateToOutputMap.get(key), value);
|
||||
}
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = stateToOutput;
|
||||
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);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
|
||||
17
dist/save/index.js
vendored
17
dist/save/index.js
vendored
@@ -46395,22 +46395,21 @@ class StateProviderBase {
|
||||
class StateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||
this.setState = core.saveState;
|
||||
this.getState = core.getState;
|
||||
}
|
||||
}
|
||||
exports.StateProvider = StateProvider;
|
||||
const stateToOutputMap = new Map([
|
||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||
]);
|
||||
function stateToOutput(key, value) {
|
||||
core.setOutput(stateToOutputMap.get(key), value);
|
||||
}
|
||||
class NullStateProvider extends StateProviderBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.setState = stateToOutput;
|
||||
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);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
this.getState = (key) => "";
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
with:
|
||||
path: |
|
||||
~/.bun/install/cache
|
||||
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
|
||||
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
|
||||
```
|
||||
|
||||
### Windows
|
||||
@@ -59,7 +59,7 @@
|
||||
with:
|
||||
path: |
|
||||
~\.bun
|
||||
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
|
||||
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
|
||||
```
|
||||
|
||||
## C# - NuGet
|
||||
|
||||
5542
package-lock.json
generated
5542
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@
|
||||
"@actions/io": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/nock": "^11.1.0",
|
||||
"@types/node": "^24.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||
@@ -41,7 +41,7 @@
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-prettier": "^5.5.3",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"jest": "^29.7.0",
|
||||
"jest": "^30.2.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"nock": "^13.2.9",
|
||||
"prettier": "^3.6.2",
|
||||
|
||||
@@ -28,22 +28,19 @@ class StateProviderBase implements IStateProvider {
|
||||
}
|
||||
|
||||
export class StateProvider extends StateProviderBase {
|
||||
setState = (key: string, value: string) => {
|
||||
core.saveState(key, value);
|
||||
stateToOutput(key, value);
|
||||
};
|
||||
setState = core.saveState;
|
||||
getState = core.getState;
|
||||
}
|
||||
|
||||
const stateToOutputMap = new Map<string, string>([
|
||||
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
||||
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
||||
]);
|
||||
function stateToOutput(key: string, value: string) {
|
||||
core.setOutput(stateToOutputMap.get(key) as string, value);
|
||||
}
|
||||
export class NullStateProvider extends StateProviderBase {
|
||||
setState = stateToOutput;
|
||||
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);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
getState = (key: string) => "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user