Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save cache on the end of the job (#1328)
* improve document of cache * save cache on the end of the job * npm run format * fix the path for versions json * fix the package path * fix the package path in the tests * fix path
- Loading branch information
1 parent
cae9fc4
commit a04ef8d
Showing
11 changed files
with
94 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as core from "@actions/core"; | ||
import * as cache from "@actions/cache"; | ||
import { State } from "./constants"; | ||
|
||
async function run() { | ||
try { | ||
const cachePath = core.getState(State.CachePath); | ||
const key = core.getState(State.CachePrimaryKey); | ||
const cachedKey = core.getState(State.CacheMatchedKey); | ||
const paths = [cachePath]; | ||
// save cache | ||
if (cachedKey !== key) { | ||
core.info(`saving cache for ${key}.`); | ||
try { | ||
await cache.saveCache(paths, key); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
if (error.name === cache.ValidationError.name) { | ||
throw error; | ||
} else if (error.name === cache.ReserveCacheError.name) { | ||
core.info(error.message); | ||
} else { | ||
core.info(`[warning]${error.message}`); | ||
} | ||
} else { | ||
core.info(`[warning]${error}`); | ||
} | ||
} | ||
} else { | ||
core.info(`cache for ${key} already exists, skip saving.`); | ||
} | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
core.setFailed(error); | ||
} else { | ||
core.setFailed(`${error}`); | ||
} | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum State { | ||
CachePrimaryKey = "CACHE_KEY", | ||
CacheMatchedKey = "CACHE_RESULT", | ||
CachePath = "CACHE_PATH", | ||
} | ||
|
||
export enum Outputs { | ||
CacheHit = "cache-hit", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters