Skip to content

Commit

Permalink
Fix: nocache npm ci (#228)
Browse files Browse the repository at this point in the history
* Add logic to don't save cache when npm ci is used

* Add extra condition to not restore cache when npm ci

* Update parameter description to meet new logic
  • Loading branch information
marboledacci authored Aug 30, 2024
1 parent 70cddc3 commit 4ec8467
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/commands/install-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ parameters:
with-cache:
type: boolean
default: true
description: Cache your node packages automatically for faster install times.
description: |
Cache your node packages automatically for faster install times.
Cache will be ignored when using npm ci.
check-cache:
type: enum
default: 'never'
Expand All @@ -28,11 +30,13 @@ parameters:
description: |
By default, packages will be installed with "npm ci", "yarn install --frozen-lockfile", "yarn install --immutable" or "pnpm install --frozen-lockfile".
Optionally supply a custom package installation command, with any additional flags needed.
When the command npm ci is used, no cache will be used, as the command doesn't benefit from it.
type: string
default: ''
cache-path:
description: |
By default, this orb will utilize 'npm ci' and cache the '~/.npm' directory. Override which path to cache with this parameter.
The cache will be ignored when using npm ci, as the command doesn't benefit from cache.
type: string
default: ''
cache-only-lockfile:
Expand All @@ -58,7 +62,16 @@ steps:
command: <<include(scripts/packages/find-package.sh)>>

- when:
condition: << parameters.with-cache >>
condition:
and:
- << parameters.with-cache >>
- or:
- not:
equal: [npm, << parameters.pkg-manager >>]
- and:
- << parameters.override-ci-command >>
- not:
equal: ["npm-ci", << parameters.override-ci-command >>]
steps:
- run:
working_directory: <<parameters.app-dir>>
Expand All @@ -84,7 +97,12 @@ steps:
command: <<include(scripts/packages/npm-install.sh)>>

- when: # cache enabled, save cache
condition: << parameters.with-cache >>
condition:
and:
- << parameters.with-cache >>
- << parameters.override-ci-command >>
- not:
equal: ["npm-ci", << parameters.override-ci-command >>]
steps:
- when: # custom cache path selected
condition: << parameters.cache-path >>
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/packages/npm-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Configure npm cache path if provided
if [[ -n "$PARAM_CACHE_PATH" ]]; then
if [[ -n "$PARAM_CACHE_PATH" ]] && [[ "$PARAM_OVERRIDE_COMMAND" != "npm ci" ]] && [[ -n "$PARAM_OVERRIDE_COMMAND" ]]; then
npm config set cache "$PARAM_CACHE_PATH"
fi

Expand Down

0 comments on commit 4ec8467

Please sign in to comment.