* A function that generates a cache key to use. * Format of the generated key will be "${{ platform }}-${{ id }}-${{ fileHash }}"". * @see https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key|spec of cache key
( packageManager: PackageManager, cacheDependencyPath: string )
| 89 | * @see {@link https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key|spec of cache key} |
| 90 | */ |
| 91 | async function computeCacheKey( |
| 92 | packageManager: PackageManager, |
| 93 | cacheDependencyPath: string |
| 94 | ) { |
| 95 | const pattern = cacheDependencyPath |
| 96 | ? cacheDependencyPath.trim().split('\n') |
| 97 | : packageManager.pattern; |
| 98 | const fileHash = await glob.hashFiles(pattern.join('\n')); |
| 99 | if (!fileHash) { |
| 100 | throw new Error( |
| 101 | `No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository` |
| 102 | ); |
| 103 | } |
| 104 | return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Restore the dependency cache |