Skip to content

Commit

Permalink
Fix 'No such file or directory' error
Browse files Browse the repository at this point in the history
This occurs when running the end-to-end tests locally.
  • Loading branch information
jacob-carlborg committed Nov 15, 2023
1 parent bacc347 commit 5272ec7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 97 deletions.
60 changes: 23 additions & 37 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: 0 additions & 4 deletions spec/operating_systems/freebsd/freebsd.spec.ts
Expand Up @@ -12,10 +12,6 @@ import * as xhyve from '../../../src/xhyve_vm'

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

get vmModule(): typeof xhyve | typeof qemu {
return qemu
}
Expand Down
8 changes: 0 additions & 8 deletions spec/operating_systems/netbsd/netbsd.spec.ts
Expand Up @@ -11,10 +11,6 @@ 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
}
Expand Down Expand Up @@ -92,10 +88,6 @@ describe('NetBSD OperatingSystem', () => {

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
}
Expand Down
31 changes: 15 additions & 16 deletions src/action/action.ts
Expand Up @@ -32,7 +32,6 @@ export class Action {
private readonly input = new input.Input()
private readonly resourceDisk: ResourceDisk
private readonly implementation: Implementation
private readonly workDirectory
private readonly sshDirectory: string
private readonly privateSshKey: fs.PathLike
private readonly publicSshKey: fs.PathLike
Expand All @@ -56,7 +55,6 @@ export class Action {
this.operatingSystem.actionImplementationKind
)

this.workDirectory = this.host.workDirectory
this.sshDirectory = path.join(this.getHomeDirectory(), '.ssh')
this.privateSshKey = path.join(this.tempPath, this.privateSshKeyName)
this.publicSshKey = `${this.privateSshKey}.pub`
Expand Down Expand Up @@ -98,7 +96,7 @@ export class Action {
hypervisorDirectory,
firmwareDirectory,
diskImagePath
].map(p => p.slice(this.workDirectory.length + 1))
].map(p => p.slice(this.homeDirectory.length + 1))

const vm = await vmPromise

Expand All @@ -107,7 +105,7 @@ export class Action {
await vm.run()
this.configSSH(vm.ipAddress)
await vm.wait(120)
await this.operatingSystem.setupWorkDirectory(vm, this.workDirectory)
await vm.setupWorkDirectory(this.homeDirectory, this.workDirectory)
await this.syncFiles(
vm,
this.targetDiskName,
Expand Down Expand Up @@ -235,16 +233,21 @@ export class Action {
return core.isDebug() ? 'v' : ''
}

private get homeDirectory(): string {
const components = this.workDirectory.split(path.sep).slice(0, -2)
return path.join('/', ...components)
}

private get workDirectory(): string {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return process.env['GITHUB_WORKSPACE']!
}

private async syncFiles(
vm: vmModule.Vm,
...excludePaths: string[]
): Promise<void> {
if (!this.shouldSyncFiles) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await vm.execute(`mkdir -p '${process.env['GITHUB_WORKSPACE']!}'`, {
log: false
})

return
}

Expand All @@ -254,7 +257,7 @@ export class Action {
`-auzrtopg${this.syncVerboseFlag}`,
'--exclude', '_actions/cross-platform-actions/action',
...flatMap(excludePaths, p => ['--exclude', p]),
`${this.workDirectory}/`,
`${this.homeDirectory}/`,
`runner@${vm.ipAddress}:work`
])
}
Expand All @@ -267,7 +270,7 @@ export class Action {
await exec.exec('rsync', [
`-uzrtopg${this.syncVerboseFlag}`,
`runner@${ipAddress}:work/`,
this.workDirectory
this.homeDirectory
])
}

Expand All @@ -279,11 +282,7 @@ export class Action {
? '$SHELL'
: shell.toString(this.input.shell)
await vm.execute2(
[
'sh',
'-c',
`'cd "${process.env['GITHUB_WORKSPACE']}" && exec "${sh}" -e'`
],
['sh', '-c', `'cd "${this.workDirectory}" && exec "${sh}" -e'`],
Buffer.from(this.input.run)
)
}
Expand Down
9 changes: 0 additions & 9 deletions src/host.ts
Expand Up @@ -18,7 +18,6 @@ export abstract class Host {
}
}

abstract get workDirectory(): string
abstract get vmModule(): typeof xhyve | typeof qemu
abstract get qemu(): HostQemu
abstract get hypervisor(): hypervisor.Hypervisor
Expand All @@ -37,10 +36,6 @@ export abstract class Host {
}

class MacOs extends Host {
get workDirectory(): string {
return '/Users/runner/work'
}

get vmModule(): typeof xhyve | typeof qemu {
return xhyve
}
Expand Down Expand Up @@ -78,10 +73,6 @@ class MacOs extends Host {
}

class Linux extends Host {
get workDirectory(): string {
return '/home/runner/work'
}

get vmModule(): typeof xhyve | typeof qemu {
return qemu
}
Expand Down
20 changes: 0 additions & 20 deletions src/operating_system.ts
Expand Up @@ -86,26 +86,6 @@ export abstract class OperatingSystem {
resourcesDirectory: fs.PathLike
): Promise<void>

async setupWorkDirectory(
vm: vmModule.Vm,
workDirectory: string
): Promise<void> {
const destination = `/home/${vmModule.Vm.user}/work`

await vm.execute('mkdir -p /home/runner/work')

if (workDirectory === destination)
await vm.execute(`rm -rf '${destination}' && mkdir -p '${workDirectory}'`)
else {
await vm.execute(
`rm -rf '${destination}' && ` +
`sudo mkdir -p '${workDirectory}' && ` +
`sudo chown '${vmModule.Vm.user}' '${workDirectory}' && ` +
`ln -sf '${workDirectory}/' '${destination}'`
)
}
}

protected get uuid(): string {
return '864ED7F0-7876-4AA7-8511-816FABCFA87F'
}
Expand Down
3 changes: 1 addition & 2 deletions src/qemu_vm.ts
Expand Up @@ -44,9 +44,8 @@ export abstract class Vm extends vm.Vm {
// '-nographic',

'-boot', 'strict=off',
/* eslint-disable @typescript-eslint/no-non-null-assertion */
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
'-bios', this.configuration.firmware!.toString()
/* eslint-enable @typescript-eslint/no-non-null-assertion */
].concat(this.hardDriverFlags)
}

Expand Down
14 changes: 14 additions & 0 deletions src/vm.ts
Expand Up @@ -118,6 +118,20 @@ export abstract class Vm {
)
}

async setupWorkDirectory(
homeDirectory: string,
workDirectory: string
): Promise<void> {
const homeDirectoryLinuxHost = `/home/${Vm.user}/work`

await this.execute(
`rm -rf '${homeDirectoryLinuxHost}' && ` +
`sudo mkdir -p '${workDirectory}' && ` +
`sudo chown -R '${Vm.user}' '${homeDirectory}' && ` +
`ln -sf '${homeDirectory}/' '${homeDirectoryLinuxHost}'`
)
}

protected async shutdown(): Promise<void> {
throw Error('Not implemented')
}
Expand Down

0 comments on commit 5272ec7

Please sign in to comment.