3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-04-26 21:35:35 +00:00

Slightly improve docs

This commit is contained in:
Arpad Borsos 2023-08-02 12:46:45 +02:00
parent f6987ea139
commit 3312b3ab47
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
7 changed files with 126 additions and 114 deletions

57
dist/save/index.js vendored
View file

@ -66790,8 +66790,6 @@ var external_path_ = __nccwpck_require__(1017);
var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
var glob = __nccwpck_require__(8090);
// EXTERNAL MODULE: ./node_modules/toml/index.js
var toml = __nccwpck_require__(4920);
// EXTERNAL MODULE: external "crypto"
var external_crypto_ = __nccwpck_require__(6113);
var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto_);
@ -66801,10 +66799,12 @@ var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_);
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(2037);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
// EXTERNAL MODULE: ./node_modules/toml/index.js
var toml = __nccwpck_require__(4920);
// EXTERNAL MODULE: ./node_modules/@actions/buildjet-cache/lib/cache.js
var cache = __nccwpck_require__(7551);
var lib_cache = __nccwpck_require__(7551);
// EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js
var lib_cache = __nccwpck_require__(7799);
var cache_lib_cache = __nccwpck_require__(7799);
;// CONCATENATED MODULE: ./src/utils.ts
@ -66846,18 +66846,16 @@ async function getCmdOutput(cmd, args = [], options = {}) {
}
return stdout;
}
function getCacheHandler() {
function getCacheProvider() {
const cacheProvider = core.getInput("cache-provider");
switch (cacheProvider) {
case "github":
core.info("Using Github Cache.");
return lib_cache;
case "buildjet":
core.info("Using Buildjet Cache.");
return cache;
default:
throw new Error("Only currently support github and buildjet caches");
const cache = cacheProvider === "github" ? cache_lib_cache : cacheProvider === "buildjet" ? lib_cache : undefined;
if (!cache) {
throw new Error(`The \`cache-provider\` \`{cacheProvider}\` is not valid.`);
}
return {
name: cacheProvider,
cache: cache,
};
}
;// CONCATENATED MODULE: ./src/workspace.ts
@ -67007,7 +67005,7 @@ class CacheConfig {
const cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`));
for (const cargo_manifest of cargo_manifests) {
try {
const content = await promises_default().readFile(cargo_manifest, { encoding: 'utf8' });
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
const parsed = toml.parse(content);
if ("package" in parsed) {
const pack = parsed.package;
@ -67024,21 +67022,22 @@ class CacheConfig {
for (const key of Object.keys(deps)) {
const dep = deps[key];
if ("path" in dep) {
dep.version = '0.0.0';
dep.version = "0.0.0";
}
}
}
hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest);
}
catch (_e) { // Fallback to caching them as regular file
catch (_e) {
// Fallback to caching them as regular file
keyFiles.push(cargo_manifest);
}
}
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`));
for (const cargo_lock of cargo_locks) {
try {
const content = await promises_default().readFile(cargo_lock, { encoding: 'utf8' });
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content);
if (parsed.version !== 3 || !("package" in parsed)) {
// Fallback to caching them as regular file since this action
@ -67054,7 +67053,8 @@ class CacheConfig {
hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock);
}
catch (_e) { // Fallback to caching them as regular file
catch (_e) {
// Fallback to caching them as regular file
keyFiles.push(cargo_lock);
}
}
@ -67098,15 +67098,16 @@ class CacheConfig {
}
const self = new CacheConfig();
Object.assign(self, JSON.parse(source));
self.workspaces = self.workspaces
.map((w) => new Workspace(w.root, w.target));
self.workspaces = self.workspaces.map((w) => new Workspace(w.root, w.target));
return self;
}
/**
* Prints the configuration to the action log.
*/
printInfo() {
printInfo(cacheProvider) {
core.startGroup("Cache Configuration");
core.info(`Cache Provider:`);
core.info(` ${cacheProvider.name}`);
core.info(`Workspaces:`);
for (const workspace of this.workspaces) {
core.info(` ${workspace.root}`);
@ -67173,7 +67174,7 @@ async function globFiles(pattern) {
// fs.statSync resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved
// file is actually a regular file.
return (await globber.glob()).filter(file => external_fs_default().statSync(file).isFile());
return (await globber.glob()).filter((file) => external_fs_default().statSync(file).isFile());
}
function sort_and_uniq(a) {
return a
@ -67476,9 +67477,9 @@ process.on("uncaughtException", (e) => {
}
});
async function run() {
const cache = getCacheHandler();
const cacheProvider = getCacheProvider();
const save = core.getInput("save-if").toLowerCase() || "true";
if (!(cache.isFeatureAvailable() && save === "true")) {
if (!(cacheProvider.cache.isFeatureAvailable() && save === "true")) {
return;
}
try {
@ -67487,7 +67488,7 @@ async function run() {
return;
}
const config = CacheConfig.fromState();
config.printInfo();
config.printInfo(cacheProvider);
core.info("");
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
await macOsWorkaround();
@ -67505,7 +67506,7 @@ async function run() {
}
try {
const crates = core.getInput("cache-all-crates").toLowerCase() || "false";
core.info(`... Cleaning cargo registry cache-all-crates: ${crates} ...`);
core.info(`... Cleaning cargo registry (cache-all-crates: ${crates}) ...`);
await cleanRegistry(allPackages, crates !== "true");
}
catch (e) {
@ -67529,7 +67530,7 @@ async function run() {
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed.
await cache.saveCache(config.cachePaths.slice(), config.cacheKey);
await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey);
}
catch (e) {
reportError(e);