持续集成

pnpm 可以很容易地用于各种持续集成系统。

Travis

Travis CI,请将此添加到您的 .travis.yml 文件中,使用 pnpm 来安装您的依赖项:

.travis.yml

  1. cache:
  2. npm: false
  3. directories:
  4. - "~/.pnpm-store"
  5. before_install:
  6. - corepack enable
  7. - corepack prepare pnpm@latest-7 --activate
  8. - pnpm config set store-dir ~/.pnpm-store
  9. install:
  10. - pnpm install

Semaphore

Semapore上 ,请将此内容添加到 .semaphore/semaphore.yml 文件中,使用 pnpm 来安装和缓存您的依赖:

.semaphore/semaphore.yml

  1. version: v1.0
  2. name: Semaphore CI pnpm example
  3. agent:
  4. machine:
  5. type: e1-standard-2
  6. os_image: ubuntu1804
  7. blocks:
  8. - name: Install dependencies
  9. task:
  10. jobs:
  11. - name: pnpm install
  12. commands:
  13. - corepack enable
  14. - corepack prepare pnpm@latest-7 --activate
  15. - checkout
  16. - cache restore node-$(checksum pnpm-lock.yaml)
  17. - pnpm install
  18. - cache store node-$(checksum pnpm-lock.yaml) $(pnpm store path)

AppVeyor

AppVeyor ,请将此添加您的 appveyor.yml来使用 pnpm 来安装您的依赖项:

appveyor.yml

  1. install:
  2. - ps: Install-Product node $env:nodejs_version
  3. - corepack enable
  4. - corepack prepare pnpm@latest-7 --activate
  5. - pnpm install

GitHub Actions

在 GitHub Actions 上,您可以像这样使用 pnpm 安装和缓存您的依赖项 .github/workflows/NAME.yml):

.github/workflows/NAME.yml

  1. name: pnpm Example Workflow
  2. on:
  3. push:
  4. jobs:
  5. build:
  6. runs-on: ubuntu-20.04
  7. strategy:
  8. matrix:
  9. node-version: [15]
  10. steps:
  11. - uses: actions/checkout@v3
  12. - uses: pnpm/action-setup@v2
  13. with:
  14. version: 7
  15. - name: Use Node.js ${{ matrix.node-version }}
  16. uses: actions/setup-node@v3
  17. with:
  18. node-version: ${{ matrix.node-version }}
  19. cache: 'pnpm'
  20. - name: Install dependencies
  21. run: pnpm install

:::注意

使用 actions/setup-node@v2 缓存包依赖项要求您安装版本 6.10+ 的 pnpm。

:::

GitLab CI

在 Gitlab 上,您可以使用 pnpm 来安装和缓存您的依赖项 像这样(在 .gitlab-ci.yml 中):

.gitlab-ci.yml

  1. stages:
  2. - build
  3. build:
  4. stage: build
  5. image: node:14.16.0-buster
  6. before_script:
  7. - corepack enable
  8. - corepack prepare pnpm@latest-7 --activate
  9. - pnpm config set store-dir .pnpm-store
  10. script:
  11. - pnpm install # install dependencies
  12. cache:
  13. key:
  14. files:
  15. - pnpm-lock.yaml
  16. paths:
  17. - .pnpm-store

Bitbucket Pipelines

您可以使用 pnpm 来安装和缓存您的依赖项:

.bitbucket-pipelines.yml

  1. definitions:
  2. caches:
  3. pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store
  4. pipelines:
  5. pull-requests:
  6. "**":
  7. - step:
  8. name: Build and test
  9. image: node:14.16.0
  10. script:
  11. - corepack enable
  12. - corepack prepare pnpm@latest-7 --activate
  13. - pnpm install
  14. - pnpm run build # Replace with your build/test…etc. commands
  15. caches:
  16. - pnpm

Azure Pipelines

在 Azure pipeline 中,您可以将以下内容添加到 Azure-Pipelines.yml 中,使用 pnpm 安装和缓存依赖项:

azure-pipelines.yml

  1. variables:
  2. pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store
  3. steps:
  4. - task: Cache@2
  5. inputs:
  6. key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml'
  7. path: $(pnpm_config_cache)
  8. displayName: Cache pnpm
  9. - script: |
  10. corepack enable
  11. corepack prepare pnpm@latest-7 --activate
  12. pnpm config set store-dir $(pnpm_config_cache)
  13. displayName: "Setup pnpm"
  14. - script: |
  15. pnpm install
  16. pnpm run build
  17. displayName: "pnpm install and build"

CircleCI

在 CircleCI 中,您可以将以下内容添加到 .circleci/config.yml 中,使用 pnpm 安装和缓存依赖项:

.circleci/config.yml

  1. version: 2.1
  2. jobs:
  3. build: # this can be any name you choose
  4. docker:
  5. - image: node:18
  6. resource_class: large
  7. parallelism: 10
  8. steps:
  9. - checkout
  10. - restore_cache:
  11. name: Restore pnpm Package Cache
  12. keys:
  13. - pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
  14. - run:
  15. name: Install pnpm package manager
  16. command: |
  17. corepack enable
  18. corepack prepare pnpm@latest-7 --activate
  19. - run:
  20. name: Install Dependencies
  21. command: |
  22. pnpm install
  23. - save_cache:
  24. name: Save pnpm Package Cache
  25. key: pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
  26. paths:
  27. - node_modules

Jenkins

您可以使用 pnpm 来安装和缓存您的依赖项:

  1. pipeline {
  2. agent {
  3. docker {
  4. image 'node:lts-bullseye-slim'
  5. args '-p 3000:3000'
  6. }
  7. }
  8. stages {
  9. stage('Build') {
  10. steps {
  11. sh 'corepack enable'
  12. sh 'corepack prepare pnpm@latest-7 --activate'
  13. sh 'pnpm install'
  14. }
  15. }
  16. }
  17. }