pnpm/action-setup

repository·master·Indexed 23 days ago

https://github.com/pnpm/action-setup

A GitHub Action to install and configure the pnpm package manager. It supports version management (via the version input or package.json packageManager field), automatic dependency installation through run_install, and pnpm store caching. It also features a standalone mode using @pnpm/exe for Node.js compatibility and provides outputs for the installation destination and binary path.

Tokens
2.2K
Snippets
4
Records
18
Agent score
77%

What's inside pnpm-action-setup

  1. Setup pnpm in GitHub Actions

    master

    Use pnpm/action-setup to install the pnpm package manager in your GitHub Actions workflows.

    Important Note: This action does not set up Node.js. You should use actions/setup-node separately to ensure a Node.js environment is available before running this action.

    If you are upgrading from v2, please upgrade to the latest version (v6+) as v2 is incompatible with newer Node.js versions.

    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - uses: pnpm/action-setup@v6
        with:
          version: 10
  2. Configure `cache` for pnpm store

    master

    Enable caching of the pnpm store directory to reduce installation times in your workflows.

    • cache (boolean, default: false): Set to true to enable caching.
    • cache_dependency_path (string, default: pnpm-lock.yaml): The file path to the lockfile used to generate the cache key. You can provide multiple paths by separating them with newlines.

    Note: You do not need to run pnpm store prune at the end of your job; the action's post-run step handles this automatically.

    - uses: pnpm/action-setup@v6
      with:
        version: 10
        cache: true
        cache_dependency_path: |
          one/pnpm-lock.yaml
          two/pnpm-lock.yaml
  3. Configure the `version` input

    master

    Specifies the version of pnpm to install. It supports the npm versioning scheme (e.g., 10.9.8, 10, ^10.9.8, *, or latest).

    • Required: If your package.json does not contain a packageManager field.
    • Optional: If a packageManager field is present in your package.json, this action will automatically use that version.
  4. Configure `run_install` to automate dependency installation

    master

    The run_install input allows you to run pnpm install automatically during the action setup.

    • null or false (default): pnpm will not install any packages.
    • true: Runs pnpm install to install dependencies recursively.
    • YAML String (Object/Array): You can provide a list of specific install commands or configurations.

    run_install Configuration Options:

    • recursive (boolean, default: false): Whether to use pnpm recursive install.
    • cwd (string): The working directory for the install command.
    • args (string[]): Additional arguments passed to the command (e.g., [--ignore-scripts]).
    - uses: pnpm/action-setup@v6
      with:
        version: 10
        run_install: |
          - recursive: true
            args: [--strict-peer-dependencies]
          - args: [--global, gulp, prettier, typescript]
  5. Configure `standalone` mode

    master
    When standalone is set to true, the action installs @pnpm/exe (a Node.js bundled package). This allows you to use pnpm even if the current Node.js version is incompatible with the version of pnpm you are trying to use.
  6. Configure the run_install input

    master

    The run_install input allows you to specify one or more pnpm install commands to run during the action setup. The input accepts YAML-formatted values and supports several shapes:

    • Boolean: Passing true is equivalent to running pnpm install --recursive.
    • Object: A single configuration object defining recursive, cwd, and args.
    • Array of Objects: Multiple configuration objects to run multiple install commands.

    Configuration Options

    KeyTypeDescription
    recursivebooleanIf true, runs the install command recursively.
    cwdstringThe working directory in which to run the command.
    argsarray of stringsAdditional arguments to pass to the pnpm install command.

    Examples

    Run a simple recursive install:

    run_install: true

    Run a single install with specific arguments in a directory:

    run_install:
      cwd: ./apps/web
      args: ['--frozen-lockfile']

    Run multiple distinct install commands:

    run_install:
      - cwd: ./packages/core
        args: ['--prefer-offline']
      - recursive: true
  7. Install pnpm using the install function

    master

    The install function is the primary entrypoint for setting up the pnpm/action-setup logic. It executes the pnpm self-installer based on the provided Inputs.

    If the installation is successful, it returns the destination path of the pnpm binary (binDest). If the installation fails (indicated by a non-zero exit code from the self-installer), it calls setFailed to fail the GitHub Action and returns undefined.

  8. Configure pnpm install options

    master

    When using runPnpmInstall, the inputs.runInstall property provides an array of configuration objects. Each object allows you to specify how the pnpm install command should behave:

    • recursive: If true, prepends the recursive flag to the command (pnpm recursive install).
    • args: An array of additional CLI arguments to append to the command.
    • cwd: The current working directory in which the command should run.
  9. Save the pnpm cache with saveCache()

    master
    The saveCache function is an entrypoint used to persist the pnpm cache during a GitHub Action workflow. It only executes if the cache input is enabled. If the cache saving process fails, it will trigger a failure in the GitHub Action via setFailed.
  10. Restore the pnpm cache using restoreCache

    master
    The restoreCache function attempts to restore the pnpm cache if caching is enabled in the inputs. It first checks if the GitHub Actions cache feature is available; if not, it issues a warning and skips restoration. If available, it executes the cache restoration process within a logged group named 'Restoring cache...'.