Skip to content

Commit

Permalink
feat: add yarn berry / modern (version 2 and later) examples (#838)
Browse files Browse the repository at this point in the history
* add yarn-modern to update script

* add workflow for yarn modern

* add yarn modern to readme

* create yarn-modern examples

* fix script permissions
  • Loading branch information
MikeMcC399 authored Mar 19, 2023
1 parent e77704d commit d6a7839
Show file tree
Hide file tree
Showing 17 changed files with 5,025 additions and 12 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/example-yarn-modern.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: example-yarn-modern
on:
push:
branches:
- 'master'
pull_request:
workflow_dispatch:

jobs:

# ~~~~~~~~~~~~~~~~~~ Cypress v9 and below (using Legacy configuration) ~~~~~~~~~~~~~~~~~~~ #

yarn-modern-v9:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Custom Yarn command
uses: ./
with:
working-directory: examples/v9/yarn-modern
# https://yarnpkg.com/cli/install
install-command: yarn install

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

yarn-modern:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Custom Yarn command
uses: ./
with:
working-directory: examples/yarn-modern
# https://yarnpkg.com/cli/install
install-command: yarn install
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- generate a [robust custom build id](#robust-custom-build-id) to allow re-running the workflow
- use different [working-directory](#working-directory)
- use [Yarn Classic](#yarn-classic)
- use [Yarn Modern](#yarn-modern)
- use [Yarn workspaces](#yarn-workspaces)
- use [custom cache key](#custom-cache-key)
- run tests on multiple [Node versions](#node-versions)
Expand Down Expand Up @@ -1018,7 +1019,29 @@ See [example-yarn-classic.yml](.github/workflows/example-yarn-classic.yml) for a

[![Yarn classic example](https://github.com/cypress-io/github-action/workflows/example-yarn-classic/badge.svg?branch=master)](.github/workflows/example-yarn-classic.yml)

See below under [Yarn Modern](#yarn-modern) (version 2 and later) for instructions on installing dependencies using this later version.
### Yarn Modern

To install dependencies using a `yarn.lock` file from [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) you need to override the default [Yarn 1 (Classic)](https://classic.yarnpkg.com/) installation command `yarn --frozen-lockfile`. You can do this by using the `install-command` parameter and specifying `yarn install` for example:

```yaml
name: example-yarn-modern
on: push
jobs:
yarn-classic:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cypress run
uses: cypress-io/github-action@v5
with:
working-directory: examples/yarn-modern
install-command: yarn install
```

See [example-yarn-modern.yml](.github/workflows/example-yarn-modern.yml) for an example.

[![Yarn Modern example](https://github.com/cypress-io/github-action/workflows/example-yarn-modern/badge.svg?branch=master)](.github/workflows/example-yarn-modern.yml)

### Yarn workspaces

Expand Down Expand Up @@ -1200,17 +1223,7 @@ See [cypress-gh-action-example](https://github.com/bahmutov/cypress-gh-action-ex

### Installation

This action installs local dependencies using lock files. If `yarn.lock` file is found, the install uses `yarn --frozen-lockfile` command. Otherwise it expects to find `package-lock.json` and install using `npm ci` command.

#### Yarn Modern

The above default `yarn` installation command can be replaced for [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) using the `install-command` parameter, for example:

```yml
- uses: cypress-io/github-action@v5
with:
install-command: yarn install
```
This action installs local dependencies using lock files. If `yarn.lock` file is found, the install uses `yarn --frozen-lockfile` command. Otherwise it expects to find `package-lock.json` and install using `npm ci` command. See the [Yarn Modern](#yarn-modern) example for instructions on installing dependencies using this later version.

#### Minimum Node.js

Expand Down
873 changes: 873 additions & 0 deletions examples/v9/yarn-modern/.yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/v9/yarn-modern/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.4.1.cjs
3 changes: 3 additions & 0 deletions examples/v9/yarn-modern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# example: yarn-modern

This example demonstrates installing dependencies using [Yarn Modern (version 2 and later)](https://yarnpkg.com/).
6 changes: 6 additions & 0 deletions examples/v9/yarn-modern/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fixturesFolder": false,
"supportFile": false,
"pluginsFile": false,
"baseUrl": "https://example.cypress.io/"
}
7 changes: 7 additions & 0 deletions examples/v9/yarn-modern/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />
describe('example: yarn-modern', () => {
it('loads the deployed site', () => {
cy.visit('/')
cy.contains('h1', 'Kitchen Sink')
})
})
14 changes: 14 additions & 0 deletions examples/v9/yarn-modern/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example-yarn-modern",
"version": "1.0.0",
"description": "Install Yarn dependencies using custom command",
"scripts": {
"test": "cypress run"
},
"license": "MIT",
"private": true,
"devDependencies": {
"cypress": "9.7.0"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit d6a7839

Please sign in to comment.