mirror of
https://github.com/actions/cache.git
synced 2025-07-12 09:10:44 +00:00
Validate event type during restore
This commit is contained in:
parent
4b0709a0d5
commit
bae12fc444
4 changed files with 119 additions and 2 deletions
|
@ -12,3 +12,9 @@ export namespace State {
|
|||
export const CacheKey = "CACHE_KEY";
|
||||
export const CacheResult = "CACHE_RESULT";
|
||||
}
|
||||
|
||||
export namespace Events {
|
||||
export const Key = "GITHUB_EVENT_NAME";
|
||||
export const Push = "push";
|
||||
export const PullRequest = "pull_request";
|
||||
}
|
||||
|
|
|
@ -11,6 +11,12 @@ import * as utils from "./utils/actionUtils";
|
|||
async function run() {
|
||||
try {
|
||||
// Validate inputs, this can cause task failure
|
||||
if (!utils.isValidEvent()) {
|
||||
core.setFailed(
|
||||
`Event Validation Error: The event type ${process.env["GITHUB_EVENT_NAME"]} is not supported. Only \`push\` and \`pull_request\` events are supported at this time.`
|
||||
);
|
||||
}
|
||||
|
||||
let cachePath = utils.resolvePath(
|
||||
core.getInput(Inputs.Path, { required: true })
|
||||
);
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as os from "os";
|
|||
import * as path from "path";
|
||||
import * as uuidV4 from "uuid/v4";
|
||||
|
||||
import { Outputs, State } from "../constants";
|
||||
import { Events, Outputs, State } from "../constants";
|
||||
import { ArtifactCacheEntry } from "../contracts";
|
||||
|
||||
// From https://github.com/actions/toolkit/blob/master/packages/tool-cache/src/tool-cache.ts#L23
|
||||
|
@ -84,3 +84,11 @@ export function resolvePath(filePath: string): string {
|
|||
|
||||
return path.resolve(filePath);
|
||||
}
|
||||
|
||||
// Currently the cache token is only authorized for push and pull_request events
|
||||
// All other events will fail when reading and saving the cache
|
||||
// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context
|
||||
export function isValidEvent(): boolean {
|
||||
const githubEvent = process.env[Events.Key] || "";
|
||||
return githubEvent === Events.Push || githubEvent === Events.PullRequest;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue