持續整合 (CI)
pnpm 可以很容易地用在多種 CI 系統中。
備註
本篇指南提供的範例,都有啟用儲存區快取功能。 不過此功能是非強制的,且開啟儲存區快取不一定會讓安裝更快。 因此您可以依需要決定是否啟用。
Travis
On Travis CI, you can use pnpm for installing your dependencies by adding this
to your .travis.yml
file:
.travis.yml
cache:
npm: false
directories:
- "~/.pnpm-store"
before_install:
- npm install --global corepack@latest
- corepack enable
- corepack prepare pnpm@latest-10 --activate
- pnpm config set store-dir ~/.pnpm-store
install:
- pnpm install
Semaphore
On Semaphore, you can use pnpm for installing and caching your dependencies by
adding this to your .semaphore/semaphore.yml
file:
.semaphore/semaphore.yml
version: v1.0
name: Semaphore CI pnpm example
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: Install dependencies
task:
jobs:
- name: pnpm install
commands:
- npm install --global corepack@latest
- corepack enable
- corepack prepare pnpm@latest-10 --activate
- checkout
- cache restore node-$(checksum pnpm-lock.yaml)
- pnpm install
- cache store node-$(checksum pnpm-lock.yaml) $(pnpm store path)
AppVeyor
On AppVeyor, you can use pnpm for installing your dependencies by adding this
to your appveyor.yml
:
appveyor.yml
install:
- ps: Install-Product node $env:nodejs_version
- npm install --global corepack@latest
- corepack enable
- corepack prepare pnpm@latest-10 --activate
- pnpm install
GitHub Actions
On GitHub Actions, you can use pnpm for installing and caching your dependencies
like so (belongs in .github/workflows/NAME.yml
):
.github/workflows/NAME.yml
name: pnpm Example Workflow
on:
push:
jobs:
build:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
GitLab CI
On GitLab, you can use pnpm for installing and caching your dependencies
like so (belongs in .gitlab-ci.yml
):
.gitlab-ci.yml
stages:
- build
build:
stage: build
image: node:18.17.1
before_script:
- npm install --global corepack@latest
- corepack enable
- corepack prepare pnpm@latest-10 --activate
- pnpm config set store-dir .pnpm-store
script:
- pnpm install # install dependencies
cache:
key:
files:
- pnpm-lock.yaml
paths:
- .pnpm-store
Bitbucket Pipelines
使用 pnpm 安裝、快取相依性的方法如下:
.bitbucket-pipelines.yml
definitions:
caches:
pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store
pipelines:
pull-requests:
"**":
- step:
name: Build and test
image: node:18.17.1
script:
- npm install --global corepack@latest
- corepack enable
- corepack prepare pnpm@latest-10 --activate
- pnpm install
- pnpm run build # Replace with your build/test…etc. commands
caches:
- pnpm