mirror of
				https://github.com/Swatinem/rust-cache.git
				synced 2025-10-31 16:13:49 +00:00 
			
		
		
		
	Allow opting out of caching $CARGO_HOME/bin. (#216)
Prevents wiping the bin directory, which is harmful for self-hosted runners.
This commit is contained in:
		
							parent
							
								
									9a2e0d3212
								
							
						
					
					
						commit
						e8e63cdbf2
					
				| @ -79,6 +79,10 @@ sensible defaults. | |||||||
|     # Can be set to either "github" or "buildjet" |     # Can be set to either "github" or "buildjet" | ||||||
|     # default: "github" |     # default: "github" | ||||||
|     cache-provider: "" |     cache-provider: "" | ||||||
|  | 
 | ||||||
|  |     # Determines whether to cache the ~/.cargo/bin directory. | ||||||
|  |     # default: "true" | ||||||
|  |     cache-bin: "" | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Further examples are available in the [.github/workflows](./.github/workflows/) directory. | Further examples are available in the [.github/workflows](./.github/workflows/) directory. | ||||||
| @ -175,4 +179,7 @@ to see those details as well as further details related to caching operations. | |||||||
| ## Known issues | ## Known issues | ||||||
| 
 | 
 | ||||||
| - The cache cleaning process currently removes all the files from `~/.cargo/bin` | - The cache cleaning process currently removes all the files from `~/.cargo/bin` | ||||||
|   that were present before the action ran (for example `rustc`). |   that were present before the action ran (for example `rustc`), by default. | ||||||
|  |   This can be an issue on long-running self-hosted runners, where such state | ||||||
|  |   is expected to be preserved across runs.  You can work around this by setting | ||||||
|  |   `cache-bin: "false"`. | ||||||
|  | |||||||
| @ -40,6 +40,10 @@ inputs: | |||||||
|     description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github." |     description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github." | ||||||
|     required: false |     required: false | ||||||
|     default: "github" |     default: "github" | ||||||
|  |   cache-bin: | ||||||
|  |     description: "Determines whether to cache ${CARGO_HOME}/bin." | ||||||
|  |     required: false | ||||||
|  |     default: "true" | ||||||
|   lookup-only: |   lookup-only: | ||||||
|     description: "Check if a cache entry exists without downloading the cache" |     description: "Check if a cache entry exists without downloading the cache" | ||||||
|     required: false |     required: false | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							| @ -77276,6 +77276,8 @@ class CacheConfig { | |||||||
|         this.cacheKey = ""; |         this.cacheKey = ""; | ||||||
|         /** The secondary (restore) key that only contains the prefix and environment */ |         /** The secondary (restore) key that only contains the prefix and environment */ | ||||||
|         this.restoreKey = ""; |         this.restoreKey = ""; | ||||||
|  |         /** Whether to cache CARGO_HOME/.bin */ | ||||||
|  |         this.cacheBin = true; | ||||||
|         /** The workspace configurations */ |         /** The workspace configurations */ | ||||||
|         this.workspaces = []; |         this.workspaces = []; | ||||||
|         /** The cargo binaries present during main step */ |         /** The cargo binaries present during main step */ | ||||||
| @ -77351,6 +77353,7 @@ class CacheConfig { | |||||||
|         // Construct the lockfiles portion of the key:
 |         // Construct the lockfiles portion of the key:
 | ||||||
|         // This considers all the files found via globbing for various manifests
 |         // This considers all the files found via globbing for various manifests
 | ||||||
|         // and lockfiles.
 |         // and lockfiles.
 | ||||||
|  |         self.cacheBin = lib_core.getInput("cache-bin").toLowerCase() == "true"; | ||||||
|         // Constructs the workspace config and paths to restore:
 |         // Constructs the workspace config and paths to restore:
 | ||||||
|         // The workspaces are given using a `$workspace -> $target` syntax.
 |         // The workspaces are given using a `$workspace -> $target` syntax.
 | ||||||
|         const workspaces = []; |         const workspaces = []; | ||||||
| @ -77445,7 +77448,13 @@ class CacheConfig { | |||||||
|         self.keyFiles = sort_and_uniq(keyFiles); |         self.keyFiles = sort_and_uniq(keyFiles); | ||||||
|         key += `-${lockHash}`; |         key += `-${lockHash}`; | ||||||
|         self.cacheKey = key; |         self.cacheKey = key; | ||||||
|         self.cachePaths = [config_CARGO_HOME]; |         self.cachePaths = [ | ||||||
|  |             external_path_default().join(config_CARGO_HOME, "registry"), | ||||||
|  |             external_path_default().join(config_CARGO_HOME, "git"), | ||||||
|  |         ]; | ||||||
|  |         if (self.cacheBin) { | ||||||
|  |             self.cachePaths = [external_path_default().join(config_CARGO_HOME, "bin"), ...self.cachePaths]; | ||||||
|  |         } | ||||||
|         const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true"; |         const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true"; | ||||||
|         if (cacheTargets === "true") { |         if (cacheTargets === "true") { | ||||||
|             self.cachePaths.push(...workspaces.map((ws) => ws.target)); |             self.cachePaths.push(...workspaces.map((ws) => ws.target)); | ||||||
|  | |||||||
							
								
								
									
										25
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							| @ -77276,6 +77276,8 @@ class CacheConfig { | |||||||
|         this.cacheKey = ""; |         this.cacheKey = ""; | ||||||
|         /** The secondary (restore) key that only contains the prefix and environment */ |         /** The secondary (restore) key that only contains the prefix and environment */ | ||||||
|         this.restoreKey = ""; |         this.restoreKey = ""; | ||||||
|  |         /** Whether to cache CARGO_HOME/.bin */ | ||||||
|  |         this.cacheBin = true; | ||||||
|         /** The workspace configurations */ |         /** The workspace configurations */ | ||||||
|         this.workspaces = []; |         this.workspaces = []; | ||||||
|         /** The cargo binaries present during main step */ |         /** The cargo binaries present during main step */ | ||||||
| @ -77351,6 +77353,7 @@ class CacheConfig { | |||||||
|         // Construct the lockfiles portion of the key:
 |         // Construct the lockfiles portion of the key:
 | ||||||
|         // This considers all the files found via globbing for various manifests
 |         // This considers all the files found via globbing for various manifests
 | ||||||
|         // and lockfiles.
 |         // and lockfiles.
 | ||||||
|  |         self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true"; | ||||||
|         // Constructs the workspace config and paths to restore:
 |         // Constructs the workspace config and paths to restore:
 | ||||||
|         // The workspaces are given using a `$workspace -> $target` syntax.
 |         // The workspaces are given using a `$workspace -> $target` syntax.
 | ||||||
|         const workspaces = []; |         const workspaces = []; | ||||||
| @ -77445,7 +77448,13 @@ class CacheConfig { | |||||||
|         self.keyFiles = sort_and_uniq(keyFiles); |         self.keyFiles = sort_and_uniq(keyFiles); | ||||||
|         key += `-${lockHash}`; |         key += `-${lockHash}`; | ||||||
|         self.cacheKey = key; |         self.cacheKey = key; | ||||||
|         self.cachePaths = [CARGO_HOME]; |         self.cachePaths = [ | ||||||
|  |             external_path_default().join(CARGO_HOME, "registry"), | ||||||
|  |             external_path_default().join(CARGO_HOME, "git"), | ||||||
|  |         ]; | ||||||
|  |         if (self.cacheBin) { | ||||||
|  |             self.cachePaths = [external_path_default().join(CARGO_HOME, "bin"), ...self.cachePaths]; | ||||||
|  |         } | ||||||
|         const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; |         const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; | ||||||
|         if (cacheTargets === "true") { |         if (cacheTargets === "true") { | ||||||
|             self.cachePaths.push(...workspaces.map((ws) => ws.target)); |             self.cachePaths.push(...workspaces.map((ws) => ws.target)); | ||||||
| @ -77907,12 +77916,14 @@ async function run() { | |||||||
|         catch (e) { |         catch (e) { | ||||||
|             core.debug(`${e.stack}`); |             core.debug(`${e.stack}`); | ||||||
|         } |         } | ||||||
|         try { |         if (config.cacheBin) { | ||||||
|             core.info(`... Cleaning cargo/bin ...`); |             try { | ||||||
|             await cleanBin(config.cargoBins); |                 core.info(`... Cleaning cargo/bin ...`); | ||||||
|         } |                 await cleanBin(config.cargoBins); | ||||||
|         catch (e) { |             } | ||||||
|             core.debug(`${e.stack}`); |             catch (e) { | ||||||
|  |                 core.debug(`${e.stack}`); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         try { |         try { | ||||||
|             core.info(`... Cleaning cargo git cache ...`); |             core.info(`... Cleaning cargo git cache ...`); | ||||||
|  | |||||||
| @ -25,6 +25,9 @@ export class CacheConfig { | |||||||
|   /** The secondary (restore) key that only contains the prefix and environment */ |   /** The secondary (restore) key that only contains the prefix and environment */ | ||||||
|   public restoreKey = ""; |   public restoreKey = ""; | ||||||
| 
 | 
 | ||||||
|  |   /** Whether to cache CARGO_HOME/.bin */ | ||||||
|  |   public cacheBin: boolean = true; | ||||||
|  | 
 | ||||||
|   /** The workspace configurations */ |   /** The workspace configurations */ | ||||||
|   public workspaces: Array<Workspace> = []; |   public workspaces: Array<Workspace> = []; | ||||||
| 
 | 
 | ||||||
| @ -120,6 +123,8 @@ export class CacheConfig { | |||||||
|     // This considers all the files found via globbing for various manifests
 |     // This considers all the files found via globbing for various manifests
 | ||||||
|     // and lockfiles.
 |     // and lockfiles.
 | ||||||
| 
 | 
 | ||||||
|  |     self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true"; | ||||||
|  | 
 | ||||||
|     // Constructs the workspace config and paths to restore:
 |     // Constructs the workspace config and paths to restore:
 | ||||||
|     // The workspaces are given using a `$workspace -> $target` syntax.
 |     // The workspaces are given using a `$workspace -> $target` syntax.
 | ||||||
| 
 | 
 | ||||||
| @ -238,7 +243,13 @@ export class CacheConfig { | |||||||
|     key += `-${lockHash}`; |     key += `-${lockHash}`; | ||||||
|     self.cacheKey = key; |     self.cacheKey = key; | ||||||
| 
 | 
 | ||||||
|     self.cachePaths = [CARGO_HOME]; |     self.cachePaths = [ | ||||||
|  |       path.join(CARGO_HOME, "registry"), | ||||||
|  |       path.join(CARGO_HOME, "git"), | ||||||
|  |     ]; | ||||||
|  |     if (self.cacheBin) { | ||||||
|  |       self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths]; | ||||||
|  |     } | ||||||
|     const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; |     const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; | ||||||
|     if (cacheTargets === "true") { |     if (cacheTargets === "true") { | ||||||
|       self.cachePaths.push(...workspaces.map((ws) => ws.target)); |       self.cachePaths.push(...workspaces.map((ws) => ws.target)); | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								src/save.ts
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/save.ts
									
									
									
									
									
								
							| @ -56,11 +56,13 @@ async function run() { | |||||||
|       core.debug(`${(e as any).stack}`); |       core.debug(`${(e as any).stack}`); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     try { |     if (config.cacheBin) { | ||||||
|       core.info(`... Cleaning cargo/bin ...`); |       try { | ||||||
|       await cleanBin(config.cargoBins); |         core.info(`... Cleaning cargo/bin ...`); | ||||||
|     } catch (e) { |         await cleanBin(config.cargoBins); | ||||||
|       core.debug(`${(e as any).stack}`); |       } catch (e) { | ||||||
|  |         core.debug(`${(e as any).stack}`); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user