mirror of
				https://github.com/actions/cache.git
				synced 2025-10-31 20:08:36 +08:00 
			
		
		
		
	Use zstd instead of gzip
This commit is contained in:
		
							parent
							
								
									eb78578266
								
							
						
					
					
						commit
						7c7ab7c49e
					
				|  | @ -2,7 +2,7 @@ import * as core from "@actions/core"; | ||||||
| import * as path from "path"; | import * as path from "path"; | ||||||
| 
 | 
 | ||||||
| import * as cacheHttpClient from "../src/cacheHttpClient"; | import * as cacheHttpClient from "../src/cacheHttpClient"; | ||||||
| import { Events, Inputs } from "../src/constants"; | import { CacheFilename, Events, Inputs } from "../src/constants"; | ||||||
| import { ArtifactCacheEntry } from "../src/contracts"; | import { ArtifactCacheEntry } from "../src/contracts"; | ||||||
| import run from "../src/restore"; | import run from "../src/restore"; | ||||||
| import * as tar from "../src/tar"; | import * as tar from "../src/tar"; | ||||||
|  | @ -227,7 +227,7 @@ test("restore with cache found", async () => { | ||||||
|         return Promise.resolve(tempPath); |         return Promise.resolve(tempPath); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const archivePath = path.join(tempPath, "cache.tgz"); |     const archivePath = path.join(tempPath, CacheFilename); | ||||||
|     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); |     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); | ||||||
|     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); |     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); | ||||||
| 
 | 
 | ||||||
|  | @ -297,7 +297,7 @@ test("restore with a pull request event and cache found", async () => { | ||||||
|         return Promise.resolve(tempPath); |         return Promise.resolve(tempPath); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const archivePath = path.join(tempPath, "cache.tgz"); |     const archivePath = path.join(tempPath, CacheFilename); | ||||||
|     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); |     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); | ||||||
|     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); |     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); | ||||||
| 
 | 
 | ||||||
|  | @ -364,7 +364,7 @@ test("restore with cache found for restore key", async () => { | ||||||
|         return Promise.resolve(tempPath); |         return Promise.resolve(tempPath); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const archivePath = path.join(tempPath, "cache.tgz"); |     const archivePath = path.join(tempPath, CacheFilename); | ||||||
|     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); |     const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); | ||||||
|     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); |     const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -45,7 +45,15 @@ test("extract tar", async () => { | ||||||
|     expect(execMock).toHaveBeenCalledTimes(1); |     expect(execMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(execMock).toHaveBeenCalledWith( |     expect(execMock).toHaveBeenCalledWith( | ||||||
|         `"${tarPath}"`, |         `"${tarPath}"`, | ||||||
|         ["-xz", "-f", archivePath, "-P", "-C", workspace], |         [ | ||||||
|  |             "--use-compress-program", | ||||||
|  |             "zstd --long=31 -d", | ||||||
|  |             "-xf", | ||||||
|  |             archivePath, | ||||||
|  |             "-P", | ||||||
|  |             "-C", | ||||||
|  |             workspace | ||||||
|  |         ], | ||||||
|         { cwd: undefined } |         { cwd: undefined } | ||||||
|     ); |     ); | ||||||
| }); | }); | ||||||
|  | @ -70,8 +78,9 @@ test("create tar", async () => { | ||||||
|     expect(execMock).toHaveBeenCalledWith( |     expect(execMock).toHaveBeenCalledWith( | ||||||
|         `"${tarPath}"`, |         `"${tarPath}"`, | ||||||
|         [ |         [ | ||||||
|             "-cz", |             "--use-compress-program", | ||||||
|             "-f", |             "zstd -T0 --long=31", | ||||||
|  |             "-cf", | ||||||
|             CacheFilename, |             CacheFilename, | ||||||
|             "-C", |             "-C", | ||||||
|             workspace, |             workspace, | ||||||
|  |  | ||||||
|  | @ -19,4 +19,4 @@ export enum Events { | ||||||
|     PullRequest = "pull_request" |     PullRequest = "pull_request" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const CacheFilename = "cache.tgz"; | export const CacheFilename = "cache.tar.zst"; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import * as core from "@actions/core"; | ||||||
| import * as path from "path"; | import * as path from "path"; | ||||||
| 
 | 
 | ||||||
| import * as cacheHttpClient from "./cacheHttpClient"; | import * as cacheHttpClient from "./cacheHttpClient"; | ||||||
| import { Events, Inputs, State } from "./constants"; | import { CacheFilename, Events, Inputs, State } from "./constants"; | ||||||
| import { extractTar } from "./tar"; | import { extractTar } from "./tar"; | ||||||
| import * as utils from "./utils/actionUtils"; | import * as utils from "./utils/actionUtils"; | ||||||
| 
 | 
 | ||||||
|  | @ -63,7 +63,7 @@ async function run(): Promise<void> { | ||||||
| 
 | 
 | ||||||
|             const archivePath = path.join( |             const archivePath = path.join( | ||||||
|                 await utils.createTempDirectory(), |                 await utils.createTempDirectory(), | ||||||
|                 "cache.tgz" |                 CacheFilename | ||||||
|             ); |             ); | ||||||
|             core.debug(`Archive Path: ${archivePath}`); |             core.debug(`Archive Path: ${archivePath}`); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								src/tar.ts
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/tar.ts
									
									
									
									
									
								
							|  | @ -39,7 +39,15 @@ export async function extractTar(archivePath: string): Promise<void> { | ||||||
|     // Create directory to extract tar into
 |     // Create directory to extract tar into
 | ||||||
|     const workingDirectory = getWorkingDirectory(); |     const workingDirectory = getWorkingDirectory(); | ||||||
|     await io.mkdirP(workingDirectory); |     await io.mkdirP(workingDirectory); | ||||||
|     const args = ["-xz", "-f", archivePath, "-P", "-C", workingDirectory]; |     const args = [ | ||||||
|  |         "--use-compress-program", | ||||||
|  |         "zstd --long=31 -d", | ||||||
|  |         "-xf", | ||||||
|  |         archivePath, | ||||||
|  |         "-P", | ||||||
|  |         "-C", | ||||||
|  |         workingDirectory | ||||||
|  |     ]; | ||||||
|     await execTar(args); |     await execTar(args); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -56,8 +64,9 @@ export async function createTar( | ||||||
| 
 | 
 | ||||||
|     const workingDirectory = getWorkingDirectory(); |     const workingDirectory = getWorkingDirectory(); | ||||||
|     const args = [ |     const args = [ | ||||||
|         "-cz", |         "--use-compress-program", | ||||||
|         "-f", |         "zstd -T0 --long=31", | ||||||
|  |         "-cf", | ||||||
|         CacheFilename, |         CacheFilename, | ||||||
|         "-C", |         "-C", | ||||||
|         workingDirectory, |         workingDirectory, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 BSKY
						BSKY