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() {
|
static async new() {
|
||||||
const self = new CacheConfig();
|
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:
|
// Construct key prefix:
|
||||||
// This uses either the `shared-key` input,
|
// This uses either the `shared-key` input,
|
||||||
// or the `key` input combined with the `job` key.
|
// or the `key` input combined with the `job` key.
|
||||||
@ -60157,6 +60149,25 @@ class CacheConfig {
|
|||||||
self.cargoBins = Array.from(bins.values());
|
self.cargoBins = Array.from(bins.values());
|
||||||
return self;
|
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.
|
* 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() {
|
static async new() {
|
||||||
const self = new 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) => new Workspace(w.root, w.target));
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
// Construct key prefix:
|
// Construct key prefix:
|
||||||
// This uses either the `shared-key` input,
|
// This uses either the `shared-key` input,
|
||||||
// or the `key` input combined with the `job` key.
|
// or the `key` input combined with the `job` key.
|
||||||
@ -60157,6 +60149,25 @@ class CacheConfig {
|
|||||||
self.cargoBins = Array.from(bins.values());
|
self.cargoBins = Array.from(bins.values());
|
||||||
return self;
|
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.
|
* Prints the configuration to the action log.
|
||||||
*/
|
*/
|
||||||
@ -60470,7 +60481,7 @@ async function run() {
|
|||||||
core.info(`Cache up-to-date.`);
|
core.info(`Cache up-to-date.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const config = await CacheConfig["new"]();
|
const config = CacheConfig.fromState();
|
||||||
config.printInfo();
|
config.printInfo();
|
||||||
core.info("");
|
core.info("");
|
||||||
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
||||||
|
@ -46,15 +46,6 @@ export class CacheConfig {
|
|||||||
*/
|
*/
|
||||||
static async new(): Promise<CacheConfig> {
|
static async new(): Promise<CacheConfig> {
|
||||||
const self = new 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:
|
// Construct key prefix:
|
||||||
// This uses either the `shared-key` input,
|
// This uses either the `shared-key` input,
|
||||||
@ -177,6 +168,28 @@ export class CacheConfig {
|
|||||||
return self;
|
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.
|
* Prints the configuration to the action log.
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +25,7 @@ async function run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = await CacheConfig.new();
|
const config = CacheConfig.fromState();
|
||||||
config.printInfo();
|
config.printInfo();
|
||||||
core.info("");
|
core.info("");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user