mirror of
				https://github.com/actions-rs/cargo.git
				synced 2025-10-31 20:03:50 +00:00 
			
		
		
		
	Checking that cargo executable is installed and available (#2)
This commit is contained in:
		
							parent
							
								
									b08fe239f7
								
							
						
					
					
						commit
						0deeed314b
					
				
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										43
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -9,11 +9,30 @@ import * as input from './input'; | |||||||
| 
 | 
 | ||||||
| const CROSS_REV: string = '69b8da7da287055127812c9e4b071756c2b98545'; | const CROSS_REV: string = '69b8da7da287055127812c9e4b071756c2b98545'; | ||||||
| 
 | 
 | ||||||
| async function getCross(): Promise<string> { | // TODO: `core.info` function is not published yet as for `1.0.1` version,
 | ||||||
|  | // bundling it.
 | ||||||
|  | function core_info(message: string): void { | ||||||
|  |     process.stdout.write(message + os.EOL); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function getCargo(): Promise<string> { | ||||||
|  |     try { | ||||||
|  |         return await io.which('cargo', true); | ||||||
|  |     } catch (error) { | ||||||
|  |         core_info('cargo is not installed by default for some virtual environments, \ | ||||||
|  | see https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions');
 | ||||||
|  |         core_info('To install it, use this action: https://github.com/actions-rs/toolchain'); | ||||||
|  | 
 | ||||||
|  |         throw error; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function getCross(cargoPath: string): Promise<string> { | ||||||
|     try { |     try { | ||||||
|         return await io.which('cross', true); |         return await io.which('cross', true); | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|         core.debug('Unable to find cross, installing it now'); |         core.debug('Unable to find cross, installing it now'); | ||||||
|  |         throw error; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Somewhat new Rust is required to compile `cross`
 |     // Somewhat new Rust is required to compile `cross`
 | ||||||
| @ -29,11 +48,12 @@ async function getCross(): Promise<string> { | |||||||
| 
 | 
 | ||||||
|     const cwd = process.cwd(); |     const cwd = process.cwd(); | ||||||
|     process.chdir(os.tmpdir()); |     process.chdir(os.tmpdir()); | ||||||
|  | 
 | ||||||
|     try { |     try { | ||||||
|         core.startGroup('Install cross'); |         core.startGroup('Install cross'); | ||||||
|         core.warning('Git version of cross will be installed, \ |         core.warning('Git version of cross will be installed, \ | ||||||
| see https://github.com/actions-rs/cargo/issues/1');
 | see https://github.com/actions-rs/cargo/issues/1');
 | ||||||
|         await exec.exec('cargo', [ |         await exec.exec(cargoPath, [ | ||||||
|             'install', |             'install', | ||||||
|             '--rev', |             '--rev', | ||||||
|             CROSS_REV, |             CROSS_REV, | ||||||
| @ -41,8 +61,7 @@ see https://github.com/actions-rs/cargo/issues/1'); | |||||||
|             'https://github.com/rust-embedded/cross.git' |             'https://github.com/rust-embedded/cross.git' | ||||||
|         ]); |         ]); | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|         core.setFailed(error.message); |         throw error; | ||||||
|         throw new Error(error); |  | ||||||
|     } finally { |     } finally { | ||||||
|         // It is important to chdir back!
 |         // It is important to chdir back!
 | ||||||
|         process.chdir(cwd); |         process.chdir(cwd); | ||||||
| @ -53,14 +72,15 @@ see https://github.com/actions-rs/cargo/issues/1'); | |||||||
|     return 'cross'; |     return 'cross'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function run() { | async function run(): Promise<void> { | ||||||
|     const actionInput = input.parse(); |     const actionInput = input.parse(); | ||||||
|  |     const cargo = await getCargo(); | ||||||
| 
 | 
 | ||||||
|     let program; |     let program; | ||||||
|     if (actionInput.useCross) { |     if (actionInput.useCross) { | ||||||
|         program = await getCross(); |         program = await getCross(cargo); | ||||||
|     } else { |     } else { | ||||||
|         program = 'cargo'; |         program = cargo; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let args: string[] = []; |     let args: string[] = []; | ||||||
| @ -70,12 +90,15 @@ async function run() { | |||||||
|     args.push(actionInput.command); |     args.push(actionInput.command); | ||||||
|     args = args.concat(actionInput.args); |     args = args.concat(actionInput.args); | ||||||
| 
 | 
 | ||||||
|  |     await exec.exec(program, args); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function main(): Promise<void> { | ||||||
|     try { |     try { | ||||||
|         await exec.exec(program, args); |         await run(); | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|         core.setFailed(error.message); |         core.setFailed(error.message); | ||||||
|         throw error; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| run(); | main(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user