Skip to content

Commit

Permalink
exit early after install
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 15, 2024
1 parent fd307f6 commit 07126f6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/example-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 28 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down
41 changes: 28 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 07126f6

Please sign in to comment.