From e5292ca57c0cfaa59bdf9176981c3f729cbcc19f Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Wed, 13 Sep 2023 10:42:05 +0800 Subject: [PATCH] wip --- build/fingerprint-post/index.js | 43 ++++++++++++++++++++++----------- build/fingerprint/index.js | 43 ++++++++++++++++++++++----------- build/preview-build/index.js | 38 +++++++++++++++++++---------- build/setup/index.js | 38 +++++++++++++++++++---------- src/actions/fingerprint.ts | 2 +- src/actions/preview-build.ts | 2 +- src/actions/setup.ts | 2 +- src/cacher.ts | 39 ++++++++++++++++++++---------- src/sqlite.ts | 5 +++- 9 files changed, 141 insertions(+), 71 deletions(-) diff --git a/build/fingerprint-post/index.js b/build/fingerprint-post/index.js index 512a0651..e5fa5e55 100644 --- a/build/fingerprint-post/index.js +++ b/build/fingerprint-post/index.js @@ -77509,40 +77509,52 @@ function cacheKey(name, version, manager) { return `${name}-${process.platform}-${external_os_default().arch()}-${manager}-${version}`; } /** - * Restore a tool from the remote cache. - * This will install the tool back into the local tool cache. + * Restore a directory from the remote cache. */ -async function restoreFromCache(name, version, manager) { - const dir = toolPath(name, version); +async function restoreCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped restoring from remote cache, not available.`); - return undefined; + return null; } try { - if (await (0,cache.restoreCache)([dir], cacheKey(name, version, manager))) { - return dir; + if (await (0,cache.restoreCache)([cachePath], cacheKey)) { + return cachePath; } } catch (error) { handleCacheError(error); } + return null; } /** - * Save a tool to the remote cache. - * This will fetch the tool from the local tool cache. + * Save a directory to the remote cache. */ -async function saveToCache(name, version, manager) { +async function saveCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped saving to remote cache, not available.`); - return undefined; + return; } try { - await (0,cache.saveCache)([toolPath(name, version)], cacheKey(name, version, manager)); + await (0,cache.saveCache)([cachePath], cacheKey); } catch (error) { handleCacheError(error); } } +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +function restoreFromCache(name, version, manager) { + return restoreCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +function saveToCache(name, version, manager) { + return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} /** * Try to handle incoming cache errors. * Because workers can operate in environments without cache configured, @@ -77637,6 +77649,7 @@ async function installPackage(name, version, manager) { + /** * Open a database and return a promise that resolves to a database object. */ @@ -77673,7 +77686,7 @@ async function installSQLiteAsync(packager) { const version = await resolvePackage(packageName, sqliteVersion); const message = `Installing ${packageName} (${version}) from cache or with ${packager}`; return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || undefined; + let libRoot = (0,tool_cache.find)(packageName, version) || null; console.log('ooxx0', libRoot); if (!libRoot) { libRoot = await restoreFromCache(packageName, version, packager); @@ -77684,6 +77697,8 @@ async function installSQLiteAsync(packager) { await saveToCache(packageName, version, packager); } console.log('ooxx2', libRoot); + const { stdout } = await (0,lib_exec.getExecOutput)('find', [libRoot, '-ls']); + console.log('ooxx stdout', stdout); addGlobalNodeSearchPath(libRoot); return libRoot; }); @@ -77877,7 +77892,7 @@ async function installFingerprintAsync(input) { ? `Installing ${packageName} (${version}) from cache or with ${input.packager}` : `Installing ${packageName} (${version}) with ${input.packager}`; return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || undefined; + let libRoot = (0,tool_cache.find)(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, input.packager); } diff --git a/build/fingerprint/index.js b/build/fingerprint/index.js index 1b7b22f9..17cfba81 100644 --- a/build/fingerprint/index.js +++ b/build/fingerprint/index.js @@ -77514,40 +77514,52 @@ function cacheKey(name, version, manager) { return `${name}-${process.platform}-${external_os_default().arch()}-${manager}-${version}`; } /** - * Restore a tool from the remote cache. - * This will install the tool back into the local tool cache. + * Restore a directory from the remote cache. */ -async function restoreFromCache(name, version, manager) { - const dir = toolPath(name, version); +async function restoreCacheAsync(cachePath, cacheKey) { if (!cacher_cacheIsAvailable()) { (0,core.warning)(`Skipped restoring from remote cache, not available.`); - return undefined; + return null; } try { - if (await (0,cache.restoreCache)([dir], cacheKey(name, version, manager))) { - return dir; + if (await (0,cache.restoreCache)([cachePath], cacheKey)) { + return cachePath; } } catch (error) { cacher_handleCacheError(error); } + return null; } /** - * Save a tool to the remote cache. - * This will fetch the tool from the local tool cache. + * Save a directory to the remote cache. */ -async function saveToCache(name, version, manager) { +async function saveCacheAsync(cachePath, cacheKey) { if (!cacher_cacheIsAvailable()) { (0,core.warning)(`Skipped saving to remote cache, not available.`); - return undefined; + return; } try { - await (0,cache.saveCache)([toolPath(name, version)], cacheKey(name, version, manager)); + await (0,cache.saveCache)([cachePath], cacheKey); } catch (error) { cacher_handleCacheError(error); } } +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +function restoreFromCache(name, version, manager) { + return restoreCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +function saveToCache(name, version, manager) { + return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} /** * Try to handle incoming cache errors. * Because workers can operate in environments without cache configured, @@ -77640,6 +77652,7 @@ async function installPackage(name, version, manager) { + /** * Open a database and return a promise that resolves to a database object. */ @@ -77676,7 +77689,7 @@ async function installSQLiteAsync(packager) { const version = await resolvePackage(packageName, sqliteVersion); const message = `Installing ${packageName} (${version}) from cache or with ${packager}`; return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || undefined; + let libRoot = (0,tool_cache.find)(packageName, version) || null; console.log('ooxx0', libRoot); if (!libRoot) { libRoot = await restoreFromCache(packageName, version, packager); @@ -77687,6 +77700,8 @@ async function installSQLiteAsync(packager) { await saveToCache(packageName, version, packager); } console.log('ooxx2', libRoot); + const { stdout } = await (0,lib_exec.getExecOutput)('find', [libRoot, '-ls']); + console.log('ooxx stdout', stdout); addGlobalNodeSearchPath(libRoot); return libRoot; }); @@ -77878,7 +77893,7 @@ async function installFingerprintAsync(input) { ? `Installing ${packageName} (${version}) from cache or with ${input.packager}` : `Installing ${packageName} (${version}) with ${input.packager}`; return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || undefined; + let libRoot = (0,tool_cache.find)(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, input.packager); } diff --git a/build/preview-build/index.js b/build/preview-build/index.js index ecb58a68..05aca6da 100644 --- a/build/preview-build/index.js +++ b/build/preview-build/index.js @@ -75485,40 +75485,52 @@ function cacheKey(name, version, manager) { return `${name}-${process.platform}-${external_os_default().arch()}-${manager}-${version}`; } /** - * Restore a tool from the remote cache. - * This will install the tool back into the local tool cache. + * Restore a directory from the remote cache. */ -async function restoreFromCache(name, version, manager) { - const dir = toolPath(name, version); +async function restoreCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped restoring from remote cache, not available.`); - return undefined; + return null; } try { - if (await (0,cache.restoreCache)([dir], cacheKey(name, version, manager))) { - return dir; + if (await (0,cache.restoreCache)([cachePath], cacheKey)) { + return cachePath; } } catch (error) { handleCacheError(error); } + return null; } /** - * Save a tool to the remote cache. - * This will fetch the tool from the local tool cache. + * Save a directory to the remote cache. */ -async function saveToCache(name, version, manager) { +async function saveCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped saving to remote cache, not available.`); - return undefined; + return; } try { - await (0,cache.saveCache)([toolPath(name, version)], cacheKey(name, version, manager)); + await (0,cache.saveCache)([cachePath], cacheKey); } catch (error) { handleCacheError(error); } } +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +function restoreFromCache(name, version, manager) { + return restoreCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +function saveToCache(name, version, manager) { + return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} /** * Try to handle incoming cache errors. * Because workers can operate in environments without cache configured, @@ -75788,7 +75800,7 @@ async function installFingerprintAsync(input) { ? `Installing ${packageName} (${version}) from cache or with ${input.packager}` : `Installing ${packageName} (${version}) with ${input.packager}`; return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || undefined; + let libRoot = (0,tool_cache.find)(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, input.packager); } diff --git a/build/setup/index.js b/build/setup/index.js index aa38f1e6..9dda13b1 100644 --- a/build/setup/index.js +++ b/build/setup/index.js @@ -72356,40 +72356,52 @@ function cacheKey(name, version, manager) { return `${name}-${process.platform}-${external_os_default().arch()}-${manager}-${version}`; } /** - * Restore a tool from the remote cache. - * This will install the tool back into the local tool cache. + * Restore a directory from the remote cache. */ -async function restoreFromCache(name, version, manager) { - const dir = toolPath(name, version); +async function restoreCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped restoring from remote cache, not available.`); - return undefined; + return null; } try { - if (await (0,cache.restoreCache)([dir], cacheKey(name, version, manager))) { - return dir; + if (await (0,cache.restoreCache)([cachePath], cacheKey)) { + return cachePath; } } catch (error) { handleCacheError(error); } + return null; } /** - * Save a tool to the remote cache. - * This will fetch the tool from the local tool cache. + * Save a directory to the remote cache. */ -async function saveToCache(name, version, manager) { +async function saveCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { (0,core.warning)(`Skipped saving to remote cache, not available.`); - return undefined; + return; } try { - await (0,cache.saveCache)([toolPath(name, version)], cacheKey(name, version, manager)); + await (0,cache.saveCache)([cachePath], cacheKey); } catch (error) { handleCacheError(error); } } +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +function restoreFromCache(name, version, manager) { + return restoreCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +function saveToCache(name, version, manager) { + return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} /** * Try to handle incoming cache errors. * Because workers can operate in environments without cache configured, @@ -72667,7 +72679,7 @@ async function setupAction(input = setupInput()) { } } async function installCli(name, version, packager, useCache = true) { - let cliPath = (0,tool_cache.find)(name, version) || undefined; + let cliPath = (0,tool_cache.find)(name, version) || null; if (!cliPath && useCache) { cliPath = await restoreFromCache(name, version, packager); } diff --git a/src/actions/fingerprint.ts b/src/actions/fingerprint.ts index f8907982..99048526 100644 --- a/src/actions/fingerprint.ts +++ b/src/actions/fingerprint.ts @@ -60,7 +60,7 @@ async function installFingerprintAsync(input: ReturnType): : `Installing ${packageName} (${version}) with ${input.packager}`; return await group(message, async () => { - let libRoot = findTool(packageName, version) || undefined; + let libRoot = findTool(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, input.packager); } diff --git a/src/actions/preview-build.ts b/src/actions/preview-build.ts index 1119314b..e3ffe5e7 100644 --- a/src/actions/preview-build.ts +++ b/src/actions/preview-build.ts @@ -100,7 +100,7 @@ async function installFingerprintAsync(input: ReturnType { - let libRoot = findTool(packageName, version) || undefined; + let libRoot = findTool(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, input.packager); } diff --git a/src/actions/setup.ts b/src/actions/setup.ts index 0d3628f3..166a43b5 100644 --- a/src/actions/setup.ts +++ b/src/actions/setup.ts @@ -58,7 +58,7 @@ export async function setupAction(input = setupInput()) { } async function installCli(name: string, version: string, packager: string, useCache = true) { - let cliPath = findTool(name, version) || undefined; + let cliPath = findTool(name, version) || null; if (!cliPath && useCache) { cliPath = await restoreFromCache(name, version, packager); diff --git a/src/cacher.ts b/src/cacher.ts index 5e5a92d3..9fdca17f 100644 --- a/src/cacher.ts +++ b/src/cacher.ts @@ -20,43 +20,56 @@ export function cacheKey(name: string, version: string, manager: string): string } /** - * Restore a tool from the remote cache. - * This will install the tool back into the local tool cache. + * Restore a directory from the remote cache. */ -export async function restoreFromCache(name: string, version: string, manager: string) { - const dir = toolPath(name, version)!; - +export async function restoreCacheAsync(cachePath: string, cacheKey: string): Promise { if (!cacheIsAvailable()) { warning(`Skipped restoring from remote cache, not available.`); - return undefined; + return null; } try { - if (await restoreCache([dir], cacheKey(name, version, manager))) { - return dir; + if (await restoreCache([cachePath], cacheKey)) { + return cachePath; } } catch (error) { handleCacheError(error); } + return null; } /** - * Save a tool to the remote cache. - * This will fetch the tool from the local tool cache. + * Save a directory to the remote cache. */ -export async function saveToCache(name: string, version: string, manager: string) { +export async function saveCacheAsync(cachePath: string, cacheKey: string): Promise { if (!cacheIsAvailable()) { warning(`Skipped saving to remote cache, not available.`); - return undefined; + return; } try { - await saveCache([toolPath(name, version)], cacheKey(name, version, manager)); + await saveCache([cachePath], cacheKey); } catch (error) { handleCacheError(error); } } +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +export function restoreFromCache(name: string, version: string, manager: string) { + return restoreCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} + +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +export function saveToCache(name: string, version: string, manager: string) { + return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); +} + /** * Try to handle incoming cache errors. * Because workers can operate in environments without cache configured, diff --git a/src/sqlite.ts b/src/sqlite.ts index 1eda8d76..9ac5cf9f 100644 --- a/src/sqlite.ts +++ b/src/sqlite.ts @@ -1,4 +1,5 @@ import { group } from '@actions/core'; +import { getExecOutput } from '@actions/exec'; import assert from 'assert'; import type sqlite3Types from 'sqlite3'; import { promisify } from 'util'; @@ -56,7 +57,7 @@ export async function installSQLiteAsync(packager: string): Promise { const message = `Installing ${packageName} (${version}) from cache or with ${packager}`; return await group(message, async () => { - let libRoot = findTool(packageName, version) || undefined; + let libRoot = findTool(packageName, version) || null; console.log('ooxx0', libRoot); if (!libRoot) { libRoot = await restoreFromCache(packageName, version, packager); @@ -68,6 +69,8 @@ export async function installSQLiteAsync(packager: string): Promise { } console.log('ooxx2', libRoot); + const { stdout } = await getExecOutput('find', [libRoot, '-ls']); + console.log('ooxx stdout', stdout); addGlobalNodeSearchPath(libRoot); return libRoot; });