display QEMU version installed on the runner
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>pull/116/head
parent
5306bad0ba
commit
3bf7a4ebec
@ -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']);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -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