Skip to content

Commit fba9ebd

Browse files
committed
display QEMU version installed on the runner
Signed-off-by: CrazyMax <[email protected]>
1 parent 5306bad commit fba9ebd

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

.github/workflows/ci.yml

+34
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,37 @@ jobs:
6565
echo "::error::Should have failed"
6666
exit 1
6767
fi
68+
69+
version:
70+
runs-on: ${{ matrix.os }}
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
os:
75+
- ubuntu-latest
76+
- ubuntu-22.04
77+
- ubuntu-20.04
78+
install:
79+
- true
80+
- false
81+
steps:
82+
-
83+
name: Checkout
84+
uses: actions/checkout@v4
85+
-
86+
name: Install QEMU
87+
if: ${{ matrix.install }}
88+
run: |
89+
sudo apt-get update
90+
sudo apt-get install -y qemu-user-static
91+
-
92+
name: QEMU bins
93+
run: |
94+
echo $PATH | tr ':' '\n' | xargs -I {} find {} -type f -executable -name "qemu*" || true
95+
-
96+
name: Set up QEMU
97+
uses: ./
98+
-
99+
name: QEMU bins
100+
run: |
101+
echo $PATH | tr ':' '\n' | xargs -I {} find {} -type f -executable -name "qemu*" || true

__tests__/qemu.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {describe, expect, jest, it} from '@jest/globals';
2+
import * as io from '@actions/io';
3+
import {Exec} from '@docker/actions-toolkit/lib/exec';
4+
5+
import * as qemu from '../src/qemu';
6+
7+
describe('isInstalled', () => {
8+
it('bin', async () => {
9+
const ioWhichSpy = jest.spyOn(io, 'which');
10+
await qemu.isInstalled();
11+
expect(ioWhichSpy).toHaveBeenCalledTimes(1);
12+
expect(ioWhichSpy).toHaveBeenCalledWith(qemu.bin(), true);
13+
});
14+
});
15+
16+
describe('printVersion', () => {
17+
it('call qemu --version', async () => {
18+
const execSpy = jest.spyOn(Exec, 'exec');
19+
await qemu.printVersion().catch(() => {
20+
// noop
21+
});
22+
expect(execSpy).toHaveBeenCalledWith(qemu.bin(), ['--version']);
23+
});
24+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"license": "Apache-2.0",
2727
"dependencies": {
2828
"@actions/core": "^1.10.1",
29+
"@actions/io": "^1.1.3",
2930
"@docker/actions-toolkit": "^0.16.1"
3031
},
3132
"devDependencies": {

src/main.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as context from './context';
2+
import * as qemu from './qemu';
23
import * as core from '@actions/core';
34
import * as actionsToolkit from '@docker/actions-toolkit';
45
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
@@ -14,6 +15,14 @@ actionsToolkit.run(
1415
async () => {
1516
const input: context.Inputs = context.getInputs();
1617

18+
await core.group('QEMU version', async () => {
19+
if (await qemu.isInstalled()) {
20+
await qemu.printVersion();
21+
} else {
22+
core.warning('QEMU is not installed');
23+
}
24+
});
25+
1726
await core.group(`Docker info`, async () => {
1827
await Docker.printVersion();
1928
await Docker.printInfo();

src/qemu.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os from 'os';
2+
import * as core from '@actions/core';
3+
import * as io from '@actions/io';
4+
import {Exec} from '@docker/actions-toolkit/lib/exec';
5+
6+
export async function isInstalled(): Promise<boolean> {
7+
return await io
8+
.which(bin(), true)
9+
.then(res => {
10+
core.debug(`qemu.isInstalled ok: ${res}`);
11+
return true;
12+
})
13+
.catch(error => {
14+
core.debug(`qemu.isInstalled error: ${error}`);
15+
return false;
16+
});
17+
}
18+
19+
export async function printVersion(): Promise<void> {
20+
await Exec.exec(bin(), ['--version']);
21+
}
22+
23+
export function bin(): string {
24+
return `qemu-system-${arch()}`;
25+
}
26+
27+
function arch(): string {
28+
switch (os.arch()) {
29+
case 'x64': {
30+
return 'x86_64';
31+
}
32+
case 'arm64': {
33+
return 'aarch64';
34+
}
35+
default: {
36+
return os.arch();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)