Skip to content

Commit

Permalink
fix: conflict action checkout #443 (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Sep 12, 2023
1 parent 981c3b1 commit b4d212a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { env } from '../env';
import { DoguLogger } from '../logger/logger';
import { MessageContext } from '../message/message.types';
import { optionsConfig } from '../options-config.instance';
import { StepMessageContext } from '../step/step.types';
import { CommandProcessRegistry } from './command.process-registry';

interface PackageJson {
Expand Down Expand Up @@ -37,13 +38,16 @@ export class ActionProcessor {

async action(action: Action, context: MessageContext): Promise<ErrorResult> {
const { info, environmentVariableReplacer } = context;
const { deviceWorkspacePath } = info;
const { actionId, inputs } = action;
this.logger.verbose('action started', { action });
const pathMap = await this.deviceClientService.deviceHostClient.getPathMap();
const yarnPath = pathMap.common.yarn;
const gitPath = pathMap.common.git;
const { error, actionGitPath } = await this.prepare(context, deviceWorkspacePath, actionId, gitPath, yarnPath);

const workspacePath = await this.resolveWorkspacePath(context);
this.logger.verbose('action workspace path', { workspacePath });

const { error, actionGitPath } = await this.prepare(context, workspacePath, actionId, gitPath, yarnPath);
if (error) {
return error;
} else if (!actionGitPath) {
Expand All @@ -57,17 +61,30 @@ export class ActionProcessor {
return this.parseConfigAndRun(context, actionGitPath, env, yarnPath);
}

private async prepare(context: MessageContext, deviceWorkspacePath: string, actionId: string, gitPath: string, yarnPath: string): Promise<PrepareResult> {
private async resolveWorkspacePath(context: MessageContext): Promise<string> {
if (context instanceof StepMessageContext) {
const { deviceRunnerId } = context;
const deviceRunnerWorkspacePath = HostPaths.deviceRunnerWorkspacePath(HostPaths.doguHomePath, deviceRunnerId);
await fs.promises.mkdir(deviceRunnerWorkspacePath, { recursive: true });
return deviceRunnerWorkspacePath;
} else {
const { info } = context;
const { deviceWorkspacePath } = info;
return deviceWorkspacePath;
}
}

private async prepare(context: MessageContext, workspacePath: string, actionId: string, gitPath: string, yarnPath: string): Promise<PrepareResult> {
this.logger.verbose('action prepare', { actionId });
if (this.useSource()) {
const actionSourcePath = await this.findSource(actionId);
if (actionSourcePath) {
return { actionGitPath: actionSourcePath };
} else {
return this.fetchGitAndUpdateYarn(context, deviceWorkspacePath, actionId, gitPath, yarnPath);
return this.fetchGitAndUpdateYarn(context, workspacePath, actionId, gitPath, yarnPath);
}
} else {
return this.fetchGitAndUpdateYarn(context, deviceWorkspacePath, actionId, gitPath, yarnPath);
return this.fetchGitAndUpdateYarn(context, workspacePath, actionId, gitPath, yarnPath);
}
}

Expand All @@ -94,8 +111,8 @@ export class ActionProcessor {
return null;
}

private async fetchGit(context: MessageContext, deviceWorkspacePath: string, actionId: string, gitPath: string): Promise<PrepareResult> {
const actionGitPath = HostPaths.deviceActionGitPath(deviceWorkspacePath, actionId);
private async fetchGit(context: MessageContext, workspacePath: string, actionId: string, gitPath: string): Promise<PrepareResult> {
const actionGitPath = HostPaths.deviceActionGitPath(workspacePath, actionId);
const dotGitPath = path.resolve(actionGitPath, '.git');
const stat = await fs.promises.stat(dotGitPath).catch(() => null);
const configArgs = ['-c', 'core.longpaths=true'];
Expand Down Expand Up @@ -185,8 +202,8 @@ export class ActionProcessor {
};
}

private async fetchGitAndUpdateYarn(context: MessageContext, deviceWorkspacePath: string, actionId: string, gitPath: string, yarnPath: string): Promise<PrepareResult> {
const { error, actionGitPath } = await this.fetchGit(context, deviceWorkspacePath, actionId, gitPath);
private async fetchGitAndUpdateYarn(context: MessageContext, workspacePath: string, actionId: string, gitPath: string, yarnPath: string): Promise<PrepareResult> {
const { error, actionGitPath } = await this.fetchGit(context, workspacePath, actionId, gitPath);
if (error) {
return { error };
} else if (!actionGitPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class DeviceJobStepProcessor {
},
},
stepWorkingPath,
deviceRunnerId,
);
const result = await router.route<RunStepValue, ErrorResult>(value, stepMessageContext).catch((error) => {
const errorified = errorify(error);
Expand Down
11 changes: 9 additions & 2 deletions packages/typescript-private/host-agent/src/step/step.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceId, OrganizationId, RoutineStepId } from '@dogu-private/types';
import { DeviceId, DeviceRunnerId, OrganizationId, RoutineStepId } from '@dogu-private/types';
import { StackEnvironmentVariableReplacer } from '@dogu-tech/node';
import { MessageRouter } from '../message/message.router';
import { MessageCanceler, MessageContext, MessageEventHandler } from '../message/message.types';
Expand All @@ -17,7 +17,14 @@ export interface StepRegistryInfo extends StepRegistryKeySource {
export type ResolveStep = Resolve<void>;

export class StepMessageContext extends MessageContext {
constructor(info: MessageInfo, router: MessageRouter, replacer: StackEnvironmentVariableReplacer, handler: MessageEventHandler, readonly workingPath: string) {
constructor(
info: MessageInfo,
router: MessageRouter,
replacer: StackEnvironmentVariableReplacer,
handler: MessageEventHandler,
readonly workingPath: string,
readonly deviceRunnerId: DeviceRunnerId,
) {
super(info, router, replacer, handler);
}
}
3 changes: 2 additions & 1 deletion packages/typescript/node/src/host-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const HostPaths = {
hostSharesPath: (hostWorkspacePath: string): string => path.resolve(hostWorkspacePath, 'shares'),
deviceWorkspacePath: (organizationWorkspacePath: string, deviceId: string): string => path.resolve(organizationWorkspacePath, 'devices', deviceId),
deviceActionWorkspacePath: (deviceWorkspacePath: string): string => path.resolve(deviceWorkspacePath, 'actions'),
deviceActionGitPath: (deviceWorkspacePath: string, actionId: string): string => path.resolve(deviceWorkspacePath, 'actions', actionId.replaceAll('@', '-').replaceAll(':', '-')),
deviceActionGitPath: (workspacePath: string, actionId: string): string => path.resolve(workspacePath, 'actions', actionId.replaceAll('@', '-').replaceAll(':', '-')),
actionSourcePath: (doguWorkspacePath: string, actionId: string): string => path.resolve(doguWorkspacePath, actionId),
idaRunspacesPath: (doguHomePath: string): string => path.resolve(doguHomePath, 'ida-runspaces'),
deviceRunnerWorkspacePath: (doguHomePath: string, deviceRunnerId: string): string => path.resolve(doguHomePath, 'device-runners', deviceRunnerId),

android: {
platformToolsPath: (androidHomePath: string): string => path.resolve(androidHomePath, 'platform-tools'),
Expand Down

0 comments on commit b4d212a

Please sign in to comment.