fix(#1357): Gracefully handle missing pnpm installation during cache

This change prevents the action from failing immediately when pnpm is specified
in packageManager but not yet installed (e.g., when using corepack).

Changes:
- Add isPackageManagerInstalled() function to check if a package manager exists
- Update restoreCache to skip caching with a warning if package manager not found
- Update cachePackages to skip cache save with a warning if package manager not found
- This allows workflows to continue instead of failing
- Users can either install pnpm first or disable caching with package-manager-cache: false

Fixes #1357
Related: https://github.com/actions/setup-node/issues/1357
This commit is contained in:
Satishchoudhary94 2026-01-18 14:08:11 +00:00
commit dff445bec7
5 changed files with 109 additions and 3 deletions

View file

@ -2,7 +2,7 @@ import * as core from '@actions/core';
import * as cache from '@actions/cache';
import {State} from './constants';
import {getPackageManagerInfo} from './cache-utils';
import {getPackageManagerInfo, isPackageManagerInstalled} from './cache-utils';
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
@ -45,6 +45,17 @@ const cachePackages = async (packageManager: string) => {
return;
}
// Check if the package manager is installed before attempting to save cache
// This prevents cache save failures for package managers that may not be installed
const isInstalled = await isPackageManagerInstalled(packageManager);
if (!isInstalled) {
core.warning(
`Package manager '${packageManager}' was not found in the PATH. ` +
`Skipping cache save.`
);
return;
}
if (!cachePaths.length) {
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
// export declare function getInput(name: string, options?: InputOptions): string;