mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-08-14 20:55:13 +00:00
chore: make config load from state explicit
Make the loading of config from state explicit by splitting into a dedicated static method.
This commit is contained in:
parent
68377a4bda
commit
c7502cd809
27
dist/restore/index.js
vendored
27
dist/restore/index.js
vendored
@ -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.
|
||||
*/
|
||||
|
29
dist/save/index.js
vendored
29
dist/save/index.js
vendored
@ -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
|
||||
|
@ -46,15 +46,6 @@ export class CacheConfig {
|
||||
*/
|
||||
static async new(): Promise<CacheConfig> {
|
||||
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.
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@ async function run() {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await CacheConfig.new();
|
||||
const config = CacheConfig.fromState();
|
||||
config.printInfo();
|
||||
core.info("");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user