mirror of
https://github.com/actions/setup-node.git
synced 2026-02-05 23:18:22 +00:00
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:
parent
6044e13b5d
commit
dff445bec7
5 changed files with 109 additions and 3 deletions
29
dist/cache-save/index.js
vendored
29
dist/cache-save/index.js
vendored
|
|
@ -44084,6 +44084,14 @@ const cachePackages = async (packageManager) => {
|
|||
core.debug(`Caching for '${packageManager}' is not supported`);
|
||||
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 (0, cache_utils_1.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;
|
||||
|
|
@ -44147,7 +44155,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.repoHasYarnBerryManagedDependencies = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
||||
exports.repoHasYarnBerryManagedDependencies = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.isPackageManagerInstalled = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
||||
exports.isGhes = isGhes;
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
|
|
@ -44218,6 +44226,25 @@ const getPackageManagerInfo = async (packageManager) => {
|
|||
}
|
||||
};
|
||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||
/**
|
||||
* Checks if a package manager is installed and available on the PATH
|
||||
* This helps prevent cache failures when a package manager is specified
|
||||
* but not yet installed (e.g., pnpm via corepack)
|
||||
* See: https://github.com/actions/setup-node/issues/1357
|
||||
*/
|
||||
const isPackageManagerInstalled = async (packageManager) => {
|
||||
try {
|
||||
const { exitCode } = await exec.getExecOutput(`${packageManager} --version`, undefined, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
return exitCode === 0;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
exports.isPackageManagerInstalled = isPackageManagerInstalled;
|
||||
/**
|
||||
* getProjectDirectoriesFromCacheDependencyPath is called twice during `restoreCache`
|
||||
* - first through `getCacheDirectories`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue