当前位置: 首页 > 文档资料 > Yarn 中文文档 >

Continuous Integration

优质
小牛编辑
126浏览
2023-12-01

Yarn can easily be used in various continuous integration systems. To speed up builds, the Yarn cache directory can be saved across builds.

AppVeyor

Yarn is preinstalled on AppVeyor,
so you don’t need to do anything extra in order to use it as part of your
build.

To speed up your builds, you can cache Yarn’s cache folder by adding this to
your appveyor.yml:

cache:
 - "%LOCALAPPDATA%\\Yarn"

CircleCI

CircleCI provides documentation for Yarn. You can get up and running by following their Yarn documentation.

Codeship

Yarn is pre-installed Codeship Basic.

If you are using Codeship Pro (with Docker), it is recommended to install Yarn via our Debian/Ubuntu package
instead.

Travis

Travis CI detects the use of Yarn by the presence of yarn.lock in the repository root.
If it is available, Travis CI will install yarn if necessary, and execute yarn as the default install command.

If your install phase requires more, it is necessary to install Yarn yourself until it is pre-installed on build images.

There are a couple of ways to install Yarn; one with sudo, the other without.
If you are using the container-based environment
use the latter.

sudo-enabled builds

sudo: required
before_install: # if "install" is overridden
  # Repo for Yarn
  - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
  - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  - sudo apt-get update -qq
  - sudo apt-get install -y -qq yarn
cache:
  yarn: true

It is recommended that you lock in a specific version of Yarn, so that all your builds use the same version of Yarn, and you can test new Yarn releases before switching over. You can do this by adding the version number to the apt-get install call:

sudo apt-get install -y -qq yarn=1.13.0-1

container-based builds

Container-based builds do not have the sudo privilege, so they must rely on other means to install.
For example:

sudo: false
before_install:
  - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0
  - export PATH=$HOME/.yarn/bin:$PATH
cache:
  yarn: true

Semaphore

Semaphore has Yarn pre-installed for all supported Node.js versions, and no user interaction is required for the Yarn cache to work.

To assure that your local Yarn version matches the one on Semaphore, add the lines below to your setup commands, in Project Settings.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# install-package is a tool for caching APT installations in Semaphore
# defining a package version is optional
install-package --update-new yarn=<version>

SolanoCI

Yarn is pre-installed on SolanoCI. You can quickly get up and running by following their Yarn documentation. For an example configuration file, check out one of their sample configuration files.

GitLab

Because [GitLab CI](https://about.gitlab.com/product/continuous-integration/) uses docker in the background, you can specify an image with yarn pre-installed.
# .gitlab-ci.yml
image: node:9.4.0

If you’re using a docker image that doesn’t come with yarn pre-installed you can still install it after the container has loaded.

# .gitlab-ci.yml
image: does-not-have-yarn

before_script:
  # Install yarn as outlined in (https://yarnpkg.com/lang/en/docs/install/#alternatives-stable)
  - curl -o- -L https://yarnpkg.com/install.sh | bash

In either case, it’s good practice to cache your node_modules and .yarn folders as well to speed up your builds.

# .gitlab-ci.yml
cache:
  paths:
    - node_modules/
    - .yarn

Here’s an example .gitlab-ci.yml file using yarn to run a testing suite.
Just save this file to the root of your project and GitLab’s CI will pick up the jobs.

# .gitlab-ci.yml
image: node:9.11.1

before_script:
  - yarn install

test:
  stage: test
  cache:
    paths:
    - node_modules/
    - .yarn