Skip to content

Commit

Permalink
fixup! Fix #26: Add support for running the action multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Dec 9, 2023
1 parent e303af1 commit ee222e6
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 40 deletions.
48 changes: 33 additions & 15 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.

21 changes: 11 additions & 10 deletions src/action/action.ts
Expand Up @@ -289,6 +289,8 @@ export class Action {
}): SshConfigurator {
if (isRunning) return new NoopSshConfiguration(this)

core.debug(`Using SSH configuration: ${SshConfigurationKind[kind]}`)

switch (kind) {
case SshConfigurationKind.qemu:
return new QemuSshConfiguration(this)
Expand Down Expand Up @@ -555,6 +557,14 @@ export abstract class SshConfigurator {
protected get customSendEnv(): string {
return this.action['customSendEnv']
}

protected setupHostname(ipAddress: string): void {
if (ipAddress === 'localhost') ipAddress = '127.0.0.1'

execSync(
`sudo bash -c 'printf "${ipAddress} ${this.cpaHost}\n" >> /etc/hosts'`
)
}
}

class NoopSshConfiguration extends SshConfigurator {
Expand All @@ -565,9 +575,8 @@ class NoopSshConfiguration extends SshConfigurator {
}

class XhyveSshConfiguration extends SshConfigurator {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
override config(_ipAddress: string): void {
// noop
//this.setupHostname(ipAddress)
}
}

Expand Down Expand Up @@ -602,12 +611,4 @@ class QemuSshConfiguration extends SshConfigurator {
const publicKeyContent = fs.readFileSync(this.publicSshKey)
fs.appendFileSync(authorizedKeysPath, publicKeyContent)
}

private setupHostname(ipAddress: string): void {
if (ipAddress === 'localhost') ipAddress = '127.0.0.1'

execSync(
`sudo bash -c 'printf "${ipAddress} ${this.cpaHost}\n" >> /etc/hosts'`
)
}
}
6 changes: 2 additions & 4 deletions src/action/input.ts
Expand Up @@ -79,9 +79,8 @@ export class Input {
return (this.architecture_ = architecture.Kind.x86_64)

const kind = architecture.toKind(input)
core.debug(`kind: '${kind}'`)

if (kind === undefined) throw Error(`Invalid architecture: ${input}`)
core.debug(`architecture kind: '${architecture.Kind[kind]}'`)

return (this.architecture_ = kind)
}
Expand Down Expand Up @@ -122,9 +121,8 @@ export class Input {
return (this.hypervisor_ = this.host.hypervisor)

const kind = hypervisor.toKind(input)
core.debug(`kind: '${kind}'`)

if (kind === undefined) throw Error(`Invalid hypervisor: ${input}`)
core.debug(`hypervisor kind: '${hypervisor.Kind[kind]}'`)

const hypervisorClass = hypervisor.toHypervisor(kind)
return (this.hypervisor_ = new hypervisorClass())
Expand Down
14 changes: 13 additions & 1 deletion src/architecture.ts
Expand Up @@ -58,8 +58,12 @@ export abstract class Architecture {
return 'virtio-net'
}

get resolveName(): string {
return this.constructor.name
}

resolve<T>(implementation: Record<string, T>): T {
const name = this.constructor.name.toLocaleLowerCase()
const name = this.resolveName.toLocaleLowerCase()
return getOrDefaultOrThrow(implementation, name)
}

Expand All @@ -80,6 +84,10 @@ export abstract class Architecture {
return 'arm64'
}

override get resolveName(): string {
return 'arm64'
}

override get resourceUrl(): string {
return `${this.resourceBaseUrl}/qemu-system-aarch64-${this.hostString}.tar`
}
Expand Down Expand Up @@ -123,6 +131,10 @@ export abstract class Architecture {
return 'x86-64'
}

override get resolveName(): string {
return 'x86_64'
}

override get resourceUrl(): string {
return `${this.resourceBaseUrl}/qemu-system-x86_64-${this.hostString}.tar`
}
Expand Down
24 changes: 18 additions & 6 deletions src/operating_systems/freebsd/freebsd.ts
Expand Up @@ -13,6 +13,7 @@ import {LinuxDiskFileCreator, LinuxDiskDeviceCreator} from '../../resource_disk'
import versions from '../../version'
import {XhyveVm} from './xhyve_vm'
import {Input} from '../../action/input'
import {host} from '../../host'

@operatingSystem
export default class FreeBsd extends os.OperatingSystem {
Expand All @@ -29,12 +30,23 @@ export default class FreeBsd extends os.OperatingSystem {
}

get actionImplementationKind(): action.SshConfigurationKind {
if (this.architecture.kind === architecture.Kind.x86_64) {
return this.architecture.resolve({
x86_64: action.SshConfigurationKind.xhyve,
default: action.SshConfigurationKind.qemu
})
} else return action.SshConfigurationKind.qemu
const defaultKind = action.SshConfigurationKind.qemu

const archResult = this.architecture.resolve({
x86_64: action.SshConfigurationKind.xhyve,
default: defaultKind
})

const result = host.hypervisor.resolve({
xhyve: archResult,
default: defaultKind
})

core.debug(
`actionImplementationKind result: ${action.SshConfigurationKind[result]}`
)

return result
}

override async prepareDisk(
Expand Down
20 changes: 17 additions & 3 deletions src/operating_systems/openbsd/openbsd.ts
Expand Up @@ -29,9 +29,23 @@ export default class OpenBsd extends os.OperatingSystem {
}

get actionImplementationKind(): action.SshConfigurationKind {
if (this.architecture.kind === architecture.Kind.x86_64)
return action.SshConfigurationKind.xhyve
else return action.SshConfigurationKind.qemu
const defaultKind = action.SshConfigurationKind.qemu

const archResult = this.architecture.resolve({
x86_64: action.SshConfigurationKind.xhyve,
default: defaultKind
})

const result = host.hypervisor.resolve({
xhyve: archResult,
default: defaultKind
})

core.debug(
`actionImplementationKind result: ${action.SshConfigurationKind[result]}`
)

return result
}

override async prepareDisk(
Expand Down

0 comments on commit ee222e6

Please sign in to comment.