mirror of
				https://github.com/actions-rs/toolchain.git
				synced 2025-10-31 16:53:53 +00:00 
			
		
		
		
	Merge 6bbb331ffcc44b148bf62cd68a72bb0132181cdd into 88dc2356392166efad76775c878094f4e83ff746
This commit is contained in:
		
						commit
						b70a5cb9c1
					
				| @ -71,4 +71,17 @@ describe("actions-rs/toolchain", () => { | ||||
| 
 | ||||
|         expect(args.name).toBe("1.39.0"); | ||||
|     }); | ||||
| 
 | ||||
|     it("supports toml override file", function () { | ||||
|         const rustToolchainFile = tempWriteSync(` | ||||
|             [toolchain] | ||||
|             channel = "stable" | ||||
|         `);
 | ||||
| 
 | ||||
|         const args = morph(() => { | ||||
|             return getToolchainArgs(rustToolchainFile); | ||||
|         }, {}); | ||||
| 
 | ||||
|         expect(args.name).toBe("stable"); | ||||
|     }); | ||||
| }); | ||||
|  | ||||
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										10170
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10170
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -35,7 +35,8 @@ | ||||
|         "@actions-rs/core": "^0.1.6", | ||||
|         "@actions/core": "^1.2.6", | ||||
|         "@actions/exec": "^1.0.4", | ||||
|         "@actions/io": "^1.0.2" | ||||
|         "@actions/io": "^1.0.2", | ||||
|         "fast-toml": "^0.5.4" | ||||
|     }, | ||||
|     "devDependencies": { | ||||
|         "@types/jest": "^26.0.15", | ||||
|  | ||||
							
								
								
									
										24
									
								
								src/args.ts
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/args.ts
									
									
									
									
									
								
							| @ -1,6 +1,7 @@ | ||||
| import { input } from "@actions-rs/core"; | ||||
| import { debug } from "@actions/core"; | ||||
| import { existsSync, readFileSync } from "fs"; | ||||
| import { parse } from "fast-toml"; | ||||
| 
 | ||||
| export interface ToolchainOptions { | ||||
|     name: string; | ||||
| @ -19,20 +20,35 @@ function determineToolchain(overrideFile: string): string { | ||||
|         return toolchainInput; | ||||
|     } | ||||
| 
 | ||||
|     if (!existsSync(overrideFile)) { | ||||
|     const toolchainPath = existsSync(overrideFile) | ||||
|         ? overrideFile | ||||
|         : existsSync(`${overrideFile}.toml`) | ||||
|         ? `${overrideFile}.toml` | ||||
|         : undefined; | ||||
| 
 | ||||
|     if (!toolchainPath) { | ||||
|         throw new Error( | ||||
|             "toolchain input was not given and repository does not have a rust-toolchain file" | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     const rustToolchainFile = readFileSync(overrideFile, { | ||||
|     const rustToolchainFile = readFileSync(toolchainPath, { | ||||
|         encoding: "utf-8", | ||||
|         flag: "r", | ||||
|     }).trim(); | ||||
| 
 | ||||
|     debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`); | ||||
|     const toolchain = rustToolchainFile.includes("[toolchain]") | ||||
|         ? parse<{ toolchain?: { channel?: string } }>(rustToolchainFile) | ||||
|               ?.toolchain?.channel | ||||
|         : rustToolchainFile; | ||||
| 
 | ||||
|     return rustToolchainFile; | ||||
|     if (!toolchain) { | ||||
|         throw new Error(`channel is not specified in ${toolchainPath}`); | ||||
|     } | ||||
| 
 | ||||
|     debug(`using toolchain from rust-toolchain file: ${toolchain}`); | ||||
| 
 | ||||
|     return toolchain; | ||||
| } | ||||
| 
 | ||||
| export function getToolchainArgs(overrideFile: string): ToolchainOptions { | ||||
|  | ||||
							
								
								
									
										9
									
								
								types/fast-toml/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								types/fast-toml/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| declare module "fast-toml" { | ||||
|     export function parse<R extends Record<string, unknown>>(input: string): R; | ||||
|     export function parseFile<R extends Record<string, unknown>>( | ||||
|         file: string | ||||
|     ): Promise<R>; | ||||
|     export function parseFileSync<R extends Record<string, unknown>>( | ||||
|         file: string | ||||
|     ): R; | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user