Permalink
Cannot retrieve contributors at this time
65 lines (55 sloc)
1.94 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
github-actions-cache/src/restore.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
import * as cache from "@actions/cache"; | |
import * as core from "@actions/core"; | |
import { Events, Inputs, State } from "./constants"; | |
import * as utils from "./utils/actionUtils"; | |
async function run(): Promise<void> { | |
try { | |
// Validate inputs, this can cause task failure | |
if (!utils.isValidEvent()) { | |
utils.logWarning( | |
`Event Validation Error: The event type ${ | |
process.env[Events.Key] | |
} is not supported because it's not tied to a branch or tag ref.` | |
); | |
return; | |
} | |
const primaryKey = core.getInput(Inputs.Key, { required: true }); | |
core.saveState(State.CachePrimaryKey, primaryKey); | |
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys); | |
const cachePaths = utils.getInputAsArray(Inputs.Path, { | |
required: true | |
}); | |
try { | |
const cacheKey = await cache.restoreCache( | |
cachePaths, | |
primaryKey, | |
restoreKeys | |
); | |
if (!cacheKey) { | |
core.info( | |
`Cache not found for input keys: ${[ | |
primaryKey, | |
...restoreKeys | |
].join(", ")}` | |
); | |
return; | |
} | |
// Store the matched cache key | |
utils.setCacheState(cacheKey); | |
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); | |
utils.setCacheHitOutput(isExactKeyMatch); | |
core.info(`Cache restored from key: ${cacheKey}`); | |
} catch (error) { | |
if (error.name === cache.ValidationError.name) { | |
throw error; | |
} else { | |
utils.logWarning(error.message); | |
utils.setCacheHitOutput(false); | |
} | |
} | |
} catch (error) { | |
core.setFailed(error.message); | |
} | |
} | |
run(); | |
export default run; |