mirror of
				https://github.com/docker/setup-qemu-action.git
				synced 2025-10-31 01:00:11 +08:00 
			
		
		
		
	Use context for inputs
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									8c1e35a8c6
								
							
						
					
					
						commit
						25725d8d2e
					
				| @ -13,6 +13,7 @@ ___ | ||||
| * [Usage](#usage) | ||||
| * [Customizing](#customizing) | ||||
|   * [inputs](#inputs) | ||||
|   * [outputs](#outputs) | ||||
| * [Contributing](#contributing) | ||||
| 
 | ||||
| ## Usage | ||||
|  | ||||
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										19
									
								
								src/context.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/context.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import {issueCommand} from '@actions/core/lib/command'; | ||||
| 
 | ||||
| export interface Inputs { | ||||
|   image: string; | ||||
|   platforms: string; | ||||
| } | ||||
| 
 | ||||
| export function getInputs(): Inputs { | ||||
|   return { | ||||
|     image: core.getInput('image') || 'tonistiigi/binfmt:latest', | ||||
|     platforms: core.getInput('platforms') || 'all' | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| // FIXME: Temp fix https://github.com/actions/toolkit/issues/777
 | ||||
| export function setOutput(name: string, value: unknown): void { | ||||
|   issueCommand('set-output', {name}, value); | ||||
| } | ||||
							
								
								
									
										48
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| import * as context from './context'; | ||||
| import * as core from '@actions/core'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import {issueCommand} from '@actions/core/lib/command'; | ||||
| 
 | ||||
| interface Platforms { | ||||
|   supported: string[]; | ||||
| @ -9,29 +9,32 @@ interface Platforms { | ||||
| 
 | ||||
| async function run(): Promise<void> { | ||||
|   try { | ||||
|     core.startGroup(`Docker info`); | ||||
|     await exec.exec('docker', ['version']); | ||||
|     await exec.exec('docker', ['info']); | ||||
|     core.endGroup(); | ||||
|     const input: context.Inputs = context.getInputs(); | ||||
| 
 | ||||
|     const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest'; | ||||
|     const platforms: string = core.getInput('platforms') || 'all'; | ||||
|     await core.group(`Docker info`, async () => { | ||||
|       await exec.exec('docker', ['version'], { | ||||
|         failOnStdErr: false | ||||
|       }); | ||||
|       await exec.exec('docker', ['info'], { | ||||
|         failOnStdErr: false | ||||
|       }); | ||||
|     }); | ||||
| 
 | ||||
|     core.startGroup(`Pulling binfmt Docker image`); | ||||
|     await exec.exec('docker', ['pull', image]); | ||||
|     core.endGroup(); | ||||
|     await core.group(`Pulling binfmt Docker image`, async () => { | ||||
|       await exec.exec('docker', ['pull', input.image]); | ||||
|     }); | ||||
| 
 | ||||
|     core.startGroup(`Image info`); | ||||
|     await exec.exec('docker', ['image', 'inspect', image]); | ||||
|     core.endGroup(); | ||||
|     await core.group(`Image info`, async () => { | ||||
|       await exec.exec('docker', ['image', 'inspect', input.image]); | ||||
|     }); | ||||
| 
 | ||||
|     core.startGroup(`Installing QEMU static binaries`); | ||||
|     await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]); | ||||
|     core.endGroup(); | ||||
|     await core.group(`Installing QEMU static binaries`, async () => { | ||||
|       await exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]); | ||||
|     }); | ||||
| 
 | ||||
|     core.startGroup(`Extracting available platforms`); | ||||
|     await core.group(`Extracting available platforms`, async () => { | ||||
|       await exec | ||||
|       .getExecOutput('docker', ['run', '--rm', '--privileged', image], { | ||||
|         .getExecOutput('docker', ['run', '--rm', '--privileged', input.image], { | ||||
|           ignoreReturnCode: true, | ||||
|           silent: true | ||||
|         }) | ||||
| @ -41,17 +44,12 @@ async function run(): Promise<void> { | ||||
|           } | ||||
|           const platforms: Platforms = JSON.parse(res.stdout.trim()); | ||||
|           core.info(`${platforms.supported.join(',')}`); | ||||
|         setOutput('platforms', platforms.supported.join(',')); | ||||
|           context.setOutput('platforms', platforms.supported.join(',')); | ||||
|         }); | ||||
|     }); | ||||
|     core.endGroup(); | ||||
|   } catch (error) { | ||||
|     core.setFailed(error.message); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // FIXME: Temp fix https://github.com/actions/toolkit/issues/777
 | ||||
| function setOutput(name: string, value: unknown): void { | ||||
|   issueCommand('set-output', {name}, value); | ||||
| } | ||||
| 
 | ||||
| run(); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 CrazyMax
						CrazyMax