mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2025-05-19 12:54:45 +00:00
Support caching for mono repos and repositories with complex structure
This commit is contained in:
parent
aa759c6c94
commit
9f31dbbbc4
7 changed files with 727 additions and 674 deletions
|
@ -11,7 +11,10 @@ import {
|
|||
PackageManagerInfo
|
||||
} from './cache-utils';
|
||||
|
||||
export const restoreCache = async (packageManager: string) => {
|
||||
export const restoreCache = async (
|
||||
packageManager: string,
|
||||
cacheDependencyPath?: string
|
||||
) => {
|
||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||
if (!packageManagerInfo) {
|
||||
throw new Error(`Caching for '${packageManager}' is not supported`);
|
||||
|
@ -22,9 +25,17 @@ export const restoreCache = async (packageManager: string) => {
|
|||
packageManagerInfo,
|
||||
packageManager
|
||||
);
|
||||
const lockFilePath = findLockFile(packageManagerInfo);
|
||||
const lockFilePath = cacheDependencyPath
|
||||
? cacheDependencyPath
|
||||
: findLockFile(packageManagerInfo);
|
||||
const fileHash = await glob.hashFiles(lockFilePath);
|
||||
|
||||
if (!fileHash) {
|
||||
throw new Error(
|
||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
||||
);
|
||||
}
|
||||
|
||||
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@ export async function run() {
|
|||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
await restoreCache(cache);
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
|
||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue