From 01946376cf137cb243b5d8c59e0bc90645955e20 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Wed, 13 Sep 2023 11:35:45 +0800 Subject: [PATCH] wip --- build/fingerprint-post/index.js | 203 +++++++++++--------------------- build/fingerprint/index.js | 34 +++--- src/actions/fingerprint-post.ts | 5 +- src/actions/fingerprint.ts | 23 ++-- src/fingerprint/index.ts | 24 +++- 5 files changed, 119 insertions(+), 170 deletions(-) diff --git a/build/fingerprint-post/index.js b/build/fingerprint-post/index.js index 838dfef0..9f4a2eb1 100644 --- a/build/fingerprint-post/index.js +++ b/build/fingerprint-post/index.js @@ -71885,14 +71885,6 @@ module.exports.implForWrapper = function (wrapper) { }).call(this); -/***/ }), - -/***/ 1351: -/***/ ((module) => { - -"use strict"; -module.exports = require("@expo/fingerprint"); - /***/ }), /***/ 9491: @@ -72246,7 +72238,7 @@ __nccwpck_require__.r(__webpack_exports__); // EXPORTS __nccwpck_require__.d(__webpack_exports__, { - "runAction": () => (/* binding */ fingerprint_post_runAction) + "runAction": () => (/* binding */ runAction) }); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js @@ -72261,7 +72253,6 @@ var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); var cache = __nccwpck_require__(7799); // EXTERNAL MODULE: external "os" var external_os_ = __nccwpck_require__(2037); -var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); // EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js var lib_exec = __nccwpck_require__(1514); // EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js @@ -72291,8 +72282,8 @@ function executeAction(action) { * Install a "tool" from a node package. * This will add the folder, containing the `node_modules`, to the global path. */ -function installToolFromPackage(dir) { - return (0,core.addPath)(external_path_default().join(dir, 'node_modules', '.bin')); +function worker_installToolFromPackage(dir) { + return addPath(path.join(dir, 'node_modules', '.bin')); } /** * Try to patch Linux's inotify limits to a more sensible setting on Linux. @@ -72323,23 +72314,23 @@ async function patchWatchers() { warning(errorMessage(error)); } } -function tempPath(name, version) { - (0,external_assert_.ok)(process.env['RUNNER_TEMP'], 'Could not resolve temporary path, RUNNER_TEMP not defined'); - return external_path_default().join(process.env['RUNNER_TEMP'], name, version, external_os_default().arch()); +function worker_tempPath(name, version) { + assert(process.env['RUNNER_TEMP'], 'Could not resolve temporary path, RUNNER_TEMP not defined'); + return path.join(process.env['RUNNER_TEMP'], name, version, os.arch()); } /** * Get the package path to the tool cache. * * @see https://github.com/actions/toolkit/blob/daf8bb00606d37ee2431d9b1596b88513dcf9c59/packages/tool-cache/src/tool-cache.ts#L747-L749 */ -function toolPath(name, version) { - (0,external_assert_.ok)(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); - return external_path_default().join(process.env['RUNNER_TOOL_CACHE'], name, version, external_os_default().arch()); +function worker_toolPath(name, version) { + assert(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); + return path.join(process.env['RUNNER_TOOL_CACHE'], name, version, os.arch()); } /** * Add extra `searchPath` to the global search path for require() */ -function addGlobalNodeSearchPath(searchPath) { +function worker_addGlobalNodeSearchPath(searchPath) { const nodePath = process.env['NODE_PATH'] || ''; const delimiter = process.platform === 'win32' ? ';' : ':'; const nodePaths = nodePath.split(delimiter); @@ -72364,18 +72355,18 @@ function cacheIsAvailable() { * We can prefix this when there are breaking changes in this action. */ function cacheKey(name, version, manager) { - return `${name}-${process.platform}-${external_os_default().arch()}-${manager}-${version}`; + return `${name}-${process.platform}-${os.arch()}-${manager}-${version}`; } /** * Restore a directory from the remote cache. */ -async function restoreCacheAsync(cachePath, cacheKey) { +async function cacher_restoreCacheAsync(cachePath, cacheKey) { if (!cacheIsAvailable()) { - (0,core.warning)(`Skipped restoring from remote cache, not available.`); + warning(`Skipped restoring from remote cache, not available.`); return null; } try { - if (await (0,cache.restoreCache)([cachePath], cacheKey)) { + if (await restoreCache([cachePath], cacheKey)) { return cachePath; } } @@ -72403,14 +72394,14 @@ async function saveCacheAsync(cachePath, cacheKey) { * 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)); +function cacher_restoreFromCache(name, version, manager) { + return cacher_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) { +function cacher_saveToCache(name, version, manager) { return saveCacheAsync(toolPath(name, version), cacheKey(name, version, manager)); } /** @@ -72435,28 +72426,6 @@ function handleCacheError(error) { // EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js var io = __nccwpck_require__(7436); -;// CONCATENATED MODULE: ./src/utils.ts -/** - * Replace all template variables in a string. - * This uses the notation of `{varname}`, which can be defined as object. - */ -function template(template, replacements) { - let result = template; - for (const name in replacements) { - result = result.replaceAll(`{${name}}`, replacements[name]); - } - return result; -} -function utils_errorMessage(error) { - if (error instanceof Error) { - return error.message; - } - if (typeof error === 'string') { - return error; - } - return 'Unknown error'; -} - ;// CONCATENATED MODULE: ./src/packager.ts @@ -72467,13 +72436,13 @@ function utils_errorMessage(error) { * This is useful to invalidate the cache _and_ using dist-tags or version ranges. * It executes `npm info` and parses the latest manifest. */ -async function resolvePackage(name, range) { +async function packager_resolvePackage(name, range) { let stdout = ''; try { - ({ stdout } = await (0,lib_exec.getExecOutput)('npm', ['info', `${name}@${range}`, 'version', '--json'], { silent: true })); + ({ stdout } = await getExecOutput('npm', ['info', `${name}@${range}`, 'version', '--json'], { silent: true })); } catch (error) { - throw new Error(`Could not resolve ${name}@${range}, reason:\n${utils_errorMessage(error)}`); + throw new Error(`Could not resolve ${name}@${range}, reason:\n${errorMessage(error)}`); } // thanks npm, for returning a "" json string value for invalid versions if (!stdout) { @@ -72491,11 +72460,11 @@ async function resolvePackage(name, range) { * * Note, we do assume that the packager is globally available AND has the `add ` command. */ -async function installPackage(name, version, manager) { +async function packager_installPackage(name, version, manager) { const temp = tempPath(name, version); - await (0,io.mkdirP)(temp); - await (0,lib_exec.exec)(manager, ['add', `${name}@${version}`], { cwd: temp }); - return (0,tool_cache.cacheDir)(temp, name, version); + await mkdirP(temp); + await exec(manager, ['add', `${name}@${version}`], { cwd: temp }); + return cacheTool(temp, name, version); } // EXTERNAL MODULE: external "util" @@ -72511,7 +72480,7 @@ var external_util_ = __nccwpck_require__(3837); /** * Open a database and return a promise that resolves to a database object. */ -function openDatabaseAsync(filename) { +function sqlite_openDatabaseAsync(filename) { return new Promise((resolve, reject) => { const sqlite3 = __nccwpck_require__(7299); const db = new sqlite3.Database(filename, err => { @@ -72525,12 +72494,12 @@ function openDatabaseAsync(filename) { }).then(db => { return { ...db, - closeAsync: (0,external_util_.promisify)(db.close.bind(db)), - runAsync: (0,external_util_.promisify)(db.run.bind(db)), - execAsync: (0,external_util_.promisify)(db.exec.bind(db)), - prepareAsync: (0,external_util_.promisify)(db.prepare.bind(db)), - getAsync: (0,external_util_.promisify)(db.get.bind(db)), - allAsync: (0,external_util_.promisify)(db.all.bind(db)), + closeAsync: promisify(db.close.bind(db)), + runAsync: promisify(db.run.bind(db)), + execAsync: promisify(db.exec.bind(db)), + prepareAsync: promisify(db.prepare.bind(db)), + getAsync: promisify(db.get.bind(db)), + allAsync: promisify(db.all.bind(db)), }; }); } @@ -72539,12 +72508,12 @@ function openDatabaseAsync(filename) { */ async function installSQLiteAsync(packager) { const sqliteVersion = (__nccwpck_require__(4147)/* .dependencies.sqlite3 */ .HO.xp); - external_assert_default()(sqliteVersion); + assert(sqliteVersion); const packageName = 'sqlite3'; 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) || null; + return await group(message, async () => { + let libRoot = findTool(packageName, version) || null; if (!libRoot) { libRoot = await restoreFromCache(packageName, version, packager); } @@ -72552,25 +72521,25 @@ async function installSQLiteAsync(packager) { libRoot = await installPackage(packageName, version, packager); await saveToCache(packageName, version, packager); } - addGlobalNodeSearchPath(external_path_default().join(libRoot, 'node_modules')); + addGlobalNodeSearchPath(path.join(libRoot, 'node_modules')); return libRoot; }); } ;// CONCATENATED MODULE: ./src/fingerprint/FingerprintDbManager.ts -class FingerprintDbManager { +class FingerprintDbManager_FingerprintDbManager { dbPath; constructor(dbPath) { this.dbPath = dbPath; } async initAsync() { const db = await openDatabaseAsync(this.dbPath); - await db.runAsync(`CREATE TABLE IF NOT EXISTS ${FingerprintDbManager.TABLE_NAME} (${FingerprintDbManager.SCHEMA.join(', ')})`); - for (const index of FingerprintDbManager.INDEXES) { + await db.runAsync(`CREATE TABLE IF NOT EXISTS ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} (${FingerprintDbManager_FingerprintDbManager.SCHEMA.join(', ')})`); + for (const index of FingerprintDbManager_FingerprintDbManager.INDEXES) { await db.runAsync(index); } - await db.runAsync(`PRAGMA fingerprint_schema_version = ${FingerprintDbManager.SCHEMA_VERSION}`); + await db.runAsync(`PRAGMA fingerprint_schema_version = ${FingerprintDbManager_FingerprintDbManager.SCHEMA_VERSION}`); this.db = db; return db; } @@ -72578,27 +72547,27 @@ class FingerprintDbManager { if (!this.db) { throw new Error('Database not initialized. Call initAsync() first.'); } - await this.db.runAsync(`INSERT INTO ${FingerprintDbManager.TABLE_NAME} (eas_build_id, git_commit_hash, fingerprint_hash, fingerprint) VALUES (?, ?, ?, json(?))`, params.easBuildId, params.gitCommitHash, params.fingerprint.hash, JSON.stringify(params.fingerprint)); + await this.db.runAsync(`INSERT INTO ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} (eas_build_id, git_commit_hash, fingerprint_hash, fingerprint) VALUES (?, ?, ?, json(?))`, params.easBuildId, params.gitCommitHash, params.fingerprint.hash, JSON.stringify(params.fingerprint)); } async queryEasBuildIdFromFingerprintAsync(fingerprintHash) { if (!this.db) { throw new Error('Database not initialized. Call initAsync() first.'); } - const row = await this.db.getAsync(`SELECT eas_build_id FROM ${FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash); + const row = await this.db.getAsync(`SELECT eas_build_id FROM ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash); return row?.['eas_build_id'] ?? null; } async getEntityFromGitCommitHashAsync(gitCommitHash) { if (!this.db) { throw new Error('Database not initialized. Call initAsync() first.'); } - const row = await this.db.getAsync(`SELECT * FROM ${FingerprintDbManager.TABLE_NAME} WHERE git_commit_hash = ?`, gitCommitHash); - return row ? FingerprintDbManager.serialize(row) : null; + const row = await this.db.getAsync(`SELECT * FROM ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} WHERE git_commit_hash = ?`, gitCommitHash); + return row ? FingerprintDbManager_FingerprintDbManager.serialize(row) : null; } async getFingerprintSourcesAsync(fingerprintHash) { if (!this.db) { throw new Error('Database not initialized. Call initAsync() first.'); } - const row = await this.db.getAsync(`SELECT json_extract(fingerprint, '$.sources') as sources FROM ${FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash); + const row = await this.db.getAsync(`SELECT json_extract(fingerprint, '$.sources') as sources FROM ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash); const result = row?.['sources']; if (!result) { return null; @@ -72609,19 +72578,19 @@ class FingerprintDbManager { this.db?.closeAsync(); } //#region private - static SCHEMA_VERSION = 0; - static TABLE_NAME = 'fingerprint'; - static SCHEMA = [ + static SCHEMA_VERSION = (/* unused pure expression or super */ null && (0)); + static TABLE_NAME = (/* unused pure expression or super */ null && ('fingerprint')); + static SCHEMA = (/* unused pure expression or super */ null && ([ 'id INTEGER PRIMARY KEY AUTOINCREMENT', 'eas_build_id TEXT', 'git_commit_hash TEXT NOT NULL', 'fingerprint_hash TEXT NOT NULL', 'fingerprint TEXT NOT NULL', - ]; - static INDEXES = [ + ])); + static INDEXES = (/* unused pure expression or super */ null && ([ 'CREATE UNIQUE INDEX IF NOT EXISTS idx_fingerprint_hash ON fingerprint (fingerprint_hash)', 'CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON fingerprint (git_commit_hash)', - ]; + ])); db = null; static serialize(rawEntity) { return { @@ -72651,9 +72620,16 @@ async function createFingerprintDbManagerAsync(cacheKey) { await dbManager.initAsync(); return dbManager; } -function getDbPath() { - external_assert_default()(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); - return external_path_default().join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); +function collectFingerprintActionInput() { + return { + packager: (0,core.getInput)('packager') || 'yarn', + workingDirectory: (0,core.getInput)('working-directory'), + fingerprintVersion: (0,core.getInput)('fingerprint-version') || 'latest', + fingerprintInstallationCache: !(0,core.getInput)('fingerprint-installation-cache') || (0,core.getBooleanInput)('fingerprint-installation-cache'), + fingerprintDbCacheKey: (0,core.getInput)('fingerprint-db-cache-key'), + fingerprintPreviousGitCommit: (0,core.getInput)('fingerprint-previous-git-commit'), + fingerprintCurrentGitCommit: (0,core.getInput)('fingerprint-current-git-commit'), + }; } /** * Install @expo/fingerprint based on given input @@ -72664,8 +72640,8 @@ async function installFingerprintAsync(fingerprintVersion, packager, useCache = const message = useCache ? `Installing ${packageName} (${version}) from cache or with ${packager}` : `Installing ${packageName} (${version}) with ${packager}`; - return await (0,core.group)(message, async () => { - let libRoot = (0,tool_cache.find)(packageName, version) || null; + return await group(message, async () => { + let libRoot = findTool(packageName, version) || null; if (!libRoot && useCache) { libRoot = await restoreFromCache(packageName, version, packager); } @@ -72676,7 +72652,7 @@ async function installFingerprintAsync(fingerprintVersion, packager, useCache = } } installToolFromPackage(libRoot); - addGlobalNodeSearchPath(external_path_default().join(libRoot, 'node_modules')); + addGlobalNodeSearchPath(path.join(libRoot, 'node_modules')); return libRoot; }); } @@ -72685,7 +72661,7 @@ async function installFingerprintAsync(fingerprintVersion, packager, useCache = * This will install the tool back into the local tool cache. */ function restoreDbFromCacheAsync(cacheKey) { - return restoreCacheAsync(external_path_default().dirname(getDbPath()), cacheKey); + return restoreCacheAsync(path.dirname(getDbPath()), cacheKey); } /** * Save database to the remote cache. @@ -72694,54 +72670,19 @@ function restoreDbFromCacheAsync(cacheKey) { function saveDbToCacheAsync(cacheKey) { return saveCacheAsync(external_path_default().dirname(getDbPath()), cacheKey); } - -;// CONCATENATED MODULE: ./src/actions/fingerprint.ts - - - - -function collectInput() { - return { - packager: (0,core.getInput)('packager') || 'yarn', - workingDirectory: (0,core.getInput)('working-directory'), - fingerprintVersion: (0,core.getInput)('fingerprint-version') || 'latest', - fingerprintInstallationCache: !(0,core.getInput)('fingerprint-installation-cache') || (0,core.getBooleanInput)('fingerprint-installation-cache'), - fingerprintDbCacheKey: (0,core.getInput)('fingerprint-db-cache-key'), - fingerprintPreviousGitCommit: (0,core.getInput)('fingerprint-previous-git-commit'), - fingerprintCurrentGitCommit: (0,core.getInput)('fingerprint-current-git-commit'), - }; -} -executeAction(runAction); -async function runAction(input = collectInput()) { - await installFingerprintAsync(input.fingerprintVersion, input.packager, input.fingerprintInstallationCache); - const fingerprint = __nccwpck_require__(1351); - const currentFingerprint = await fingerprint.createFingerprintAsync(input.workingDirectory); - await installSQLiteAsync(input.packager); - const dbManager = await createFingerprintDbManagerAsync(input.fingerprintDbCacheKey); - await dbManager.insertFingerprintAsync({ - easBuildId: '', - gitCommitHash: input.fingerprintCurrentGitCommit, - fingerprint: currentFingerprint, - }); - let diff = undefined; - if (input.fingerprintPreviousGitCommit) { - const previousFingerprint = await dbManager.getEntityFromGitCommitHashAsync(input.fingerprintPreviousGitCommit); - if (previousFingerprint != null) { - diff = await fingerprint.diffFingerprints(previousFingerprint.fingerprint, currentFingerprint); - } - } - if (diff == null) { - diff = await fingerprint.diffFingerprints({ sources: [], hash: '' }, currentFingerprint); - } - (0,core.setOutput)('fingerprint-diff', diff); +/** + * Get the path to the fingerprint database + */ +function getDbPath() { + external_assert_default()(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); + return external_path_default().join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); } ;// CONCATENATED MODULE: ./src/actions/fingerprint-post.ts - -executeAction(fingerprint_post_runAction); -async function fingerprint_post_runAction(input = collectInput()) { +executeAction(runAction); +async function runAction(input = collectFingerprintActionInput()) { await saveDbToCacheAsync(input.fingerprintDbCacheKey); } diff --git a/build/fingerprint/index.js b/build/fingerprint/index.js index 3d7beb10..db0d1e18 100644 --- a/build/fingerprint/index.js +++ b/build/fingerprint/index.js @@ -72246,7 +72246,6 @@ __nccwpck_require__.r(__webpack_exports__); // EXPORTS __nccwpck_require__.d(__webpack_exports__, { - "collectInput": () => (/* binding */ collectInput), "runAction": () => (/* binding */ runAction) }); @@ -72652,9 +72651,16 @@ async function createFingerprintDbManagerAsync(cacheKey) { await dbManager.initAsync(); return dbManager; } -function getDbPath() { - external_assert_default()(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); - return external_path_default().join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); +function collectFingerprintActionInput() { + return { + packager: (0,core.getInput)('packager') || 'yarn', + workingDirectory: (0,core.getInput)('working-directory'), + fingerprintVersion: (0,core.getInput)('fingerprint-version') || 'latest', + fingerprintInstallationCache: !(0,core.getInput)('fingerprint-installation-cache') || (0,core.getBooleanInput)('fingerprint-installation-cache'), + fingerprintDbCacheKey: (0,core.getInput)('fingerprint-db-cache-key'), + fingerprintPreviousGitCommit: (0,core.getInput)('fingerprint-previous-git-commit'), + fingerprintCurrentGitCommit: (0,core.getInput)('fingerprint-current-git-commit'), + }; } /** * Install @expo/fingerprint based on given input @@ -72695,25 +72701,21 @@ function restoreDbFromCacheAsync(cacheKey) { function saveDbToCacheAsync(cacheKey) { return saveCacheAsync(path.dirname(getDbPath()), cacheKey); } +/** + * Get the path to the fingerprint database + */ +function getDbPath() { + external_assert_default()(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); + return external_path_default().join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); +} ;// CONCATENATED MODULE: ./src/actions/fingerprint.ts -function collectInput() { - return { - packager: (0,core.getInput)('packager') || 'yarn', - workingDirectory: (0,core.getInput)('working-directory'), - fingerprintVersion: (0,core.getInput)('fingerprint-version') || 'latest', - fingerprintInstallationCache: !(0,core.getInput)('fingerprint-installation-cache') || (0,core.getBooleanInput)('fingerprint-installation-cache'), - fingerprintDbCacheKey: (0,core.getInput)('fingerprint-db-cache-key'), - fingerprintPreviousGitCommit: (0,core.getInput)('fingerprint-previous-git-commit'), - fingerprintCurrentGitCommit: (0,core.getInput)('fingerprint-current-git-commit'), - }; -} executeAction(runAction); -async function runAction(input = collectInput()) { +async function runAction(input = collectFingerprintActionInput()) { await installFingerprintAsync(input.fingerprintVersion, input.packager, input.fingerprintInstallationCache); const fingerprint = __nccwpck_require__(1351); const currentFingerprint = await fingerprint.createFingerprintAsync(input.workingDirectory); diff --git a/src/actions/fingerprint-post.ts b/src/actions/fingerprint-post.ts index da9ca45f..bccd5a1c 100644 --- a/src/actions/fingerprint-post.ts +++ b/src/actions/fingerprint-post.ts @@ -1,9 +1,8 @@ -import { saveDbToCacheAsync } from '../fingerprint'; +import { collectFingerprintActionInput, saveDbToCacheAsync } from '../fingerprint'; import { executeAction } from '../worker'; -import { collectInput } from './fingerprint'; executeAction(runAction); -export async function runAction(input = collectInput()) { +export async function runAction(input = collectFingerprintActionInput()) { await saveDbToCacheAsync(input.fingerprintDbCacheKey); } diff --git a/src/actions/fingerprint.ts b/src/actions/fingerprint.ts index 2b599e3d..bb83abcd 100644 --- a/src/actions/fingerprint.ts +++ b/src/actions/fingerprint.ts @@ -1,26 +1,17 @@ -import { getBooleanInput, getInput, setOutput } from '@actions/core'; +import { setOutput } from '@actions/core'; import type * as Fingerprint from '@expo/fingerprint'; -import { createFingerprintDbManagerAsync, installFingerprintAsync } from '../fingerprint'; +import { + collectFingerprintActionInput, + createFingerprintDbManagerAsync, + installFingerprintAsync, +} from '../fingerprint'; import { installSQLiteAsync } from '../sqlite'; import { executeAction } from '../worker'; -export function collectInput() { - return { - packager: getInput('packager') || 'yarn', - workingDirectory: getInput('working-directory'), - fingerprintVersion: getInput('fingerprint-version') || 'latest', - fingerprintInstallationCache: - !getInput('fingerprint-installation-cache') || getBooleanInput('fingerprint-installation-cache'), - fingerprintDbCacheKey: getInput('fingerprint-db-cache-key'), - fingerprintPreviousGitCommit: getInput('fingerprint-previous-git-commit'), - fingerprintCurrentGitCommit: getInput('fingerprint-current-git-commit'), - }; -} - executeAction(runAction); -export async function runAction(input = collectInput()) { +export async function runAction(input = collectFingerprintActionInput()) { await installFingerprintAsync(input.fingerprintVersion, input.packager, input.fingerprintInstallationCache); const fingerprint = require('@expo/fingerprint') as typeof import('@expo/fingerprint'); const currentFingerprint = await fingerprint.createFingerprintAsync(input.workingDirectory); diff --git a/src/fingerprint/index.ts b/src/fingerprint/index.ts index 82771f83..5526331a 100644 --- a/src/fingerprint/index.ts +++ b/src/fingerprint/index.ts @@ -1,4 +1,4 @@ -import { group } from '@actions/core'; +import { getBooleanInput, getInput, group } from '@actions/core'; import assert from 'assert'; import path from 'path'; @@ -17,9 +17,17 @@ export async function createFingerprintDbManagerAsync(cacheKey: string): Promise return dbManager; } -function getDbPath(): string { - assert(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); - return path.join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); +export function collectFingerprintActionInput() { + return { + packager: getInput('packager') || 'yarn', + workingDirectory: getInput('working-directory'), + fingerprintVersion: getInput('fingerprint-version') || 'latest', + fingerprintInstallationCache: + !getInput('fingerprint-installation-cache') || getBooleanInput('fingerprint-installation-cache'), + fingerprintDbCacheKey: getInput('fingerprint-db-cache-key'), + fingerprintPreviousGitCommit: getInput('fingerprint-previous-git-commit'), + fingerprintCurrentGitCommit: getInput('fingerprint-current-git-commit'), + }; } /** @@ -69,3 +77,11 @@ export function restoreDbFromCacheAsync(cacheKey: string) { export function saveDbToCacheAsync(cacheKey: string) { return saveCacheAsync(path.dirname(getDbPath()), cacheKey); } + +/** + * Get the path to the fingerprint database + */ +function getDbPath(): string { + assert(process.env['RUNNER_TOOL_CACHE'], 'Could not resolve the local tool cache, RUNNER_TOOL_CACHE not defined'); + return path.join(process.env['RUNNER_TOOL_CACHE'], 'fingerprint.db'); +}