pnpm / pnpm/action-setup

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

Open
#183 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
217
Avg merge
8h 42m
Merged PRs (30d)
1

Description

目前遇到一个旧项目,使用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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the local .github/actions/setup-pnpm action and the workflow shown in the issue, focusing on the pnpm store path and the actions/cache step. Check how the Node.js and pnpm setup steps interact with cache restoration, then verify the workflow on a repeated run. Done means the existing pnpm dependencies are restored instead of being downloaded again.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, node.js
Domain
ci-cd
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.