Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: caching and yarn issues #137

Merged
merged 11 commits into from
Mar 14, 2022
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: >
Jaryt marked this conversation as resolved.
Show resolved Hide resolved
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 current LTS version of Node.js will be installed by default.
Jaryt marked this conversation as resolved.
Show resolved Hide resolved
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