From 2af8a1a117733b60524c7c873a4cc91885796cfe Mon Sep 17 00:00:00 2001 From: jiro Date: Sat, 29 Jun 2024 16:13:40 +0900 Subject: [PATCH] fix: Slow installation #483 (#485) * fix: bump minor node version * fix: slow install --- .node-version | 2 +- lib/installer.js | 14 +++++++++++++- src/installer.ts | 27 +++++++++++++++++++++------ src/util.ts | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.node-version b/.node-version index d5a15960..90756595 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -20.10.0 +20.15.0 diff --git a/lib/installer.js b/lib/installer.js index 09a8dc5d..78f6e49d 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -61,11 +61,18 @@ function installNim(version, noColor, yes) { // #38 if (util.isGlobPatchVersion(version) || util.isGlobMinorVersion(version)) { core.info(`Fetch a latest versions with ${version}`); + const beginDate = Date.now(); version = yield util.getLatestVersion(version); + const endDate = Date.now(); + const elapsed = endDate - beginDate; + core.info(`Succeeded to fetch version: version = ${version} elapsed = ${elapsed} millisecond`); } + // #483 + // なぜか init.sh を実行したときに 2.x 以降のバージョンをインストールしようとすると非常に遅い。 + // しかし 1.x を一度インストールしてから 2.x に切り替える場合は高速に完了するため、一旦その方法で回避する。 + process.env.CHOOSENIM_CHOOSE_VERSION = "1.6.0"; // #21 if (process.platform === 'win32') { - process.env.CHOOSENIM_CHOOSE_VERSION = version; proc.execFile('bash', ['init.sh', '-y'], (err, stdout, stderr) => { if (err) { core.error(err); @@ -92,12 +99,17 @@ function installNim(version, noColor, yes) { }); return; } + const beginDate = Date.now(); + core.info(`Run init.sh`); proc.execFile('bash', ['init.sh', '-y'], (err, stdout, stderr) => { if (err) { core.error(err); throw err; } + const endDate = Date.now(); + const elapsed = endDate - beginDate; core.info(stdout); + core.info(`Succeeded to run init.sh: elapsed = ${elapsed} millisecond`); // Build optional parameters of choosenim. let args = util.parseVersion(version); if (noColor) diff --git a/src/installer.ts b/src/installer.ts index d45e1a7f..3f0c9c9b 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -26,12 +26,22 @@ async function installNim(version: string, noColor: boolean, yes: boolean) { // #38 if (util.isGlobPatchVersion(version) || util.isGlobMinorVersion(version)) { core.info(`Fetch a latest versions with ${version}`) + const beginDate = Date.now() version = await util.getLatestVersion(version) + const endDate = Date.now() + const elapsed = endDate - beginDate + core.info( + `Succeeded to fetch version: version = ${version} elapsed = ${elapsed} millisecond`, + ) } + // #483 + // なぜか init.sh を実行したときに 2.x 以降のバージョンをインストールしようとすると非常に遅い。 + // しかし 1.x を一度インストールしてから 2.x に切り替える場合は高速に完了するため、一旦その方法で回避する。 + process.env.CHOOSENIM_CHOOSE_VERSION = '1.6.0' + // #21 if (process.platform === 'win32') { - process.env.CHOOSENIM_CHOOSE_VERSION = version proc.execFile( 'bash', ['init.sh', '-y'], @@ -63,15 +73,17 @@ async function installNim(version: string, noColor: boolean, yes: boolean) { throw err } core.info(stdout) - } + }, ) - } + }, ) - } + }, ) return } + const beginDate = Date.now() + core.info(`Run init.sh`) proc.execFile( 'bash', ['init.sh', '-y'], @@ -80,7 +92,10 @@ async function installNim(version: string, noColor: boolean, yes: boolean) { core.error(err) throw err } + const endDate = Date.now() + const elapsed = endDate - beginDate core.info(stdout) + core.info(`Succeeded to run init.sh: elapsed = ${elapsed} millisecond`) // Build optional parameters of choosenim. let args: string[] = util.parseVersion(version) @@ -96,8 +111,8 @@ async function installNim(version: string, noColor: boolean, yes: boolean) { throw err } core.info(stdout) - } + }, ) - } + }, ) } diff --git a/src/util.ts b/src/util.ts index 08498212..50baa0ab 100644 --- a/src/util.ts +++ b/src/util.ts @@ -41,7 +41,7 @@ export async function fetchTagList(): Promise { */ export function getLatestVersionWithTags( version: string, - tags: string[] + tags: string[], ): string { if (!isGlobPatchVersion(version) && !isGlobMinorVersion(version)) { return ''