diff --git a/dist/restore/index.js b/dist/restore/index.js index 5bf6892..39525a6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -60056,14 +60056,6 @@ class CacheConfig { */ static async new() { const self = new CacheConfig(); - const source = lib_core.getState(STATE_CONFIG); - if (source !== "") { - // Post action, use what we calculated in the main action ensuring consistency. - Object.assign(self, JSON.parse(source)); - self.workspaces = self.workspaces - .map((w) => new Workspace(w.root, w.target)); - return self; - } // Construct key prefix: // This uses either the `shared-key` input, // or the `key` input combined with the `job` key. @@ -60157,6 +60149,25 @@ class CacheConfig { self.cargoBins = Array.from(bins.values()); return self; } + /** + * Reads and returns the cache config from the action `state`. + * + * @throws {Error} if the state is not present. + * @returns {CacheConfig} the configuration. + * @see {@link CacheConfig#saveState} + * @see {@link CacheConfig#new} + */ + static fromState() { + const source = lib_core.getState(STATE_CONFIG); + if (!source) { + throw new Error("Cache configuration not found in state"); + } + const self = new CacheConfig(); + Object.assign(self, JSON.parse(source)); + self.workspaces = self.workspaces + .map((w) => new Workspace(w.root, w.target)); + return self; + } /** * Prints the configuration to the action log. */ diff --git a/dist/save/index.js b/dist/save/index.js index 24b256f..c0bd395 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -60056,14 +60056,6 @@ class CacheConfig { */ static async new() { const self = new CacheConfig(); - const source = core.getState(STATE_CONFIG); - if (source !== "") { - // Post action, use what we calculated in the main action ensuring consistency. - Object.assign(self, JSON.parse(source)); - self.workspaces = self.workspaces - .map((w) => new Workspace(w.root, w.target)); - return self; - } // Construct key prefix: // This uses either the `shared-key` input, // or the `key` input combined with the `job` key. @@ -60157,6 +60149,25 @@ class CacheConfig { self.cargoBins = Array.from(bins.values()); return self; } + /** + * Reads and returns the cache config from the action `state`. + * + * @throws {Error} if the state is not present. + * @returns {CacheConfig} the configuration. + * @see {@link CacheConfig#saveState} + * @see {@link CacheConfig#new} + */ + static fromState() { + const source = core.getState(STATE_CONFIG); + if (!source) { + throw new Error("Cache configuration not found in state"); + } + const self = new CacheConfig(); + Object.assign(self, JSON.parse(source)); + self.workspaces = self.workspaces + .map((w) => new Workspace(w.root, w.target)); + return self; + } /** * Prints the configuration to the action log. */ @@ -60470,7 +60481,7 @@ async function run() { core.info(`Cache up-to-date.`); return; } - const config = await CacheConfig["new"](); + const config = CacheConfig.fromState(); config.printInfo(); core.info(""); // TODO: remove this once https://github.com/actions/toolkit/pull/553 lands diff --git a/src/config.ts b/src/config.ts index f6e20ad..64e161c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -46,15 +46,6 @@ export class CacheConfig { */ static async new(): Promise { const self = new CacheConfig(); - const source = core.getState(STATE_CONFIG); - if (source !== "") { - // Post action, use what we calculated in the main action ensuring consistency. - Object.assign(self, JSON.parse(source)); - self.workspaces = self.workspaces - .map((w: any) => new Workspace(w.root, w.target)); - - return self; - } // Construct key prefix: // This uses either the `shared-key` input, @@ -177,6 +168,28 @@ export class CacheConfig { return self; } + /** + * Reads and returns the cache config from the action `state`. + * + * @throws {Error} if the state is not present. + * @returns {CacheConfig} the configuration. + * @see {@link CacheConfig#saveState} + * @see {@link CacheConfig#new} + */ + static fromState(): CacheConfig { + const source = core.getState(STATE_CONFIG); + if (!source) { + throw new Error("Cache configuration not found in state"); + } + + const self = new CacheConfig(); + Object.assign(self, JSON.parse(source)); + self.workspaces = self.workspaces + .map((w: any) => new Workspace(w.root, w.target)); + + return self; + } + /** * Prints the configuration to the action log. */ diff --git a/src/save.ts b/src/save.ts index 94adb28..b862f14 100644 --- a/src/save.ts +++ b/src/save.ts @@ -25,7 +25,7 @@ async function run() { return; } - const config = await CacheConfig.new(); + const config = CacheConfig.fromState(); config.printInfo(); core.info("");