Skip to content

Commit

Permalink
fix: caching and yarn issues [semver:patch] (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Lozon <[email protected]>
Co-authored-by: Yasuharu Ozaki <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2022
1 parent ccf5f1a commit 209e7b8
Show file tree
Hide file tree
Showing 9 changed files with 2,383 additions and 2,205 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Node Orb [![CircleCI Build Status](https://circleci.com/gh/CircleCI-Public/node-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/CircleCI-Public/node-orb) [![CircleCI Orb Version](https://img.shields.io/badge/endpoint.svg?url=https://badges.circleci.io/orb/circleci/node)](https://circleci.com/orbs/registry/orb/circleci/node) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/circleci-public/node-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)
# Node Orb [![CircleCI Build Status](https://circleci.com/gh/CircleCI-Public/node-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/CircleCI-Public/node-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/circleci/python.svg)](https://circleci.com/orbs/registry/orb/circleci/node) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/circleci-public/node-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)

An orb for working with Node.js on CircleCI.

Expand Down
2,932 changes: 1,529 additions & 1,403 deletions sample/package-lock.json

Large diffs are not rendered by default.

1,613 changes: 831 additions & 782 deletions sample/yarn.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/commands/install-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ steps:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths:
- << parameters.cache-path >>
- unless: # npm ci cache path
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths:
- ~/.npm

Expand All @@ -120,14 +120,14 @@ steps:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.cache-path>>
- unless: # use node modules
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths: # yarn v1 cache is slow, so it is faster to use node
- <<parameters.app-dir>>/node_modules

Expand Down Expand Up @@ -167,14 +167,14 @@ steps:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.cache-path>>
- unless: # use node modules
condition: << parameters.cache-path >>
steps:
- save_cache:
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/node-project-package.json" }}-{{ checksum "/tmp/node-project-lockfile" }}
key: node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.app-dir>>/.yarn/cache
- when:
Expand Down
4 changes: 2 additions & 2 deletions src/commands/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ parameters:
type: string
default: ""
description: >
Specify the full version tag to install. To install the latest LTS version, set the version to `lts`.
If unspecified, the version listed in .nvmrc will be installed. If no .nvmrc file exists the latest (current) version of Node.js will be installed by default.
Specify the full version tag to install. To install the latest version, set the version to `latest`.
If unspecified, the version listed in .nvmrc will be installed. If no .nvmrc file exists the active LTS version of Node.js will be installed by default.
For a full list of releases, see the following: https://nodejs.org/en/download/releases
node-install-dir:
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/install-nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ if [ "$NODE_PARAM_VERSION" = "latest" ]; then
NODE_ORB_INSTALL_VERSION=$(nvm ls-remote | tail -n1 | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+')
nvm install "$NODE_ORB_INSTALL_VERSION" # aka nvm install node. We're being explicit here.
nvm alias default "$NODE_ORB_INSTALL_VERSION"
elif [ -n "$NODE_PARAM_VERSION" ]; then
elif [ -n "$NODE_PARAM_VERSION" ] && [ "$NODE_PARAM_VERSION" != "lts" ]; then
nvm install "$NODE_PARAM_VERSION"
nvm alias default "$NODE_PARAM_VERSION"
elif [ -f ".nvmrc" ]; then
elif [ -f ".nvmrc" ]; then
NVMRC_SPECIFIED_VERSION=$(<.nvmrc)
nvm install "$NVMRC_SPECIFIED_VERSION"
nvm alias default "$NVMRC_SPECIFIED_VERSION"
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/install-yarn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ installation_check () {
fi
}

# cd to home so that yarn --version will not use relative installed yarn from .yarn/releases
cd ~ || echo "Cannot change directory to home directory, yarn version may be mismatched."

get_yarn_version
installation_check

Expand Down
8 changes: 4 additions & 4 deletions src/scripts/packages/determine-lockfile.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Link corresponding lock file to a temporary file used by cache commands
if [ -f "package-lock.json" ]; then
echo "Found package-lock.json file, assuming lockfile"
ln package-lock.json /tmp/node-project-lockfile
cp package-lock.json /tmp/node-project-lockfile
elif [ -f "npm-shrinkwrap.json" ]; then
echo "Found npm-shrinkwrap.json file, assuming lockfile"
ln npm-shrinkwrap.json /tmp/node-project-lockfile
cp npm-shrinkwrap.json /tmp/node-project-lockfile
elif [ -f "yarn.lock" ]; then
echo "Found yarn.lock file, assuming lockfile"
ln yarn.lock /tmp/node-project-lockfile
cp yarn.lock /tmp/node-project-lockfile
fi
ln package.json /tmp/node-project-package.json
cp package.json /tmp/node-project-package.json
10 changes: 5 additions & 5 deletions src/scripts/packages/yarn-berry-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ if [[ -n "$PARAM_OVERRIDE_COMMAND" ]]; then
else
# If a cache folder is already present, then we use Yarn Zero installs
# See: https://yarnpkg.com/features/zero-installs
if [[ ! -f "$PARAM_CACHE_PATH" ]]; then
if [[ -e "$PARAM_CACHE_PATH" ]]; then
# See: https://yarnpkg.com/features/zero-installs#does-it-have-security-implications
YARN_LOCKFILE_PATH="/tmp/yarn-zero-lockfile"

if [[ "$PARAM_CHECK_CACHE" == "detect" ]]; then
if [[ ! -f "$YARN_LOCKFILE_PATH" ]]; then
echo "No yarn zero lockfile cached. Enabling check cache this run."
Expand All @@ -26,13 +26,13 @@ else
echo "No changes detected in lockfile. Skipping check cache this run."
fi
fi

if [[ "$PARAM_CHECK_CACHE" == "always" || -n "$ENABLE_CHECK_CACHE" ]]; then
set -- "$@" --check-cache
fi

yarn install --immutable --immutable-cache "$@"

if [[ "$PARAM_CHECK_CACHE" == "detect" && -n "$ENABLE_CHECK_CACHE" ]]; then
cp yarn.lock "$YARN_LOCKFILE_PATH"
fi
Expand Down

0 comments on commit 209e7b8

Please sign in to comment.