handle non-dir cache-dependency-path

This commit is contained in:
Sergey Dolin 2023-05-04 16:05:46 +02:00
parent 813556063c
commit a3d2aaf78f
5 changed files with 118 additions and 61 deletions

View file

@ -56,8 +56,8 @@ export const restoreCache = async (
const findLockFile = (packageManager: PackageManagerInfo) => {
const lockFiles = packageManager.lockFilePatterns;
const workspace =
getPackageManagerWorkingDir() || process.env.GITHUB_WORKSPACE!;
const workspace = process.env.GITHUB_WORKSPACE!;
const rootContent = fs.readdirSync(workspace);
const lockFile = lockFiles.find(item => rootContent.includes(item));

View file

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as cache from '@actions/cache';
import path from 'path';
import fs from 'fs';
type SupportedPackageManagers = {
[prop: string]: PackageManagerInfo;
@ -58,7 +59,17 @@ export const getPackageManagerWorkingDir = (): string | null => {
}
const cacheDependencyPath = core.getInput('cache-dependency-path');
return cacheDependencyPath ? path.dirname(cacheDependencyPath) : null;
if (!cacheDependencyPath) {
return null;
}
const wd = path.dirname(cacheDependencyPath);
if (fs.existsSync(wd) && fs.lstatSync(wd).isDirectory()) {
return wd;
}
return null;
};
export const getPackageManagerCommandOutput = (command: string) =>