-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display QEMU version installed on the runner
Signed-off-by: CrazyMax <[email protected]>
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |