React to feeback and change to use 0.2.0 cache package

This commit is contained in:
Aiqiao Yan 2020-05-19 13:46:58 -04:00
parent 249a22026d
commit bcc23b930f
10 changed files with 5098 additions and 5604 deletions

View file

@ -4,11 +4,13 @@ on:
pull_request:
branches:
- master
- releases/**
paths-ignore:
- '**.md'
push:
branches:
- master
- releases/**
paths-ignore:
- '**.md'
@ -17,7 +19,7 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, ubuntu-16.04]
os: [ubuntu-latest, ubuntu-16.04, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
@ -61,7 +63,7 @@ jobs:
test-save:
strategy:
matrix:
os: [ubuntu-latest, ubuntu-16.04]
os: [ubuntu-latest, ubuntu-16.04, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
@ -84,7 +86,7 @@ jobs:
needs: test-save
strategy:
matrix:
os: [ubuntu-latest, ubuntu-16.04]
os: [ubuntu-latest, ubuntu-16.04, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:

View file

@ -79,7 +79,7 @@ test("setOutputAndState with exact match to set cache-hit output and state", ()
expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "true");
expect(setOutputMock).toHaveBeenCalledTimes(1);
expect(saveStateMock).toHaveBeenCalledWith(State.CacheResult, cacheKey);
expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey);
expect(saveStateMock).toHaveBeenCalledTimes(1);
});
@ -95,7 +95,7 @@ test("setOutputAndState with no exact match to set cache-hit output and state",
expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "false");
expect(setOutputMock).toHaveBeenCalledTimes(1);
expect(saveStateMock).toHaveBeenCalledWith(State.CacheResult, cacheKey);
expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey);
expect(saveStateMock).toHaveBeenCalledTimes(1);
});
@ -109,7 +109,7 @@ test("getCacheState with no state returns undefined", () => {
expect(state).toBe(undefined);
expect(getStateMock).toHaveBeenCalledWith(State.CacheResult);
expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey);
expect(getStateMock).toHaveBeenCalledTimes(1);
});
@ -125,7 +125,7 @@ test("getCacheState with valid state", () => {
expect(state).toEqual(cacheKey);
expect(getStateMock).toHaveBeenCalledWith(State.CacheResult);
expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey);
expect(getStateMock).toHaveBeenCalledTimes(1);
});

2244
dist/restore/index.js vendored

File diff suppressed because it is too large Load diff

2242
dist/save/index.js vendored

File diff suppressed because it is too large Load diff

6032
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.1",
"@actions/io": "^1.0.1",
"@actions/cache": "^0.1.0"
"@actions/cache": "^0.2.0"
},
"devDependencies": {
"@types/jest": "^24.0.13",

View file

@ -9,8 +9,8 @@ export enum Outputs {
}
export enum State {
CacheKey = "CACHE_KEY",
CacheResult = "CACHE_RESULT"
CachePrimaryKey = "CACHE_KEY",
CacheMatchedKey = "CACHE_RESULT"
}
export enum Events {

View file

@ -17,7 +17,7 @@ async function run(): Promise<void> {
}
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CacheKey, primaryKey);
core.saveState(State.CachePrimaryKey, primaryKey);
const restoreKeys = core
.getInput(Inputs.RestoreKeys)
@ -45,7 +45,7 @@ async function run(): Promise<void> {
return;
}
// Store the cache result
// Store the matched cache key
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);

View file

@ -18,7 +18,7 @@ async function run(): Promise<void> {
const state = utils.getCacheState();
// Inputs are re-evaluted before the post action, so we want the original key used for restore
const primaryKey = core.getState(State.CacheKey);
const primaryKey = core.getState(State.CachePrimaryKey);
if (!primaryKey) {
utils.logWarning(`Error retrieving key from state.`);
return;

View file

@ -12,7 +12,7 @@ export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
}
export function setCacheState(state: string): void {
core.saveState(State.CacheResult, state);
core.saveState(State.CacheMatchedKey, state);
}
export function setCacheHitOutput(isCacheHit: boolean): void {
@ -21,12 +21,12 @@ export function setCacheHitOutput(isCacheHit: boolean): void {
export function setOutputAndState(key: string, cacheKey?: string): void {
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
// Store the cache result if it exists
// Store the matched cache key if it exists
cacheKey && setCacheState(cacheKey);
}
export function getCacheState(): string | undefined {
const cacheKey = core.getState(State.CacheResult);
const cacheKey = core.getState(State.CacheMatchedKey);
if (cacheKey) {
core.debug(`Cache state/key: ${cacheKey}`);
return cacheKey;