mirror of
				https://github.com/docker/setup-qemu-action.git
				synced 2025-11-01 01:40:10 +08:00 
			
		
		
		
	Merge b79376c2b4 into e0e4588fad
				
					
				
			This commit is contained in:
		
						commit
						5650dd2ebd
					
				
							
								
								
									
										36
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										36
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							| @ -65,3 +65,39 @@ jobs: | |||||||
|             echo "::error::Should have failed" |             echo "::error::Should have failed" | ||||||
|             exit 1 |             exit 1 | ||||||
|           fi |           fi | ||||||
|  | 
 | ||||||
|  |   version: | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: | ||||||
|  |           - ubuntu-latest | ||||||
|  |           - ubuntu-22.04 | ||||||
|  |           - ubuntu-20.04 | ||||||
|  |         install: | ||||||
|  |           - true | ||||||
|  |           - false | ||||||
|  |     steps: | ||||||
|  |       - | ||||||
|  |         name: Checkout | ||||||
|  |         uses: actions/checkout@v4 | ||||||
|  |       - | ||||||
|  |         name: Install QEMU | ||||||
|  |         if: ${{ matrix.install }} | ||||||
|  |         run: | | ||||||
|  |           sudo apt-get update | ||||||
|  |           sudo apt-get install -y qemu-user-static | ||||||
|  |       - | ||||||
|  |         name: QEMU bins | ||||||
|  |         run: | | ||||||
|  |           echo $PATH | tr ':' '\n' | xargs -I {} find {} -type f -executable -name "qemu*" || true | ||||||
|  |           dpkg -l | grep '^ii' | grep 'qemu' || true | ||||||
|  |       - | ||||||
|  |         name: Set up QEMU | ||||||
|  |         uses: ./ | ||||||
|  |       - | ||||||
|  |         name: QEMU bins | ||||||
|  |         run: | | ||||||
|  |           echo $PATH | tr ':' '\n' | xargs -I {} find {} -type f -executable -name "qemu*" || true | ||||||
|  |           dpkg -l | grep '^ii' | grep 'qemu' || true | ||||||
|  | |||||||
							
								
								
									
										24
									
								
								__tests__/qemu.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								__tests__/qemu.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | import {describe, expect, jest, it} from '@jest/globals'; | ||||||
|  | import * as io from '@actions/io'; | ||||||
|  | import {Exec} from '@docker/actions-toolkit/lib/exec'; | ||||||
|  | 
 | ||||||
|  | import * as qemu from '../src/qemu'; | ||||||
|  | 
 | ||||||
|  | describe('isInstalled', () => { | ||||||
|  |   it('bin', async () => { | ||||||
|  |     const ioWhichSpy = jest.spyOn(io, 'which'); | ||||||
|  |     await qemu.isInstalled(); | ||||||
|  |     expect(ioWhichSpy).toHaveBeenCalledTimes(1); | ||||||
|  |     expect(ioWhichSpy).toHaveBeenCalledWith(qemu.bin(), true); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | describe('printVersion', () => { | ||||||
|  |   it('call qemu --version', async () => { | ||||||
|  |     const execSpy = jest.spyOn(Exec, 'exec'); | ||||||
|  |     await qemu.printVersion().catch(() => { | ||||||
|  |       // noop
 | ||||||
|  |     }); | ||||||
|  |     expect(execSpy).toHaveBeenCalledWith(qemu.bin(), ['--version']); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										6
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								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
											
										
									
								
							| @ -26,6 +26,7 @@ | |||||||
|   "license": "Apache-2.0", |   "license": "Apache-2.0", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@actions/core": "^1.10.1", |     "@actions/core": "^1.10.1", | ||||||
|  |     "@actions/io": "^1.1.3", | ||||||
|     "@docker/actions-toolkit": "^0.16.1" |     "@docker/actions-toolkit": "^0.16.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| import * as context from './context'; | import * as context from './context'; | ||||||
|  | import * as qemu from './qemu'; | ||||||
| import * as core from '@actions/core'; | import * as core from '@actions/core'; | ||||||
| import * as actionsToolkit from '@docker/actions-toolkit'; | import * as actionsToolkit from '@docker/actions-toolkit'; | ||||||
| import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; | ||||||
| @ -14,6 +15,14 @@ actionsToolkit.run( | |||||||
|   async () => { |   async () => { | ||||||
|     const input: context.Inputs = context.getInputs(); |     const input: context.Inputs = context.getInputs(); | ||||||
| 
 | 
 | ||||||
|  |     await core.group('QEMU version', async () => { | ||||||
|  |       if (await qemu.isInstalled()) { | ||||||
|  |         await qemu.printVersion(); | ||||||
|  |       } else { | ||||||
|  |         core.warning('QEMU is not installed'); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     await core.group(`Docker info`, async () => { |     await core.group(`Docker info`, async () => { | ||||||
|       await Docker.printVersion(); |       await Docker.printVersion(); | ||||||
|       await Docker.printInfo(); |       await Docker.printInfo(); | ||||||
|  | |||||||
							
								
								
									
										39
									
								
								src/qemu.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/qemu.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | import os from 'os'; | ||||||
|  | import * as core from '@actions/core'; | ||||||
|  | import * as io from '@actions/io'; | ||||||
|  | import {Exec} from '@docker/actions-toolkit/lib/exec'; | ||||||
|  | 
 | ||||||
|  | export async function isInstalled(): Promise<boolean> { | ||||||
|  |   return await io | ||||||
|  |     .which(bin(), true) | ||||||
|  |     .then(res => { | ||||||
|  |       core.debug(`qemu.isInstalled ok: ${res}`); | ||||||
|  |       return true; | ||||||
|  |     }) | ||||||
|  |     .catch(error => { | ||||||
|  |       core.debug(`qemu.isInstalled error: ${error}`); | ||||||
|  |       return false; | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export async function printVersion(): Promise<void> { | ||||||
|  |   await Exec.exec(bin(), ['--version']); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export function bin(): string { | ||||||
|  |   return `qemu-system-${arch()}`; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function arch(): string { | ||||||
|  |   switch (os.arch()) { | ||||||
|  |     case 'x64': { | ||||||
|  |       return 'x86_64'; | ||||||
|  |     } | ||||||
|  |     case 'arm64': { | ||||||
|  |       return 'aarch64'; | ||||||
|  |     } | ||||||
|  |     default: { | ||||||
|  |       return os.arch(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 CrazyMax
						CrazyMax