From bac73aa464693974c1e59bffb650ad74842d79aa Mon Sep 17 00:00:00 2001 From: h0x0er Date: Mon, 26 Sep 2022 22:25:28 +0530 Subject: [PATCH] checking cache event in pre-step --- src/setup.ts | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/setup.ts b/src/setup.ts index 9043d44b..fbf4f17f 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -8,7 +8,13 @@ import * as common from "./common"; import * as tc from "@actions/tool-cache"; import { verifyChecksum } from "./checksum"; import isDocker from "is-docker"; -import { cacheFile, cacheKey, CompressionMethod, getCacheEntry } from "./cache"; +import { + cacheFile, + cacheKey, + CompressionMethod, + getCacheEntry, + isValidEvent, +} from "./cache"; (async () => { try { @@ -39,21 +45,21 @@ import { cacheFile, cacheKey, CompressionMethod, getCacheEntry } from "./cache"; disable_telemetry: core.getBooleanInput("disable-telemetry"), }; - try { - const cacheEntry = await getCacheEntry([cacheKey], [cacheFile], { - compressionMethod: CompressionMethod.ZstdWithoutLong, - }); - const url = new URL(cacheEntry.archiveLocation); - core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`); - confg.allowed_endpoints += ` ${url.hostname}:443`; - } catch (exception) { - // some exception has occurred. - core.info("Unable to fetch cacheURL"); - if (confg.egress_policy === "block") { - core.warning( - "Unable to fetch cacheURL switching egress-policy to audit mode" - ); - confg.egress_policy = "audit"; + if (isValidEvent()) { + try { + const cacheEntry = await getCacheEntry([cacheKey], [cacheFile], { + compressionMethod: CompressionMethod.ZstdWithoutLong, + }); + const url = new URL(cacheEntry.archiveLocation); + core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`); + confg.allowed_endpoints += ` ${url.hostname}:443`; + } catch (exception) { + // some exception has occurred. + core.info("Unable to fetch cacheURL"); + if (confg.egress_policy === "block") { + core.info("Switching egress-policy to audit mode"); + confg.egress_policy = "audit"; + } } }