Skip to content

Commit

Permalink
Try running NetBSD on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Feb 15, 2023
1 parent 24f8268 commit f3160be
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ jobs:
uname:
hardware: amd64

- name: NetBSD
version: '9.2'
host: macos-latest
workDirectory: /Users/runner/work/action/action
uname:
hardware: amd64

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Add support for NetBSD on macOS runners ([#28](https://github.com/cross-platform-actions/action/issues/28))
- Support for configuring memory ([#16](https://github.com/cross-platform-actions/action/issues/16))
- Support for configuring CPU core count ([#16](https://github.com/cross-platform-actions/action/issues/17))

Expand Down
11 changes: 9 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ This section lists the available inputs for the action.
| `memory` || `6G` or `13G` | string | The amount of memory for the virtual machine. The default value is `6G` for Linux runners and `13G` for macOS runners. |
| `cpu_count` || `2` or `3` cores | integer | The number of CPU cores for the virtual machine. The default value is `2` for Linux runners and `3` for macOS runners. |

All inputs are expected to be of the specified type. It's especially important
All inputs are expected to be of the specified type. It's especially important
that you specify `version` as a string, using single or
double quotes. Otherwise YAML might interpet the value as a numeric value
instead of a string, which leads to some unexpected behavior. If the
Expand Down Expand Up @@ -139,7 +139,7 @@ they can run.
| Runner | OpenBSD | FreeBSD | NetBSD |
| ----------------------------------------------| ------- | ------- | ------ |
| **Linux** ||||
| **macos-10.15**, **macos-11**, **macos-12** ||| |
| **macos-10.15**, **macos-11**, **macos-12** ||| |

## `Under the Hood`

Expand Down
149 changes: 149 additions & 0 deletions spec/operating_systems/netbsd/netbsd.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import NetBsd from '../../../src/operating_systems/netbsd/netbsd'
import * as hostModule from '../../../src/host'
import * as arch from '../../../src/architecture'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import HostQemu from '../../../src/host_qemu'
import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import * as netbsdQemuVm from '../../../src/operating_systems/netbsd/qemu_vm'

describe('NetBSD OperatingSystem', () => {
class Host extends hostModule.Host {
get workDirectory(): string {
return '/home/runner/work'
}

get vmModule(): typeof xhyve | typeof qemu {
return qemu
}

override get qemu(): HostQemu {
return new HostQemu.LinuxHostQemu()
}

override get hypervisor(): hypervisor.Hypervisor {
return new hypervisor.Qemu()
}

override get efiHypervisor(): hypervisor.Hypervisor {
return new hypervisor.QemuEfi()
}

override get defaultMemory(): string {
return '6G'
}

override get defaultCpuCount(): number {
return 6
}
}

let host = new Host()
let osKind = os.Kind.for('netbsd')
let architecture = arch.Architecture.for(arch.Kind.x86_64, host, osKind)
let netbsd = new NetBsd(architecture, '0.0.0')
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'

let config = {
memory: '4G',
cpuCount: 7,
diskImage: '',
resourcesDiskImage: '',
userboot: ''
}

describe('createVirtualMachine', () => {
it('creates a virtual machine with the correct configuration', () => {
let qemuVmSpy = spyOn(netbsdQemuVm, 'Vm')

netbsd.createVirtualMachine(
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
{
...config,
ssHostPort: 2847,
cpu: 'qemu64',
accelerator: Accelerator.tcg,
machineType: 'pc',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
}
)
})

describe('when on a macOS host', () => {
class Host extends hostModule.Host {
get workDirectory(): string {
return '/Users/runner/work'
}

get vmModule(): typeof xhyve | typeof qemu {
return xhyve
}

override get qemu(): HostQemu {
return new HostQemu.MacosHostQemu()
}

override get hypervisor(): hypervisor.Hypervisor {
return new hypervisor.Xhyve()
}

override get efiHypervisor(): hypervisor.Hypervisor {
return this.hypervisor
}

override get defaultMemory(): string {
return '13G'
}

override get defaultCpuCount(): number {
return 3
}
}

let host = new Host()
let osKind = os.Kind.for('netbsd')
let architecture = arch.Architecture.for(arch.Kind.x86_64, host, osKind)
let netbsd = new NetBsd(architecture, '0.0.0')

it('creates a virtual machine configured with BIOS firmware', () => {
let qemuVmSpy = spyOn(netbsdQemuVm, 'Vm')

netbsd.createVirtualMachine(
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
{
...config,
ssHostPort: 2847,
cpu: 'host',
accelerator: Accelerator.hvf,
machineType: 'pc',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
}
)
})
})
})
})
42 changes: 42 additions & 0 deletions spec/operating_systems/netbsd/qemu_vm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Vm} from '../../../src/operating_systems/netbsd/qemu_vm'
import * as arch from '../../../src/architecture'
import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/netbsd/netbsd'

describe('NetBSD QemuVm', () => {
let memory = '5G'
let cpuCount = 10

let osKind = os.Kind.for('netbsd')
let architecture = arch.Architecture.for(arch.Kind.x86_64, host, osKind)
let config = {
memory: memory,
cpuCount: cpuCount,
diskImage: '',
ssHostPort: 0,
cpu: '',
accelerator: Accelerator.tcg,
machineType: '',
uuid: '',
resourcesDiskImage: '',
userboot: '',
firmware: ''
}
let vm = new Vm('', '', architecture, config)

let getFlagValue = (flag: string) => vm.command[vm.command.indexOf(flag) + 1]
let actualMemory = () => getFlagValue('-m')
let actualSmp = () => getFlagValue('-smp')

describe('command', () => {
it('constucts a command with the correct memory configuration', () => {
expect(actualMemory()).toEqual(memory)
})

it('constucts a command with the correct SMP configuration', () => {
expect(actualSmp()).toEqual(cpuCount.toString())
})
})
})
5 changes: 4 additions & 1 deletion src/operating_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export abstract class OperatingSystem {
await vm.execute(`rm -rf '${destination}' && mkdir -p '${workDirectory}'`)
else {
await vm.execute(
`rm -rf '${destination}' && mkdir -p '${workDirectory}' && ln -sf '${workDirectory}/' '${destination}'`
`rm -rf '${destination}' && ` +
`sudo mkdir -p '${workDirectory}' && ` +
`sudo chown '${vmModule.Vm.user}' '${workDirectory}' && ` +
`ln -sf '${workDirectory}/' '${destination}'`
)
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/operating_systems/netbsd/netbsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as core from '@actions/core'
import * as architecture from '../../architecture'
import * as action from '../../action/action'
import {operatingSystem} from '../factory'
import * as hypervisor from '../../hypervisor'
import * as vmModule from '../../vm'
import * as os from '../../operating_system'
import versions from '../../version'
Expand Down Expand Up @@ -58,7 +59,7 @@ export default class NetBsd extends Qemu {
ssHostPort: this.ssHostPort,
firmware: path.join(
firmwareDirectory.toString(),
this.architecture.hypervisor.firmwareFile
this.hypervisor.firmwareFile
),

// qemu
Expand All @@ -77,4 +78,8 @@ export default class NetBsd extends Qemu {
config
)
}

private get hypervisor(): hypervisor.Hypervisor {
return new hypervisor.Qemu()
}
}

0 comments on commit f3160be

Please sign in to comment.