diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 57a984c8..6af7d776 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -83,6 +83,14 @@ workflows: cypress-cache-key: cypress-cache{{ arch }}-{{ checksum "examples/yarn-install/package.json" }} post-install: "npx cypress install" package-manager: "yarn" + - cypress/run: + filters: *filters + name: Yarn Version Example + working-directory: examples/yarn-install + cypress-cache-key: cypress-cache{{ arch }}-{{ checksum "examples/yarn-install/package.json" }} + post-install: "./check-yarn-version.sh 1.22.5" + package-manager: "yarn" + package-manager-version: "1.22.5" - cypress/run: filters: *filters name: Pnpm Example @@ -91,6 +99,14 @@ workflows: cypress-cache-key: cypress-cache{{ arch }}-{{ checksum "examples/pnpm-install/package.json" }} post-install: "pnpm cypress install" package-manager: "pnpm" + - cypress/run: + filters: *filters + name: Pnpm Version Example + working-directory: examples/pnpm-install + cypress-cache-key: cypress-cache{{ arch }}-{{ checksum "examples/pnpm-install/package.json" }} + post-install: "./check-pnpm-version.sh 9.7.1" + package-manager: "pnpm" + package-manager-version: "9.7.1" - cypress/run: filters: *filters name: Custom Install Example @@ -167,7 +183,9 @@ workflows: - Standard Npm Example - Custom Node Version Example - Yarn Example + - Yarn Version Example - Pnpm Example + - Pnpm Version Example - Custom Install Example - Wait On Example - Angular Application diff --git a/examples/pnpm-install/check-pnpm-version.sh b/examples/pnpm-install/check-pnpm-version.sh new file mode 100755 index 00000000..f90b6f6d --- /dev/null +++ b/examples/pnpm-install/check-pnpm-version.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Check if a version parameter is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +VERSION=$1 + +if ! pnpm --version | grep -q "$VERSION"; then + echo "pnpm version $VERSION not found" + exit 1 +fi diff --git a/examples/yarn-install/check-yarn-version.sh b/examples/yarn-install/check-yarn-version.sh new file mode 100755 index 00000000..13751f5c --- /dev/null +++ b/examples/yarn-install/check-yarn-version.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Check if a version parameter is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +VERSION=$1 + +if ! yarn --version | grep -q "$VERSION"; then + echo "yarn version $VERSION not found" + exit 1 +fi diff --git a/src/commands/install.yml b/src/commands/install.yml index e9f85a27..41a2cdc5 100644 --- a/src/commands/install.yml +++ b/src/commands/install.yml @@ -52,6 +52,14 @@ parameters: type: boolean default: false description: Allow skipping the `checkout` command + package-manager-version: + type: string + default: "" + description: | + If you need to specify a version of the package manager, you can do so here. + This is useful if you need to use a specific version of Yarn or PNPM. + If you are using Yarn Berry, you can specify the version here. + If you are using NPM, this parameter will be ignored. steps: - unless: @@ -65,6 +73,16 @@ steps: - restore_cache: name: Restore Cypress cache key: << parameters.cypress-cache-key >> + - when: + condition: + and: + - not: + equal: [ '', << parameters.package-manager-version >> ] + - equal: [ 'yarn', << parameters.package-manager >> ] + steps: + - node/install: + install-yarn: true + yarn-version: << parameters.package-manager-version >> - when: condition: and: @@ -72,6 +90,7 @@ steps: steps: - node/install: install-pnpm: true + pnpm-version: << parameters.package-manager-version >> - node/install-packages: override-ci-command: << parameters.install-command >> app-dir: << parameters.working-directory >> diff --git a/src/examples/pnpm-version.yml b/src/examples/pnpm-version.yml new file mode 100644 index 00000000..29f932e0 --- /dev/null +++ b/src/examples/pnpm-version.yml @@ -0,0 +1,15 @@ +description: > + Runs Cypress tests using pnpm. + Installs dependencies and caches NPM modules and the Cypress binary. +usage: + version: 2.1 + orbs: + cypress: cypress-io/cypress@3 + workflows: + use-my-orb: + jobs: + - cypress/run: + package-manager: "pnpm" + package-manager-version: "9.7.1" + start-command: "pnpm start" + install-command: "pnpm install" diff --git a/src/examples/pnpm.yml b/src/examples/pnpm.yml index a979d63f..3667f3de 100644 --- a/src/examples/pnpm.yml +++ b/src/examples/pnpm.yml @@ -11,4 +11,4 @@ usage: - cypress/run: package-manager: "pnpm" start-command: "pnpm start" - install-command: "pnpm install --frozen-lockfile" + install-command: "pnpm install" diff --git a/src/examples/yarn-version.yml b/src/examples/yarn-version.yml new file mode 100644 index 00000000..3289a0d8 --- /dev/null +++ b/src/examples/yarn-version.yml @@ -0,0 +1,14 @@ +description: > + Runs Cypress tests using yarn. + Installs dependencies and caches NPM modules and the Cypress binary. +usage: + version: 2.1 + orbs: + cypress: cypress-io/cypress@3 + workflows: + use-my-orb: + jobs: + - cypress/run: + package-manager: "yarn" + package-manager-version: "1.22.5" + start-command: "yarn start" diff --git a/src/jobs/run.yml b/src/jobs/run.yml index d338b59a..366e8704 100644 --- a/src/jobs/run.yml +++ b/src/jobs/run.yml @@ -54,6 +54,14 @@ parameters: enum: ["npm", "yarn", "yarn-berry", "pnpm"] default: "npm" description: Select the default node package manager to use. NPM v5+ Required. + package-manager-version: + type: string + default: "" + description: | + If you need to specify a version of the package manager, you can do so here. + This is useful if you need to use a specific version of Yarn or PNPM. + If you are using Yarn Berry, you can specify the version here. + If you are using NPM, this parameter will be ignored. start-command: description: Command used to start your local dev server for Cypress to tests against type: string @@ -87,6 +95,7 @@ steps: node-cache-version: << parameters.node-cache-version >> working-directory: << parameters.working-directory >> package-manager: << parameters.package-manager >> + package-manager-version: << parameters.package-manager-version >> include-branch-in-node-cache-key: << parameters.include-branch-in-node-cache-key >> install-browsers: << parameters.install-browsers >> skip-checkout: << parameters.skip-checkout >>