fix 本地 git 联动严格执行开关

This commit is contained in:
bwcx_jzy 2024-01-10 19:44:45 +08:00
parent 6918e38bb5
commit ba70eeee31
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
3 changed files with 27 additions and 8 deletions

View File

@ -5,6 +5,7 @@
### 🐞 解决BUG、优化功能
1. 【server】修复 编辑器无法加载样式
2. 【server】优化 本地 git 联动严格执行开关
------

View File

@ -446,6 +446,7 @@ public class BuildExecuteManage implements Runnable {
map.put("reduceProgressRatio", buildExtConfig.getLogReduceProgressRatio());
map.put("logWriter", logRecorder.getPrintWriter());
map.put("savePath", gitFile);
map.put("strictlyEnforce", buildExtraModule.strictlyEnforce());
// 模糊匹配 标签
String branchTagName = buildInfoModel.getBranchTagName();
String[] result;
@ -481,6 +482,12 @@ public class BuildExecuteManage implements Runnable {
result = (String[]) plugin.execute("pull", map);
}
msg = result[1];
// 判断是否执行失败
String errorMsg = ArrayUtil.get(result, 2);
if (errorMsg != null) {
logRecorder.systemError("拉取代码失败:{}", errorMsg);
return errorMsg;
}
// 判断hash 码和上次构建是否一致
if (checkRepositoryDiff != null && checkRepositoryDiff) {
if (StrUtil.equals(repositoryLastCommitId, result[0])) {

View File

@ -140,17 +140,17 @@ public class SystemGitProcess extends AbstractGitProcess {
public String[] pull() throws Exception {
String branchName = (String) parameter.get("branchName");
Assert.hasText(branchName, "没有 branch name");
return pull(parameter, branchName);
return pull(branchName);
}
@Override
public String[] pullByTag() throws Exception {
String tagName = (String) parameter.get("tagName");
Assert.hasText(tagName, "没有 tag name");
return pull(parameter, tagName);
return pull(tagName);
}
private String[] pull(Map<String, Object> map, String branchOrTag) throws IOException {
private String[] pull(String branchOrTag) throws IOException {
PrintWriter printWriter = (PrintWriter) parameter.get("logWriter");
boolean needClone = this.needClone();
if (needClone) {
@ -158,25 +158,36 @@ public class SystemGitProcess extends AbstractGitProcess {
this.reClone(printWriter, branchOrTag);
}
File saveFile = getSaveFile();
{
Boolean strictlyEnforce = (Boolean) parameter.get("strictlyEnforce");
strictlyEnforce = strictlyEnforce != null && strictlyEnforce;
// 更新
/*CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "pull");*/
CommandUtil.exec(saveFile, null, line -> {
int code = CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "fetch", "--all");
CommandUtil.exec(saveFile, null, line -> {
if (code != 0 && strictlyEnforce) {
return new String[]{null, null, "git fetch失败状态码:" + code};
}
code = CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "reset", "--hard", branchOrTag);
CommandUtil.exec(saveFile, null, line -> {
}, "git", "reset", "--hard", "origin/" + branchOrTag);
if (code != 0 && strictlyEnforce) {
return new String[]{null, null, "git reset --hard失败状态码:" + code};
}
code = CommandUtil.exec(saveFile, null, line -> {
printWriter.println(line);
printWriter.flush();
}, "git", "submodule", "update", "--init", "--remote", "-f", "--recursive");
if (code != 0 && strictlyEnforce) {
return new String[]{null, null, "git submodule update 失败状态码:" + code};
}
}
// 获取提交日志
String[] command = {"git", "log", "-1", branchOrTag};