持续集成
从上面的选项中选择您正在使用持续集成系统
Yarn已预先安装在 AppVeyor 上,所以不需要在构建流程中做别的事情。
要让构建速度更快,你可以把以下代码添加到appveyor.yml
文件中,缓存Yarn 的 cache 文件夹。
cache:
- "%LOCALAPPDATA%\\Yarn"
在 Codeship 上,您可以通过将如下代码添加到你的项目设置中的安装命令里,从而把安装 Yarn 作为构建过程的一部分︰
npm install --global yarn
如果您使用的 Codeship 的 Docker 平台,建议通过我们的 Debian/Ubuntu 包来安装 Yarn。
Travis CI 根据项目根目录里面是否有 yarn.lock
来检测是否在用 Yarn。 如果文件可用,Travis CI 会根据需要来安装 yarn
,将执行yarn
作为默认的安装命令。
如果你的安装流程需要更多,要自己安装 Yarn,确保它在 build 镜像里已经预先安装好。
安装 Yarn 有两种方式:用sudo
,或者不用。 如果你用的是基于容器的环境的话, 用第二种方式。
开启sudo
的构建
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
建议你锁定 Yarn 版本号,这样每次构建用的都是同一版本的 Yarn。而且在切换之前,你可以先测试新版本的 Yarn。 你可以添加版本号到 apt-get install
命令,以执行︰
sudo apt-get install -y -qq yarn=0.21.3-1
基于容器的构建
基于容器的构建没有 sudo
权限,必须通过其他方式安装。 比如:
sudo: false
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
cache:
yarn: true
Semaphore 在所有支持的 Node.js 版本里预安装了 Yarn,让 Yarn 缓存工作不需要用户做更多的事情。
为了保证本地 Yarn 版本和 Semaphore 上的一致,可以在项目设置里加上以下几行到你的设置命令中:
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 是在 Semaphore 里缓存 APT 安装程序的工具
# 包版本号可以也可以不定义
install-package yarn=<version>
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.