mirror of
				https://github.com/actions-rs/toolchain.git
				synced 2025-10-31 16:53:53 +00:00 
			
		
		
		
	Add support for reading toml files
This commit is contained in:
		
							parent
							
								
									5613870e6d
								
							
						
					
					
						commit
						cebe54f42a
					
				
							
								
								
									
										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", | ||||
|  | ||||
							
								
								
									
										18
									
								
								src/args.ts
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								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,10 +20,10 @@ function determineToolchain(overrideFile: string): string { | ||||
|         return toolchainInput; | ||||
|     } | ||||
| 
 | ||||
|     const toolchainPath = existsSync(overrideFile)  | ||||
|         ? overrideFile  | ||||
|         : existsSync(`${overrideFile}.toml`)  | ||||
|         ? `${overrideFile}.toml`  | ||||
|     const toolchainPath = existsSync(overrideFile) | ||||
|         ? overrideFile | ||||
|         : existsSync(`${overrideFile}.toml`) | ||||
|         ? `${overrideFile}.toml` | ||||
|         : undefined; | ||||
| 
 | ||||
|     if (!toolchainPath) { | ||||
| @ -36,6 +37,15 @@ function determineToolchain(overrideFile: string): string { | ||||
|         flag: "r", | ||||
|     }).trim(); | ||||
| 
 | ||||
|     const toolchain = rustToolchainFile.includes("[toolchain]") | ||||
|         ? parse<{ toolchain?: { channel?: string } }>(rustToolchainFile) | ||||
|               ?.toolchain?.channel | ||||
|         : rustToolchainFile; | ||||
| 
 | ||||
|     if (!toolchain) { | ||||
|         throw new Error(`channel is not specified in ${toolchainPath}`); | ||||
|     } | ||||
| 
 | ||||
|     debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`); | ||||
| 
 | ||||
|     return rustToolchainFile; | ||||
|  | ||||
							
								
								
									
										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