@jin7942/ray
Version:
Lightweight CI/CD deployment tool powered by Docker and Git
35 lines (34 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.gitCloneRepo = gitCloneRepo;
const child_process_1 = require("child_process");
const util_1 = require("util");
const logger_1 = require("../utils/logger");
const fsHelper_1 = require("../utils/fsHelper"); // exists도 필요함
const execAsync = (0, util_1.promisify)(child_process_1.exec);
/**
* Clones the Git repository into the workspace directory.
* If a branch is specified, it will check out that branch.
*
* @param ctx - Pipeline execution context
*/
async function gitCloneRepo(ctx) {
const { repo, branch, workspace } = ctx;
logger_1.logger.info(`Cloning ${repo} into ${workspace}`);
// 기존 workspace가 존재하면 삭제
if (await (0, fsHelper_1.exists)(workspace)) {
logger_1.logger.info(`Removing existing workspace: ${workspace}`);
await (0, fsHelper_1.removeDirectory)(workspace);
}
await (0, fsHelper_1.ensureDirectoryExists)(workspace);
// Clone with or without branch
const branchArg = branch ? `-b ${branch}` : '';
const cmd = `git clone ${branchArg} ${repo} ${workspace}`;
try {
await execAsync(cmd);
logger_1.logger.info('Repository cloned successfully.');
}
catch (e) {
throw new Error(`Git clone failed: ${e instanceof Error ? e.message : String(e)}`);
}
}