This commit is contained in:
Ivan Li
2021-07-20 22:30:00 +08:00
parent aec7f65434
commit c86772a5dd
4 changed files with 35 additions and 9 deletions

View File

@@ -27,6 +27,8 @@ import {
getSelfInstanceQueueKey,
getSelfInstanceRouteKey,
} from '../commons/utils/rabbit-mq';
import { unlink } from 'fs/promises';
import { rename } from 'fs/promises';
type Spawn = typeof spawn;
@@ -110,7 +112,7 @@ export class PipelineTaskRunner {
this.logger.info('running task [%s].', task.id);
try {
const workspaceRoot = await this.checkout(task);
let workspaceRoot = await this.checkout(task);
const units = task.units
.filter((unit) => unit !== PipelineUnits.checkout)
.map(
@@ -121,6 +123,22 @@ export class PipelineTaskRunner {
);
this.logger.info({ units }, 'begin run units.');
for (const unit of units) {
if (unit.type === PipelineUnits.deploy) {
const oldRoot = workspaceRoot;
workspaceRoot = this.reposService.getDeployRoot(task);
if (oldRoot !== workspaceRoot) {
await unlink(workspaceRoot).catch(() => void 0);
await rename(oldRoot, workspaceRoot);
}
await this.emitEvent(
task,
unit.type,
TaskStatuses.success,
`[deploy] change deploy folder content success`,
'stdout',
);
}
await this.doTaskUnit(unit.type, unit.scripts, task, workspaceRoot);
}
await this.emitEvent(

View File

@@ -56,6 +56,14 @@ export class ReposService {
);
}
getDeployRoot(task: PipelineTask) {
return join(
this.configService.get<string>('workspaces.root'),
encodeURIComponent(task.pipeline.project.name),
encodeURIComponent(`deploy-${task.pipeline.name}`),
);
}
async getGit(
project: Project,
workspaceRoot?: string,