Handle globs in cacheDependencyPath

This commit is contained in:
Sergey Dolin 2023-05-11 09:40:44 +02:00
parent 52e352b14a
commit 6af80f316c
11 changed files with 1714 additions and 290 deletions

View file

@ -2,7 +2,7 @@ import * as core from '@actions/core';
import * as cache from '@actions/cache';
import fs from 'fs';
import {State} from './constants';
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
import {getCacheDirectoriesPaths, getPackageManagerInfo} 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
@ -31,14 +31,15 @@ const cachePackages = async (packageManager: string) => {
return;
}
const cachePath = await getCacheDirectoryPath(
const cacheDependencyPath = core.getInput('cache-dependency-path');
const cachePaths = await getCacheDirectoriesPaths(
packageManagerInfo,
packageManager
cacheDependencyPath
);
if (!fs.existsSync(cachePath)) {
if (cachePaths.length === 0) {
throw new Error(
`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}`
`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`
);
}
@ -49,7 +50,7 @@ const cachePackages = async (packageManager: string) => {
return;
}
const cacheId = await cache.saveCache([cachePath], primaryKey);
const cacheId = await cache.saveCache(cachePaths, primaryKey);
if (cacheId == -1) {
return;
}