!195 新增git submodules支持

Merge pull request !195 from Croce/dev
This commit is contained in:
蒋小小 2023-08-29 07:52:27 +00:00 committed by Gitee
commit 1a2f032cf6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 41 additions and 19 deletions

View File

@ -136,6 +136,7 @@ public class ReleaseManage {
this.init();
this.resultFile = buildExtraModule.resultDirFile(this.buildNumberId);
this.buildEnv.put("BUILD_RESULT_FILE", FileUtil.getAbsolutePath(this.resultFile));
this.buildEnv.put("BUILD_RESULT_DIR_FILE", buildExtraModule.getResultDirFile());
//
this.updateStatus(BuildStatus.PubIng, "开始发布中");
if (FileUtil.isEmpty(this.resultFile)) {
@ -144,7 +145,7 @@ public class ReleaseManage {
return info;
}
long resultFileSize = FileUtil.size(this.resultFile);
logRecorder.system("开始执行发布,需要发布的文件大小:{}", FileUtil.readableFileSize(resultFileSize));
logRecorder.system("开始执行发布需要发布的文件大小:{}", FileUtil.readableFileSize(resultFileSize));
Optional.ofNullable(consumer).ifPresent(consumer1 -> consumer1.accept(resultFileSize));
// 先同步到文件管理中心
Boolean syncFileStorage = this.buildExtraModule.getSyncFileStorage();
@ -157,9 +158,9 @@ public class ReleaseManage {
// 默认的别名码为构建id
StrUtil.emptyToDefault(buildInfoModel.getAliasCode(), buildInfoModel.getId()));
if (successMd5 != null) {
logRecorder.system("构建产物文件成功同步到文件管理中心,{}", successMd5);
logRecorder.system("构建产物文件成功同步到文件管理中心{}", successMd5);
} else {
logRecorder.systemWarning("构建产物文件同步到文件管理中心失败,当前文件已经存文件管理中心存在啦");
logRecorder.systemWarning("构建产物文件同步到文件管理中心失败当前文件已经存文件管理中心存在啦");
}
}
//
@ -180,7 +181,7 @@ public class ReleaseManage {
} else if (releaseMethod == BuildReleaseMethod.No.getCode()) {
return null;
} else {
String format = StrUtil.format("没有实现的发布分发:{}", releaseMethod);
String format = StrUtil.format("没有实现的发布分发{}", releaseMethod);
logRecorder.systemError(format);
return format;
}
@ -275,7 +276,7 @@ public class ReleaseManage {
if (pushToRepository != null && pushToRepository) {
List<String> repositoryList = StrUtil.splitTrim(dockerTag, StrUtil.COMMA);
for (String repositoryItem : repositoryList) {
logRecorder.system("start push to repository in({}),{} {}", map.get("name"), StrUtil.emptyToDefault((String) map.get("registryUrl"), StrUtil.EMPTY), repositoryItem);
logRecorder.system("start push to repository in({}),{} {}{}", map.get("name"), StrUtil.emptyToDefault((String) map.get("registryUrl"), StrUtil.EMPTY), repositoryItem, System.lineSeparator());
//
map.put("repository", repositoryItem);
Consumer<String> logConsumer = s -> logRecorder.info(s);
@ -316,7 +317,7 @@ public class ReleaseManage {
}
private void doDockerImage(DockerInfoModel dockerInfoModel, Map<String, String> envMap, File dockerfile, File baseDir, String dockerTag, BuildExtraModule extraModule) {
logRecorder.system("{} start build image {}", dockerInfoModel.getName(), dockerTag);
logRecorder.system("{} start build image {}{}", dockerInfoModel.getName(), dockerTag, System.lineSeparator());
Map<String, Object> map = machineDockerServer.dockerParameter(dockerInfoModel);
//.toParameter();
map.put("Dockerfile", dockerfile);
@ -348,7 +349,7 @@ public class ReleaseManage {
logRecorder.systemError("没有需要执行的命令");
return null;
}
logRecorder.system("{} start exec", DateUtil.now());
logRecorder.system("{} start exec{}", DateUtil.now(), System.lineSeparator());
File sourceFile = BuildUtil.getSourceById(this.buildExtraModule.getId());
Map<String, String> envFileMap = buildEnv.environment();
@ -409,7 +410,7 @@ public class ReleaseManage {
if (StrUtil.isEmpty(releasePath)) {
logRecorder.systemWarning("发布目录为空");
} else {
logRecorder.system("{} {} start ftp upload", DateUtil.now(), item.getName());
logRecorder.system("{} {} start ftp upload{}", DateUtil.now(), item.getName(), System.lineSeparator());
MySftp.ProgressMonitor sftpProgressMonitor = sshService.createProgressMonitor(logRecorder);
MySftp sftp = new MySftp(session, charset, timeout, sftpProgressMonitor);
channelSftp = sftp.getClient();
@ -482,9 +483,9 @@ public class ReleaseManage {
int delSize = CollUtil.size(del);
int diffSize = CollUtil.size(diff);
if (clearOld) {
logRecorder.system("对比文件结果,产物文件 {} 个、需要上传 {} 个、需要删除 {} 个", CollUtil.size(collect), CollUtil.size(diff), delSize);
logRecorder.system("对比文件结果产物文件 {} 个、需要上传 {} 个、需要删除 {} 个", CollUtil.size(collect), CollUtil.size(diff), delSize);
} else {
logRecorder.system("对比文件结果,产物文件 {} 个、需要上传 {} 个", CollUtil.size(collect), CollUtil.size(diff));
logRecorder.system("对比文件结果产物文件 {} 个、需要上传 {} 个", CollUtil.size(collect), CollUtil.size(diff));
}
// 清空发布才先执行删除
if (delSize > 0 && clearOld) {
@ -510,7 +511,7 @@ public class ReleaseManage {
int progressRange = (int) Math.floor(progressPercentage / buildExtConfig.getLogReduceProgressRatio());
if (progressRangeList.add(progressRange)) {
// total, progressSize
logRecorder.system("上传文件进度:{}[{}/{}] {}/{} {} ", file.getName(),
logRecorder.system("上传文件进度{}[{}/{}] {}/{} {} ", file.getName(),
(finalI + 1), diffSize,
FileUtil.readableFileSize(progressSize), FileUtil.readableFileSize(total),
NumberUtil.formatPercent(((float) progressSize / total), 0)
@ -558,7 +559,7 @@ public class ReleaseManage {
double progressPercentage = Math.floor(((float) progressSize / total) * 100);
int progressRange = (int) Math.floor(progressPercentage / buildExtConfig.getLogReduceProgressRatio());
if (progressRangeList.add(progressRange)) {
logRecorder.system("上传文件进度:{} {}/{} {}", name,
logRecorder.system("上传文件进度{} {}/{} {}", name,
FileUtil.readableFileSize(progressSize), FileUtil.readableFileSize(total),
NumberUtil.formatPercent(((float) progressSize / total), 0));
}
@ -593,7 +594,7 @@ public class ReleaseManage {
return outGivingRunBuilder.build().startRun(selectProject);
});
//OutGivingRun.startRun(releaseMethodDataId, zipFile, userModel, unZip, 0);
logRecorder.system("开始执行分发包啦,请到分发中查看详情状态");
logRecorder.system("开始执行分发包啦请到分发中查看详情状态");
OutGivingModel.Status status = statusFuture.get();
logRecorder.system("分发结果:{}", status.getDesc());
}
@ -607,7 +608,7 @@ public class ReleaseManage {
try {
BaseServerController.resetInfo(userModel);
this.init();
logRecorder.system("开始回滚:{}", DateTime.now());
logRecorder.system("开始回滚{}", DateTime.now());
//
String errorMsg = this.start(null, item);
logRecorder.system("执行回滚结束:{}", StrUtil.emptyToDefault(errorMsg, "ok"));

View File

@ -44,6 +44,8 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.SubmoduleConfig.FetchRecurseSubmodulesMode;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.*;
@ -133,7 +135,7 @@ public class JGitUtil {
*/
private static Git reClone(Map<String, Object> parameter, String branchName, String tagName, File file, PrintWriter printWriter) throws GitAPIException, IOException {
println(printWriter, StrUtil.EMPTY);
println(printWriter, "Automatically re-clones repositories");
println(printWriter, "JGit: Automatically re-clones repositories");
if (!FileUtil.clean(file)) {
FileUtil.del(file.toPath());
}
@ -151,7 +153,8 @@ public class JGitUtil {
}
String url = (String) parameter.get("url");
CloneCommand command = cloneCommand.setURI(url)
.setDirectory(file);
.setDirectory(file)
.setCloneSubmodules(true);
// 设置凭证
setCredentials(command, parameter);
return command.call();
@ -377,7 +380,8 @@ public class JGitUtil {
SmallTextProgressMonitor progressMonitor = new SmallTextProgressMonitor(printWriter, progressRatio);
// 放弃本地修改
git.checkout().setName(branchName).setForced(true).setProgressMonitor(progressMonitor).call();
//
println(printWriter, "\ngit pull");
PullCommand pull = git.pull();
//
setCredentials(pull, parameter);
@ -385,6 +389,7 @@ public class JGitUtil {
PullResult call = pull
.setRemoteBranchName(branchName)
.setProgressMonitor(progressMonitor)
.setRecurseSubmodules(FetchRecurseSubmodulesMode.YES)
.call();
// 输出拉取结果
if (call != null) {
@ -405,6 +410,16 @@ public class JGitUtil {
// println(printWriter, "fetchResult {}", fetchResult);
// }
}
//
println(printWriter, "\ngit submodule update --init --remote --recursive");
SubmoduleUpdateCommand subUpdate = git.submoduleUpdate();
setCredentials(subUpdate, parameter);
Collection<String> rst = subUpdate
.setProgressMonitor(progressMonitor)
.setFetch(true)
.setStrategy(MergeStrategy.THEIRS)
.call();
println(printWriter, rst.stream().collect(Collectors.joining("\n")));
return call;
}

View File

@ -160,10 +160,16 @@ public class SystemGitProcess extends AbstractGitProcess {
File saveFile = getSaveFile();
{
// 更新
printWriter.println("git pull");
CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "pull");
printWriter.println("git submodule update --init --remote -f --recursive");
CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "submodule", "update", "--init", "--remote", "-f", "--recursive");
}
// 获取提交日志
String[] command = {"git", "log", "-1", branchOrTag};
@ -181,7 +187,7 @@ public class SystemGitProcess extends AbstractGitProcess {
}
private void reClone(PrintWriter printWriter, String branchOrTag) throws IOException {
printWriter.println("Automatically re-clones repositories");
printWriter.println("SystemGit: Automatically re-clones repositories");
// 先删除本地目录
File savePath = getSaveFile();
if (!FileUtil.clean(savePath)) {
@ -205,7 +211,7 @@ public class SystemGitProcess extends AbstractGitProcess {
return null;
}).ifPresent(integer -> env.put("GIT_HTTP_TIMEOUT", String.valueOf(integer)));
//
String[] command = new String[]{"git", "clone", depthStr, "-b", branchOrTag, this.getCovertUrl(), savePath.getAbsolutePath()};
String[] command = new String[]{"git", "clone", "--recursive", depthStr, "-b", branchOrTag, this.getCovertUrl(), savePath.getAbsolutePath()};
FileUtil.mkdir(savePath);
CommandUtil.exec(savePath, env, line -> {
printWriter.println(line);