mirror of
				https://kkgithub.com/actions/cache.git
				synced 2025-10-25 23:42:19 +08:00 
			
		
		
		
	Address PR feedback
This commit is contained in:
		| @ -86,13 +86,13 @@ function createHttpClient(): HttpClient { | ||||
| } | ||||
|  | ||||
| export function getCacheVersion(compressionMethod?: CompressionMethod): string { | ||||
|     // Add salt to cache version to support breaking changes in cache entry | ||||
|     const components = [core.getInput(Inputs.Path, { required: true })].concat( | ||||
|         compressionMethod == CompressionMethod.Zstd | ||||
|             ? [compressionMethod, versionSalt] | ||||
|             : versionSalt | ||||
|         compressionMethod == CompressionMethod.Zstd ? [compressionMethod] : [] | ||||
|     ); | ||||
|  | ||||
|     // Add salt to cache version to support breaking changes in cache entry | ||||
|     components.push(versionSalt); | ||||
|  | ||||
|     return crypto | ||||
|         .createHash("sha256") | ||||
|         .update(components.join("|")) | ||||
|  | ||||
							
								
								
									
										19
									
								
								src/tar.ts
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/tar.ts
									
									
									
									
									
								
							| @ -22,7 +22,7 @@ async function getTarPath(args: string[]): Promise<string> { | ||||
|  | ||||
| async function execTar(args: string[], cwd?: string): Promise<void> { | ||||
|     try { | ||||
|         await exec(`${await getTarPath(args)}`, args, { cwd: cwd }); | ||||
|         await exec(`"${await getTarPath(args)}"`, args, { cwd: cwd }); | ||||
|     } catch (error) { | ||||
|         throw new Error(`Tar failed with error: ${error?.message}`); | ||||
|     } | ||||
| @ -32,6 +32,10 @@ function getWorkingDirectory(): string { | ||||
|     return process.env["GITHUB_WORKSPACE"] ?? process.cwd(); | ||||
| } | ||||
|  | ||||
| function isOS64(): boolean { | ||||
|     return process.platform != "win32" || process.arch === "x64"; | ||||
| } | ||||
|  | ||||
| export async function extractTar( | ||||
|     archivePath: string, | ||||
|     compressionMethod: CompressionMethod | ||||
| @ -39,9 +43,14 @@ export async function extractTar( | ||||
|     // Create directory to extract tar into | ||||
|     const workingDirectory = getWorkingDirectory(); | ||||
|     await io.mkdirP(workingDirectory); | ||||
|     // --d: Decompress. | ||||
|     // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit. | ||||
|     const args = [ | ||||
|         ...(compressionMethod == CompressionMethod.Zstd | ||||
|             ? ["--use-compress-program", "zstd -d"] | ||||
|             ? [ | ||||
|                   "--use-compress-program", | ||||
|                   isOS64() ? "zstd -d --long=31" : "zstd -d --long=30" | ||||
|               ] | ||||
|             : ["-z"]), | ||||
|         "-xf", | ||||
|         archivePath.replace(new RegExp("\\" + path.sep, "g"), "/"), | ||||
| @ -65,10 +74,14 @@ export async function createTar( | ||||
|         sourceDirectories.join("\n") | ||||
|     ); | ||||
|     // -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores. | ||||
|     // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit. | ||||
|     const workingDirectory = getWorkingDirectory(); | ||||
|     const args = [ | ||||
|         ...(compressionMethod == CompressionMethod.Zstd | ||||
|             ? ["--use-compress-program", "zstd -T0"] | ||||
|             ? [ | ||||
|                   "--use-compress-program", | ||||
|                   isOS64() ? "zstd -T0 --long=31" : "zstd -T0 --long=30" | ||||
|               ] | ||||
|             : ["-z"]), | ||||
|         "-cf", | ||||
|         cacheFileName.replace(new RegExp("\\" + path.sep, "g"), "/"), | ||||
|  | ||||
| @ -124,7 +124,7 @@ export function unlinkFile(path: fs.PathLike): Promise<void> { | ||||
|     return util.promisify(fs.unlink)(path); | ||||
| } | ||||
|  | ||||
| async function checkVersion(app: string): Promise<string> { | ||||
| async function getVersion(app: string): Promise<string> { | ||||
|     core.debug(`Checking ${app} --version`); | ||||
|     let versionOutput = ""; | ||||
|     try { | ||||
| @ -148,7 +148,7 @@ async function checkVersion(app: string): Promise<string> { | ||||
| } | ||||
|  | ||||
| export async function getCompressionMethod(): Promise<CompressionMethod> { | ||||
|     const versionOutput = await checkVersion("zstd"); | ||||
|     const versionOutput = await getVersion("zstd"); | ||||
|     return versionOutput.toLowerCase().includes("zstd command line interface") | ||||
|         ? CompressionMethod.Zstd | ||||
|         : CompressionMethod.Gzip; | ||||
| @ -161,6 +161,6 @@ export function getCacheFileName(compressionMethod: CompressionMethod): string { | ||||
| } | ||||
|  | ||||
| export async function useGnuTar(): Promise<boolean> { | ||||
|     const versionOutput = await checkVersion("tar"); | ||||
|     const versionOutput = await getVersion("tar"); | ||||
|     return versionOutput.toLowerCase().includes("gnu tar"); | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Aiqiao Yan
					Aiqiao Yan