Skip to content

在pnpm6.x版本中,如何缓存依赖 #183

@seepine

Description

@seepine

目前遇到一个旧项目,使用node12和pnpm6,准备脚本如下

name: 'Node.js and pnpm Setup'
description: '准备 Node.js 和 pnpm 环境,并安装依赖'

inputs:
  node-version:
    description: "要使用的 Node.js 版本"
    required: false
    default: '12.x'
  pnpm-version:
    description: "要使用的 Pnpm 版本"
    required: false
    default: '6.10'

runs:
  using: "composite"
  steps:
    - name: Setup pnpm
      uses: pnpm/action-setup@v2.0.0
      with:
        version: ${{ inputs.pnpm-version }}

    - name: Expose pnpm config
      shell: bash
      run: |
        echo "STORE_PATH=$(pnpm store path)"
        echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV

    - name: Cache pnpm
      uses: actions/cache@v3
      with:
        path: |
          ${{ env.STORE_PATH }}
          node_modules
        key: ${{ runner.os }}-${{ hashFiles('package.json') }}

    - name: Setup Node
      uses: actions/setup-node@v2
      with:
        node-version: ${{ inputs.node-version }}

    - name: Install dependencies
      shell: bash
      run: pnpm install --frozen-lockfile --prefer-offline --shamefully-hoist

使用如下,但是每次都会重新下载依赖并没有缓存

name: Build

on:
  push:
    tags:
      - v*

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup and Install
        uses: ./.github/actions/setup-pnpm

      - name: Build
        run: pnpm build

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions