diff --git a/.github/workflows/example-performance.yml b/.github/workflows/example-performance.yml index 7bd4688..55baae5 100644 --- a/.github/workflows/example-performance.yml +++ b/.github/workflows/example-performance.yml @@ -10,13 +10,12 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 20 - - run: npm install chalk # look at fast this action installs a single dependency - uses: bahmutov/npm-install@performance with: working-directory: examples/basic install-command: 'npm install chalk' - cache-key-prefix: chalk6 + cache-key-prefix: chalk7 env: ACTIONS_RUNNER_DEBUG: true ACTIONS_STEP_DEBUG: true diff --git a/dist/index.js b/dist/index.js index 38b41cd..758eeb3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -282,8 +282,7 @@ const installInOneFolder = ({ } return api.utils.restoreCachedNpm(NPM_CACHE).then(npmCacheHit => { - // return api.utils.install(opts).then(() => { - return Promise.resolve().then(() => { + return api.utils.install(opts).then(() => { if (npmCacheHit) { return } @@ -314,17 +313,33 @@ const npmInstallAction = async () => { const installCommand = core.getInput('install-command') - for (const workingDirectory of workingDirectories) { - const started = +new Date() - await api.utils.installInOneFolder({ - usePackageLock, - useRollingCache, - workingDirectory, - installCommand, - cachePrefix - }) - const finished = +new Date() - core.debug(`installing in ${workingDirectory} took ${finished - started}ms`) + try { + for (const workingDirectory of workingDirectories) { + const started = +new Date() + await api.utils.installInOneFolder({ + usePackageLock, + useRollingCache, + workingDirectory, + installCommand, + cachePrefix + }) + + const finished = +new Date() + core.debug( + `installing in ${workingDirectory} took ${finished - started}ms` + ) + } + + // node will stay alive if any promises are not resolved, + // which is a possibility if HTTP requests are dangling + // due to retries or timeouts. We know that if we got here + // that all promises that we care about have successfully + // resolved, so simply exit with success. + process.exit(0) + } catch (err) { + console.error(err) + core.setFailed(err.message) + process.exit(1) } } diff --git a/index.js b/index.js index 70fc219..0b909ec 100644 --- a/index.js +++ b/index.js @@ -275,8 +275,7 @@ const installInOneFolder = ({ } return api.utils.restoreCachedNpm(NPM_CACHE).then(npmCacheHit => { - // return api.utils.install(opts).then(() => { - return Promise.resolve().then(() => { + return api.utils.install(opts).then(() => { if (npmCacheHit) { return } @@ -307,17 +306,33 @@ const npmInstallAction = async () => { const installCommand = core.getInput('install-command') - for (const workingDirectory of workingDirectories) { - const started = +new Date() - await api.utils.installInOneFolder({ - usePackageLock, - useRollingCache, - workingDirectory, - installCommand, - cachePrefix - }) - const finished = +new Date() - core.debug(`installing in ${workingDirectory} took ${finished - started}ms`) + try { + for (const workingDirectory of workingDirectories) { + const started = +new Date() + await api.utils.installInOneFolder({ + usePackageLock, + useRollingCache, + workingDirectory, + installCommand, + cachePrefix + }) + + const finished = +new Date() + core.debug( + `installing in ${workingDirectory} took ${finished - started}ms` + ) + } + + // node will stay alive if any promises are not resolved, + // which is a possibility if HTTP requests are dangling + // due to retries or timeouts. We know that if we got here + // that all promises that we care about have successfully + // resolved, so simply exit with success. + process.exit(0) + } catch (err) { + console.error(err) + core.setFailed(err.message) + process.exit(1) } }