Skip to content

Commit

Permalink
Merge pull request #5106 from rak-phillip/feature/3723-yarn-migration
Browse files Browse the repository at this point in the history
Migrate Project from npm to Yarn
  • Loading branch information
ml8mr authored Jul 19, 2023
2 parents ca01e9d + 9269200 commit 6c76b71
Show file tree
Hide file tree
Showing 46 changed files with 21,368 additions and 69,388 deletions.
9 changes: 5 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ task:
apt-get update
apt-get install --yes nodejs
node --version && npm --version
npm install --global yarn
# Info about Cirrus CI caching see: https://cirrus-ci.org/guide/writing-tasks/#cache-instruction
node_modules_cache:
folder: /home/ranchertest/src/node_modules
fingerprint_script: cat package-lock.json
fingerprint_script: cat yarn.lock
populate_script:
# Passing DEBUG=pw:install in order to verify if all Playwright deps were installed properly
- ${SUDO_NON_ROOT_CMD} DEBUG=pw:install npm ci
- ${SUDO_NON_ROOT_CMD} DEBUG=pw:install yarn install --frozen-lockfile
# `playwright install-deps` needs to be run as root, as it does apt-get things.
- /usr/bin/env --chdir=/home/ranchertest/src ./node_modules/.bin/playwright install-deps

Expand All @@ -64,11 +65,11 @@ task:
# CirrusCI caching doesn't seem to maintain the UID; we'll need to reset the ownership to ensure
# we can build files in it.
- chown -R ranchertest:ranchertest /home/ranchertest/src/node_modules
- ${SUDO_NON_ROOT_CMD} npm run postinstall
- ${SUDO_NON_ROOT_CMD} yarn postinstall

test_script:
- export KUBECONFIG=/home/ranchertest/.kube/config
- ${SUDO_NON_ROOT_CMD} xvfb-run --auto-servernum -- npm run test:e2e
- ${SUDO_NON_ROOT_CMD} xvfb-run --auto-servernum -- yarn test:e2e

on_failure:
# custom_script workaround for cirrus bug: https://github.com/cirruslabs/cirrus-ci-agent/issues/197
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-cli-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
with:
node-version: '16.x'

- run: npm ci
- run: yarn install --frozen-lockfile

- run: npm run dcmonitor
- run: yarn dcmonitor
env:
GITHUB_TOKEN: ${{ secrets.RUN_WORKFLOW_FROM_WORKFLOW }}
6 changes: 3 additions & 3 deletions .github/workflows/macM1-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
go-version: '^1.18'
- name: Install dependencies
run: npm ci
run: yarn install --frozen-lockfile
#The next steps is a workaround for an unexpected failure in launching electron before running e2e tests
#Such failure is addressed in issue #2915
- name: add tools to PATH
Expand Down Expand Up @@ -52,13 +52,13 @@ jobs:
EOF
- name: Run Rancher Desktop in dev
run: |
npm run dev -- --no-modal-dialogs &
yarn dev -- --no-modal-dialogs &
sleep 200
$HOME/.rd/bin/rdctl shutdown
wait
- name: Run e2e Tests
continue-on-error: false
run: npm run test:e2e
run: yarn test:e2e
- name: Failed tests
if: failure()
run: mkdir -p ./e2e/reports
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ jobs:
- name: Flag build for M1
if: matrix.arch == 'aarch64' && matrix.platform == 'mac'
run: echo "M1=1" >> "${GITHUB_ENV}"
- name: Upgrade npm
# We do this to avoid https://github.com/npm/cli/issues/3079
run: |
npm install -g npm@9
npm --version
- run: npm ci
- run: npm run build
- run: npm run package -- --${{ matrix.platform }} --publish=never
# Needs a network timeout for macos & windows. See https://github.com/yarnpkg/yarn/issues/8242 for more info
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn build
- run: yarn package --${{ matrix.platform }} --publish=never
- name: Build bats.tar.gz
if: matrix.platform == 'linux'
run: make -C bats bats.tar.gz
Expand Down Expand Up @@ -163,7 +159,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- run: npm ci
- run: yarn install --frozen-lockfile
- uses: actions/download-artifact@v3
if: runner.os == 'Windows'
with:
Expand All @@ -182,7 +178,7 @@ jobs:
Write-Output $cert
$env:CSC_FINGERPRINT = $cert.Thumbprint
# Run the signing script
npm run sign -- (Get-Item "Rancher Desktop*-win.zip")
yarn sign -- (Get-Item "Rancher Desktop*-win.zip")
# Check that the msi file was signed by the expected cert
$usedCert = (Get-AuthenticodeSignature -FilePath 'dist\Rancher Desktop Setup*.msi').SignerCertificate
Write-Output $usedCert
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rddepman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
with:
node-version: '16.x'

- run: npm ci
- run: yarn install --frozen-lockfile

- run: npm run rddepman
- run: yarn rddepman
env:
GITHUB_TOKEN: ${{ secrets.RUN_WORKFLOW_FROM_WORKFLOW }}
11 changes: 7 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ jobs:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- uses: actions/setup-go@v4
with:
go-version: '^1.18'
- run: npm ci
- run: npm run build
- run: npm run lint:nofix
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn lint:nofix
- name: Install shfmt
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.7.0
- run: make -C bats lint
- run: npm test
- run: yarn test
4 changes: 2 additions & 2 deletions .github/workflows/ucmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
with:
node-version: '16.x'

- run: npm ci
- run: yarn install --frozen-lockfile

- run: npm run ucmonitor
- run: yarn ucmonitor
env:
GITHUB_TOKEN: ${{ secrets.RUN_WORKFLOW_FROM_WORKFLOW }}
8 changes: 4 additions & 4 deletions .github/workflows/upgrade-generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
- name: Flag build for M1
if: matrix.arch == 'aarch64' && matrix.platform == 'mac'
run: echo "M1=1" >> "${GITHUB_ENV}"
- run: npm ci
- run: npm run build
- run: npm run package -- --${{ matrix.platform }} --publish=never
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn package --${{ matrix.platform }} --publish=never
- name: Upload Windows exe installer
if: runner.os == 'Windows'
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- run: npm ci
- run: yarn install --frozen-lockfile
- name: Download installer (exe)
id: exe
uses: actions/download-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
# random.
cache-dependency-path: src/go/rdctl/go.sum
- name: Install dependencies
run: npm ci
run: yarn install --frozen-lockfile
- name: Run e2e Tests
run: npm run test:e2e
run: yarn test:e2e
env:
RD_DEBUG_ENABLED: '1'
- name: Upload failure reports
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In this case 123 is the corresponding issue number.

Every pull request triggers a full run of testing in the CI system.
The failures reported by the code style checker (aka the "linter") and the unit tests are usually
clear and easy to fix (and can be avoided by running `npm test` locally before creating a commit).
clear and easy to fix (and can be avoided by running `yarn test` locally before creating a commit).
But when an integration, or e2e test, fails, it's sometimes useful to consult the log files
for the run.

Expand Down
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ It bundles a variety of other technologies in order to provide one cohesive appl
It includes a command line tool, `rdctl`, which is written in Go.
Most developer activities, such as running a development build, building/packaging
Rancher Desktop, running unit tests, and running end-to-end tests, are done through
`npm run` scripts. Some exceptions exist, such as running BATS tests.
`yarn` scripts. Some exceptions exist, such as running BATS tests.


## Setup
Expand Down Expand Up @@ -58,7 +58,7 @@ with an existing Windows installation.
npm config set msbuild_path "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
```

You can now clone the repository and run `npm install`.
You can now clone the repository and run `yarn`.

[development virtual machine]: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
[automated setup script]: ./scripts/windows-setup.ps1
Expand All @@ -71,9 +71,10 @@ You can now clone the repository and run `npm install`.
3. Install [Scoop] via `iwr -useb get.scoop.sh | iex`.
4. Install git, go, nvm, and unzip via `scoop install git go nvm python unzip`.
Check node version with `nvm list`. If node v16 is not installed or set as the current version, then install using `nvm install 16` and set as current using `nvm use 16.xx.xx`.
5. Install Visual Studio 2017 or higher. Make sure you have the `Windows SDK` component installed. This [Visual Studio docs] describes steps to install components.
5. Install the yarn package manager via `npm install --global yarn`
6. Install Visual Studio 2017 or higher. Make sure you have the `Windows SDK` component installed. This [Visual Studio docs] describes steps to install components.
The [Desktop development with C++] workload needs to be selected, too.
6. Ensure `msbuild_path` and `msvs_version` are configured correctly in `.npmrc` file. Run the following commands to set these properties:
7. Ensure `msbuild_path` and `msvs_version` are configured correctly in `.npmrc` file. Run the following commands to set these properties:

```
npm config set msvs_version <visual-studio-version-number>
Expand All @@ -87,7 +88,7 @@ You can now clone the repository and run `npm install`.
npm config set msbuild_path "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
```

You can now clone the repository and run `npm install`.
You can now clone the repository and run `yarn`.

[Scoop]: https://scoop.sh/
[Visual Studio docs]: https://docs.microsoft.com/en-us/visualstudio/install/modify-visual-studio?view=vs-2022
Expand All @@ -111,11 +112,17 @@ Currently we build Rancher Desktop with Node 16. To install it, run:
nvm install 16
```

Next, you'll need to install the yarn package manager:

```
npm install --global yarn
```

You'll also need to run `brew install go` if you haven't installed go.

Then you can install dependencies with:
```
npm install
yarn
```

> ### ⚠️ Working on a mac with an M1 chip?
Expand All @@ -124,10 +131,10 @@ npm install
>
> ```
> export M1=1
> npm install
> yarn
> ```
>
> You will want to run `git clean -fdx` to clean out any cached assets and re-downloaded with the correct arch before running `npm install` if you previously installed dependencies without setting `M1` first.
> You will want to run `git clean -fdx` to clean out any cached assets and re-downloaded with the correct arch before running `yarn` if you previously installed dependencies without setting `M1` first.
### Linux

Expand All @@ -137,6 +144,8 @@ Ensure you have the following installed:
installed.** For example, on openSUSE Leap 15.3 you would need to install
`nodejs16` and `nodejs16-devel`.

- [yarn classic][yarn-classic]

- Go 1.18 or later.

- Dependencies described in the [`node-gyp` docs][node-gyp] installation.
Expand All @@ -146,7 +155,7 @@ Ensure you have the following installed:
Then you can install dependencies with:

```
npm install
yarn
```

You can then run Rancher Desktop as described below. It may fail on the first run -
Expand All @@ -156,6 +165,7 @@ to solve this issue.
[Node.js]: https://nodejs.org/
[ffi-napi]: https://www.npmjs.com/package/ffi-napi
[node-gyp]: https://github.com/nodejs/node-gyp#on-unix
[yarn-classic]: https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable


## Running
Expand All @@ -164,7 +174,7 @@ Once you have your dependencies installed you can run a development version
of Rancher Desktop with:

```
npm run dev
yarn dev
```


Expand All @@ -173,13 +183,13 @@ npm run dev
To run the unit tests:

```
npm test
yarn test
```

To run the integration tests:

```
npm run test:e2e
yarn test:e2e
```


Expand All @@ -189,8 +199,8 @@ Rancher can be built from source on Windows, macOS or Linux.
Cross-compilation is currently not supported. To run a build do:

```
npm run build
npm run package --publish=never
yarn build
yarn package --publish=never
```

The build output goes to `dist/`.
Expand Down
4 changes: 2 additions & 2 deletions bats/tests/containers/auto-start.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load '../helpers/load'
}

@test 'Verify that the auto-start config is created' {
if using_npm_run_dev; then
if using_dev_mode; then
skip "Autostart prefs don't work in dev mode"
fi
if is_linux; then
Expand All @@ -57,7 +57,7 @@ load '../helpers/load'
}

@test 'Verify that the auto-start config is removed' {
if using_npm_run_dev; then
if using_dev_mode; then
skip "Autostart prefs don't work in dev mode"
fi
if is_linux; then
Expand Down
10 changes: 5 additions & 5 deletions bats/tests/helpers/defaults.bash
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ validate_enum RD_9P_SECURITY_MODEL passthrough mapped-xattr mapped-file none
# RD_LOCATION specifies the location where Rancher Desktop is installed
# system: default system-wide install location shared for all users
# user: per-user install location
# dist: use the result of `npm run package` in ../dist
# npm: dev mode; start app with `cd ..; npm run dev`
# dist: use the result of `yarn package` in ../dist
# dev: dev mode; start app with `cd ..; yarn dev`
# "": use first location from the list above that contains the app

: "${RD_LOCATION:=}"

validate_enum RD_LOCATION system user dist npm ""
validate_enum RD_LOCATION system user dist dev ""

using_npm_run_dev() {
[ "$RD_LOCATION" = "npm" ]
using_dev_mode() {
[ "$RD_LOCATION" = "dev" ]
}
4 changes: 2 additions & 2 deletions bats/tests/helpers/paths.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ set_path_resources() {
echo "- \"$system\""
echo "- \"$user\""
echo "- \"$dist\""
echo "and 'npm run dev' is unavailable outside repo clone"
echo "and 'yarn dev' is unavailable outside repo clone"
) >&3
exit 1
fi
fi
if using_npm_run_dev; then
if using_dev_mode; then
if is_windows; then
fatal "npm operation not yet implemented for Windows"
fi
Expand Down
Loading

0 comments on commit 6c76b71

Please sign in to comment.