@infly/libs 2.7.0 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/adapters/webpack/auto-export.js +53 -53
- package/build/build-dist/index.js +18 -23
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/webhook.js +135 -135
- package/build/docker/deployment/release.sh +20 -1
- package/build/docker/release-paths.js +30 -30
- package/build/project-files.js +47 -47
- package/core/async/concurrency.js +29 -29
- package/package.json +4 -4
- package/script/git-automation/check-packages.js +40 -40
- package/script/git-automation/git-clone.js +69 -69
- package/script/git-automation/git-configure.js +29 -29
- package/script/git-automation/git-submodule.js +18 -18
- package/script/git-automation/git-utils.js +59 -59
- package/script/git-automation/index.js +136 -87
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { execFileSync } = require("child_process");
|
|
4
|
-
|
|
5
|
-
function gitOutput(args, cwd = process.cwd()) {
|
|
6
|
-
return execFileSync("git", args, {
|
|
7
|
-
cwd,
|
|
8
|
-
encoding: "utf8",
|
|
9
|
-
shell: process.platform === "win32"
|
|
10
|
-
}).trim();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function findGitRepo(cwd) {
|
|
14
|
-
let currentDir = path.resolve(cwd || process.cwd());
|
|
15
|
-
|
|
16
|
-
while (true) {
|
|
17
|
-
const gitPath = path.join(currentDir, ".git");
|
|
18
|
-
|
|
19
|
-
if (fs.existsSync(gitPath)) {
|
|
20
|
-
const stat = fs.statSync(gitPath);
|
|
21
|
-
const repo = {
|
|
22
|
-
root: currentDir,
|
|
23
|
-
commonDir: gitPath
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (stat.isFile()) {
|
|
27
|
-
const content = fs.readFileSync(gitPath, "utf8");
|
|
28
|
-
const match = content.match(/gitdir:\s*(.+)/i);
|
|
29
|
-
|
|
30
|
-
if (match) {
|
|
31
|
-
repo.commonDir = path.resolve(currentDir, match[1].trim());
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return repo;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const parentDir = path.dirname(currentDir);
|
|
39
|
-
|
|
40
|
-
if (parentDir === currentDir) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
currentDir = parentDir;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
function gitOutput(args, cwd = process.cwd()) {
|
|
6
|
+
return execFileSync("git", args, {
|
|
7
|
+
cwd,
|
|
8
|
+
encoding: "utf8",
|
|
9
|
+
shell: process.platform === "win32"
|
|
10
|
+
}).trim();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function findGitRepo(cwd) {
|
|
14
|
+
let currentDir = path.resolve(cwd || process.cwd());
|
|
15
|
+
|
|
16
|
+
while (true) {
|
|
17
|
+
const gitPath = path.join(currentDir, ".git");
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(gitPath)) {
|
|
20
|
+
const stat = fs.statSync(gitPath);
|
|
21
|
+
const repo = {
|
|
22
|
+
root: currentDir,
|
|
23
|
+
commonDir: gitPath
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (stat.isFile()) {
|
|
27
|
+
const content = fs.readFileSync(gitPath, "utf8");
|
|
28
|
+
const match = content.match(/gitdir:\s*(.+)/i);
|
|
29
|
+
|
|
30
|
+
if (match) {
|
|
31
|
+
repo.commonDir = path.resolve(currentDir, match[1].trim());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return repo;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const parentDir = path.dirname(currentDir);
|
|
39
|
+
|
|
40
|
+
if (parentDir === currentDir) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
currentDir = parentDir;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
48
|
function getGitCommonDir(cwd) {
|
|
49
|
-
const repo = findGitRepo(cwd);
|
|
50
|
-
|
|
51
|
-
if (repo) {
|
|
52
|
-
return repo.commonDir;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
const commonDir = gitOutput(["-C", cwd, "rev-parse", "--git-common-dir"]);
|
|
57
|
-
return path.resolve(cwd, commonDir);
|
|
58
|
-
} catch {
|
|
59
|
-
return path.resolve(cwd || process.cwd());
|
|
60
|
-
}
|
|
49
|
+
const repo = findGitRepo(cwd);
|
|
50
|
+
|
|
51
|
+
if (repo) {
|
|
52
|
+
return repo.commonDir;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const commonDir = gitOutput(["-C", cwd, "rev-parse", "--git-common-dir"]);
|
|
57
|
+
return path.resolve(cwd, commonDir);
|
|
58
|
+
} catch {
|
|
59
|
+
return path.resolve(cwd || process.cwd());
|
|
60
|
+
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function resolveGitWorktreeRoot(cwd) {
|
|
@@ -2,7 +2,8 @@ const { formatTerminalMessage, logTerminal } = require("../../cli/terminal-style
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const crypto = require("crypto");
|
|
5
|
-
const
|
|
5
|
+
const childProcess = require("child_process");
|
|
6
|
+
const { execSync, exec } = childProcess;
|
|
6
7
|
const { promisify } = require("util");
|
|
7
8
|
const { getGitCommonDir } = require("./git-utils");
|
|
8
9
|
const execAsync = promisify(exec);
|
|
@@ -19,30 +20,37 @@ function getCurrentBranch() {
|
|
|
19
20
|
* 获取 Git 提交信息
|
|
20
21
|
* @returns {Object} 包含提交信息的对象,如果获取失败则返回空对象
|
|
21
22
|
*/
|
|
22
|
-
function getLatestCommitInfo(cwd = process.cwd()) {
|
|
23
|
+
function getLatestCommitInfo(cwd = process.cwd(), sourceCommit = "HEAD") {
|
|
24
|
+
let fullHash;
|
|
25
|
+
try {
|
|
26
|
+
fullHash = readGit(cwd, ["rev-parse", "--verify", "--end-of-options", sourceCommit + "^{commit}"]).trim();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logTerminal("error", "无法读取构建源码提交:" + error.message);
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
// 定义 Git 命令
|
|
24
33
|
const commands = {
|
|
25
34
|
// 构建元数据必须全部对应源码 HEAD。跳过 merge commit 会导致 fullHash 指向
|
|
26
35
|
// 当前合并提交,而文案、作者却回退到更早的版本构建提交。
|
|
27
|
-
commitMsg: "
|
|
28
|
-
branch: "
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
date: "git log -1 --pretty=%cd --date=iso"
|
|
36
|
+
commitMsg: ["log", "-1", "--pretty=%B", fullHash],
|
|
37
|
+
branch: ["rev-parse", "--abbrev-ref", "HEAD"],
|
|
38
|
+
author: ["log", "-1", "--pretty=%an", fullHash],
|
|
39
|
+
email: ["log", "-1", "--pretty=%ae", fullHash],
|
|
40
|
+
date: ["log", "-1", "--pretty=%cd", "--date=iso", fullHash]
|
|
33
41
|
};
|
|
34
42
|
|
|
35
43
|
// 结果对象
|
|
36
|
-
const commitInfo = {};
|
|
44
|
+
const commitInfo = { fullHash };
|
|
37
45
|
|
|
38
46
|
try {
|
|
39
47
|
// 检查当前目录是否是 Git 仓库
|
|
40
|
-
|
|
48
|
+
readGit(cwd, ["rev-parse", "--is-inside-work-tree"]);
|
|
41
49
|
|
|
42
50
|
// 遍历命令并执行
|
|
43
51
|
for (const [key, command] of Object.entries(commands)) {
|
|
44
52
|
try {
|
|
45
|
-
commitInfo[key] =
|
|
53
|
+
commitInfo[key] = readGit(cwd, command).trim();
|
|
46
54
|
} catch (cmdError) {
|
|
47
55
|
logTerminal("warning", `获取 Git 信息失败(${key}):${cmdError.message}`);
|
|
48
56
|
commitInfo[key] = ""; // 失败时设置为空字符串
|
|
@@ -67,9 +75,20 @@ function createCommitTextMatcher(template = "") {
|
|
|
67
75
|
return new RegExp(`^${escapedParts.join(".+?")}$`);
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
const SOURCE_COMMIT_TRAILER = "Infly-Source-Commit";
|
|
79
|
+
const COMMIT_HASH = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
80
|
+
const DEFAULT_BUILD_SUBJECT = /^build: 更新版本为v\S+ --build by @infly\/libs$/;
|
|
81
|
+
const NO_SOURCE_CHANGES = "无源码提交变更";
|
|
82
|
+
const UNKNOWN_ARTIFACT_BASELINE = "上次该产物的源码提交无法确认";
|
|
83
|
+
|
|
84
|
+
function readGit(cwd, args) {
|
|
85
|
+
return childProcess.execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
86
|
+
}
|
|
87
|
+
|
|
70
88
|
function isAncestorCommit(ancestor, descendant, cwd) {
|
|
89
|
+
if (!COMMIT_HASH.test(ancestor)) return false;
|
|
71
90
|
try {
|
|
72
|
-
|
|
91
|
+
readGit(cwd, ["merge-base", "--is-ancestor", ancestor, descendant]);
|
|
73
92
|
return true;
|
|
74
93
|
} catch {
|
|
75
94
|
return false;
|
|
@@ -80,10 +99,8 @@ function isAncestorCommit(ancestor, descendant, cwd) {
|
|
|
80
99
|
* 将侧分支上的版本提交映射到它首次进入当前分支第一父链的合并提交。
|
|
81
100
|
* 否则 `versionCommit..HEAD` 会把当前分支上与侧分支互不为祖先的大量旧提交误算为本次更新。
|
|
82
101
|
*/
|
|
83
|
-
function resolveBuildSummaryBaseline(versionCommit, cwd) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const firstParentHistory = execSync("git rev-list --first-parent HEAD", { cwd, encoding: "utf-8" })
|
|
102
|
+
function resolveBuildSummaryBaseline(versionCommit, cwd, head) {
|
|
103
|
+
const firstParentHistory = readGit(cwd, ["rev-list", "--first-parent", head])
|
|
87
104
|
.trim()
|
|
88
105
|
.split(/\r?\n/)
|
|
89
106
|
.filter(Boolean);
|
|
@@ -128,61 +145,94 @@ function deduplicateCommitSubjects(subjects) {
|
|
|
128
145
|
});
|
|
129
146
|
}
|
|
130
147
|
|
|
131
|
-
function getHeadParents(cwd) {
|
|
132
|
-
const headWithParents =
|
|
148
|
+
function getHeadParents(cwd, head) {
|
|
149
|
+
const headWithParents = readGit(cwd, ["rev-list", "--parents", "-n", "1", head]).trim();
|
|
133
150
|
return headWithParents ? headWithParents.split(/\s+/).slice(1) : [];
|
|
134
151
|
}
|
|
135
152
|
|
|
153
|
+
function getPreviousArtifactSource(cwd, head, outputDir, branch) {
|
|
154
|
+
try {
|
|
155
|
+
const previous = readGit(outputDir, ["log", "-1", "--first-parent", "--format=%H",
|
|
156
|
+
`refs/remotes/origin/${branch}`, "--", "."]).trim();
|
|
157
|
+
if (!COMMIT_HASH.test(previous)) return "";
|
|
158
|
+
|
|
159
|
+
const prefix = readGit(outputDir, ["rev-parse", "--show-prefix"]).trimEnd();
|
|
160
|
+
if (prefix) {
|
|
161
|
+
// 旧构建会把兄弟目录一起提交,其提交说明无法证明当前端使用的是哪份源码。
|
|
162
|
+
const files = readGit(outputDir, ["diff-tree", "--root", "--no-commit-id", "--name-only",
|
|
163
|
+
"--no-renames", "-r", "-z", previous]).split("\0").filter(Boolean);
|
|
164
|
+
if (!files.length || files.some((file) => !file.startsWith(prefix))) return "";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const [trailers, body] = readGit(outputDir, ["show", "-s",
|
|
168
|
+
`--format=%(trailers:key=${SOURCE_COMMIT_TRAILER},valueonly,separator=%x1f)%x00%B`, previous]).split("\0");
|
|
169
|
+
const recorded = trailers.split("\x1f").at(-1).trim();
|
|
170
|
+
if (trailers.trim()) return isAncestorCommit(recorded, head, cwd) ? recorded : "";
|
|
171
|
+
|
|
172
|
+
// 兼容旧产物提交复制源码提交说明的行为,只接受完整说明在当前源码历史中唯一匹配。
|
|
173
|
+
const message = body.trim();
|
|
174
|
+
if (!message) return "";
|
|
175
|
+
const records = readGit(cwd, ["log", "--format=%H%x00%B%x00", "--fixed-strings",
|
|
176
|
+
`--grep=${message.split(/\r?\n/, 1)[0]}`, head]).split("\0");
|
|
177
|
+
const matches = [];
|
|
178
|
+
for (let index = 0; index + 1 < records.length; index += 2) {
|
|
179
|
+
const hash = records[index].trim();
|
|
180
|
+
if (COMMIT_HASH.test(hash) && records[index + 1].trim() === message) matches.push(hash);
|
|
181
|
+
}
|
|
182
|
+
return matches.length === 1 ? matches[0] : "";
|
|
183
|
+
} catch {
|
|
184
|
+
return "";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function getLegacySummaryRange(matcher, cwd, head, parents) {
|
|
189
|
+
if (!matcher) return "";
|
|
190
|
+
const history = readGit(cwd, ["log", "--format=%H%x1f%s", head]).split(/\r?\n/);
|
|
191
|
+
const previous = history.map((line) => line.split("\x1f", 2))
|
|
192
|
+
.find(([hash, subject]) => COMMIT_HASH.test(hash) && matcher.test(subject));
|
|
193
|
+
if (!previous) return "";
|
|
194
|
+
|
|
195
|
+
// 缺少产物基线时,沿用合并构建展示本次合入内容的历史口径。
|
|
196
|
+
const baseline = parents.length > 1 ? parents[0] : resolveBuildSummaryBaseline(previous[0], cwd, head);
|
|
197
|
+
return `${baseline}..${head}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
136
200
|
/**
|
|
137
|
-
*
|
|
138
|
-
* Merge 提交只描述 Git 操作,不作为企业微信中的更新内容。
|
|
139
|
-
* @param {String} gitAutoCommitText 自动版本提交模板
|
|
140
|
-
* @param {String} cwd Git 仓库目录
|
|
141
|
-
* @param {Number} limit 最多展示的提交数
|
|
142
|
-
* @returns {String} 构建更新摘要;无法识别版本基线时返回空字符串
|
|
201
|
+
* 产物仓发布按目标分支和目录比较源码;旧构建保留源码仓版本范围作为参考。
|
|
143
202
|
*/
|
|
144
|
-
function getBuildUpdateText(gitAutoCommitText, cwd = process.cwd(), limit = 10) {
|
|
203
|
+
function getBuildUpdateText(gitAutoCommitText, cwd = process.cwd(), limit = 10, options = {}) {
|
|
145
204
|
const matcher = createCommitTextMatcher(gitAutoCommitText);
|
|
146
|
-
|
|
205
|
+
const { sourceCommit, targetOutputDir, targetBranch } = options;
|
|
206
|
+
const head = COMMIT_HASH.test(sourceCommit) ? sourceCommit : "HEAD";
|
|
207
|
+
const hasArtifact = Boolean(targetOutputDir && targetBranch);
|
|
208
|
+
if (!matcher && !hasArtifact) return "";
|
|
147
209
|
|
|
148
210
|
try {
|
|
149
|
-
const
|
|
211
|
+
const baseline = hasArtifact ? getPreviousArtifactSource(cwd, head, targetOutputDir, targetBranch) : "";
|
|
212
|
+
const parents = baseline ? [] : getHeadParents(cwd, head);
|
|
213
|
+
const unknownBaseline = hasArtifact && !baseline;
|
|
214
|
+
const range = baseline ? `${baseline}..${head}`
|
|
215
|
+
: getLegacySummaryRange(matcher, cwd, head, parents) || (unknownBaseline && parents.length > 1 ? `${parents[0]}..${head}` : "");
|
|
216
|
+
if (!range && !unknownBaseline) return "";
|
|
217
|
+
|
|
218
|
+
const logArgs = range ? [range] : ["-1", head];
|
|
219
|
+
const history = readGit(cwd, ["log", "--no-merges", "--format=%s", ...logArgs]);
|
|
220
|
+
const subjects = deduplicateCommitSubjects(history
|
|
150
221
|
.trim()
|
|
151
222
|
.split(/\r?\n/)
|
|
152
|
-
.filter(
|
|
153
|
-
.map((line) => {
|
|
154
|
-
const separatorIndex = line.indexOf("\x1f");
|
|
155
|
-
return {
|
|
156
|
-
hash: line.slice(0, separatorIndex),
|
|
157
|
-
subject: line.slice(separatorIndex + 1)
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
const previousBuild = history.find(({ hash, subject }) => /^[0-9a-f]{40}$/i.test(hash) && matcher.test(subject));
|
|
161
|
-
|
|
162
|
-
if (!previousBuild) return "";
|
|
223
|
+
.filter((subject) => subject && !matcher?.test(subject) && !DEFAULT_BUILD_SUBJECT.test(subject)));
|
|
163
224
|
|
|
164
|
-
|
|
165
|
-
// 构建正好发生在 Merge HEAD 时,更新内容应描述本次合入的分支,而不是第一父链上更早的待发布提交。
|
|
166
|
-
const headParents = getHeadParents(cwd);
|
|
167
|
-
const range = headParents.length > 1 ? `${headParents[0]}..HEAD` : `${baseline}..HEAD`;
|
|
168
|
-
const subjects = deduplicateCommitSubjects(execSync(`git log --no-merges --format=%s ${range}`, {
|
|
169
|
-
cwd,
|
|
170
|
-
encoding: "utf-8"
|
|
171
|
-
})
|
|
172
|
-
.trim()
|
|
173
|
-
.split(/\r?\n/)
|
|
174
|
-
.filter(Boolean));
|
|
175
|
-
|
|
176
|
-
if (subjects.length === 0) return "无源码提交变更";
|
|
225
|
+
if (subjects.length === 0) return unknownBaseline ? UNKNOWN_ARTIFACT_BASELINE : NO_SOURCE_CHANGES;
|
|
177
226
|
|
|
178
227
|
const visibleSubjects = subjects.slice(0, limit);
|
|
179
228
|
if (subjects.length > limit) {
|
|
180
229
|
visibleSubjects.push(`...另 ${subjects.length - limit} 条提交`);
|
|
181
230
|
}
|
|
182
|
-
|
|
231
|
+
const summary = visibleSubjects.map((subject) => `- ${subject}`).join("\n");
|
|
232
|
+
return unknownBaseline ? `${UNKNOWN_ARTIFACT_BASELINE},以下为可识别的提交\n${summary}` : summary;
|
|
183
233
|
} catch (error) {
|
|
184
234
|
logTerminal("warning", `获取构建更新摘要失败:${error.message}`);
|
|
185
|
-
return "";
|
|
235
|
+
return hasArtifact ? UNKNOWN_ARTIFACT_BASELINE : "";
|
|
186
236
|
}
|
|
187
237
|
}
|
|
188
238
|
|
|
@@ -261,10 +311,12 @@ function checkGitStatus(excludeDir, extraFilter, extraParams) {
|
|
|
261
311
|
|
|
262
312
|
try {
|
|
263
313
|
// 获取所有未跟踪和已修改的文件列表
|
|
264
|
-
|
|
265
|
-
|
|
314
|
+
if (targetProjectOutputDirCmd && !targetProjectOutputDir) throw new Error("未配置构建产物目录");
|
|
315
|
+
const scope = targetProjectOutputDirCmd ? ["--", "."] : [];
|
|
316
|
+
const status = readGit(targetProjectOutputDirCmd ? targetProjectOutputDir : process.cwd(), ["status", "--porcelain", "-z", ...scope]);
|
|
317
|
+
const files = status
|
|
266
318
|
.split("\u0000")
|
|
267
|
-
.filter((file) => file.trim() && isBuildFile(targetProjectOutputDir, file));
|
|
319
|
+
.filter((file) => file.trim() && (targetProjectOutputDirCmd || isBuildFile(targetProjectOutputDir, file)));
|
|
268
320
|
const excludeFiles = []; // 非指定构建相关文件
|
|
269
321
|
const includeFiles = []; // 指定的构建相关文件
|
|
270
322
|
|
|
@@ -302,10 +354,10 @@ function checkGitStatus(excludeDir, extraFilter, extraParams) {
|
|
|
302
354
|
|
|
303
355
|
function runGitCommand(command, options = {}) {
|
|
304
356
|
try {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
357
|
+
const commandOptions = { ...options, encoding: "utf8" };
|
|
358
|
+
const result = Array.isArray(command)
|
|
359
|
+
? childProcess.execFileSync("git", command, commandOptions)
|
|
360
|
+
: execSync(command, commandOptions);
|
|
309
361
|
if (result) {
|
|
310
362
|
return result.trim();
|
|
311
363
|
}
|
|
@@ -315,14 +367,13 @@ function runGitCommand(command, options = {}) {
|
|
|
315
367
|
}
|
|
316
368
|
}
|
|
317
369
|
|
|
318
|
-
function hasStagedChanges(
|
|
370
|
+
function hasStagedChanges(scope, options) {
|
|
319
371
|
try {
|
|
320
|
-
|
|
321
|
-
stdio: "ignore"
|
|
322
|
-
});
|
|
372
|
+
childProcess.execFileSync("git", ["diff", "--cached", "--quiet", ...scope], { ...options, stdio: "ignore" });
|
|
323
373
|
return false;
|
|
324
374
|
} catch (error) {
|
|
325
|
-
|
|
375
|
+
if (error.status === 1) return true;
|
|
376
|
+
throw error;
|
|
326
377
|
}
|
|
327
378
|
}
|
|
328
379
|
|
|
@@ -380,7 +431,6 @@ function autoGitProcess(buildFoldName, newFileName, extraParams = {}) {
|
|
|
380
431
|
gitAutoPushRepos,
|
|
381
432
|
targetProjectOutputDir,
|
|
382
433
|
gitAutoPushReposBranchMap = {},
|
|
383
|
-
targetProjectOutputDirCmd = gitAutoPushRepos ? ` -C ${targetProjectOutputDir}` : "",
|
|
384
434
|
projectName,
|
|
385
435
|
gitLockDir,
|
|
386
436
|
gitProcessOrder
|
|
@@ -400,18 +450,12 @@ function autoGitProcess(buildFoldName, newFileName, extraParams = {}) {
|
|
|
400
450
|
runAppGitProcess();
|
|
401
451
|
}
|
|
402
452
|
|
|
403
|
-
const { commitMsg, branch } = gitInfo || {};
|
|
453
|
+
const { commitMsg, branch, fullHash } = gitInfo || {};
|
|
404
454
|
const gitRepos = gitAutoPushRepos ? `构建仓库: ${targetProjectOutputDir}` : `当前项目: ${projectName}`;
|
|
405
|
-
let tempGitAutoCommitText = gitAutoCommitText ? gitAutoCommitText.replace("{version}", newVersion) : "";
|
|
406
|
-
|
|
407
|
-
if (gitAutoPushRepos) {
|
|
408
|
-
tempGitAutoCommitText = commitMsg;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
455
|
const tempBranch = gitAutoPushRepos ? gitAutoPushReposBranchMap[branch] : branch;
|
|
412
|
-
const
|
|
413
|
-
const
|
|
414
|
-
const
|
|
456
|
+
const commitText = gitAutoPushRepos ? String(commitMsg || "") : (gitAutoCommitText || "").replace("{version}", newVersion);
|
|
457
|
+
const gitOptions = gitAutoPushRepos ? { cwd: targetProjectOutputDir } : {};
|
|
458
|
+
const scope = gitAutoPushRepos ? ["--", "."] : [];
|
|
415
459
|
|
|
416
460
|
if (!tempBranch) {
|
|
417
461
|
logTerminal("error", `缺少分支配置`);
|
|
@@ -425,13 +469,20 @@ function autoGitProcess(buildFoldName, newFileName, extraParams = {}) {
|
|
|
425
469
|
return;
|
|
426
470
|
}
|
|
427
471
|
|
|
428
|
-
runGitCommand(
|
|
429
|
-
if (!hasStagedChanges(
|
|
472
|
+
runGitCommand(["add", "-A", ...scope], gitOptions);
|
|
473
|
+
if (!hasStagedChanges(scope, gitOptions)) {
|
|
430
474
|
logTerminal("warning", `Git ${gitRepos} 没有可提交的变更,跳过自动提交`);
|
|
431
|
-
|
|
432
|
-
runGitCommand(commitCmd);
|
|
433
|
-
runGitCommand(pushCommand);
|
|
475
|
+
return;
|
|
434
476
|
}
|
|
477
|
+
|
|
478
|
+
const commitArgs = ["commit", "-m", commitText];
|
|
479
|
+
if (gitAutoPushRepos) {
|
|
480
|
+
if (COMMIT_HASH.test(fullHash)) commitArgs.push("--trailer", `${SOURCE_COMMIT_TRAILER}: ${fullHash}`);
|
|
481
|
+
// 同仓可能同时生成多个端的产物,只提交当前目录,避免给兄弟端写错源码基线。
|
|
482
|
+
commitArgs.push("--only", ...scope);
|
|
483
|
+
}
|
|
484
|
+
runGitCommand(commitArgs, gitOptions);
|
|
485
|
+
runGitCommand(["push", "origin", tempBranch], gitOptions);
|
|
435
486
|
};
|
|
436
487
|
|
|
437
488
|
if (gitAutoPushRepos) {
|
|
@@ -454,13 +505,11 @@ async function autoBranchProcess(config) {
|
|
|
454
505
|
const { gitAutoPushRepos, gitAutoPushReposBranchMap, currentBranch, targetProjectOutputDir, validateConfig } =
|
|
455
506
|
config || {};
|
|
456
507
|
const tempBranch = gitAutoPushRepos ? gitAutoPushReposBranchMap[currentBranch] : currentBranch;
|
|
457
|
-
const
|
|
458
|
-
const checkoutCmd = `git${targetProjectOutputDirCmd} checkout ${tempBranch}`;
|
|
459
|
-
const pullCmd = `git${targetProjectOutputDirCmd} pull --ff-only origin ${tempBranch}`;
|
|
508
|
+
const gitOptions = gitAutoPushRepos ? { cwd: targetProjectOutputDir } : {};
|
|
460
509
|
const fileList = checkGitStatus(undefined, undefined, {
|
|
461
510
|
onlyCheckStatus: true,
|
|
462
511
|
targetProjectOutputDir,
|
|
463
|
-
|
|
512
|
+
gitAutoPushRepos,
|
|
464
513
|
startLogText: "Git自动化开始执行..."
|
|
465
514
|
});
|
|
466
515
|
|
|
@@ -478,8 +527,8 @@ async function autoBranchProcess(config) {
|
|
|
478
527
|
process.exit(1);
|
|
479
528
|
}
|
|
480
529
|
|
|
481
|
-
runGitCommand(
|
|
482
|
-
runGitCommand(
|
|
530
|
+
runGitCommand(["checkout", tempBranch], gitOptions);
|
|
531
|
+
runGitCommand(["pull", "--ff-only", "origin", tempBranch], gitOptions);
|
|
483
532
|
}
|
|
484
533
|
|
|
485
534
|
/**
|
|
@@ -3,20 +3,20 @@ const fs = require("fs");
|
|
|
3
3
|
function normalizeRelativePath(value) {
|
|
4
4
|
return String(value).replace(/\\/g, "/");
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
-
*/
|
|
10
|
-
function parseGitmodulesPaths(rootDir) {
|
|
11
|
-
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
-
if (!fs.existsSync(p)) return [];
|
|
13
|
-
const content = fs.readFileSync(p, "utf8");
|
|
14
|
-
const paths = [];
|
|
15
|
-
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
-
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
-
if (m) paths.push(m[1].trim());
|
|
18
|
-
});
|
|
19
|
-
return paths;
|
|
20
|
-
}
|
|
21
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
+
*/
|
|
10
|
+
function parseGitmodulesPaths(rootDir) {
|
|
11
|
+
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
+
if (!fs.existsSync(p)) return [];
|
|
13
|
+
const content = fs.readFileSync(p, "utf8");
|
|
14
|
+
const paths = [];
|
|
15
|
+
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
+
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
+
if (m) paths.push(m[1].trim());
|
|
18
|
+
});
|
|
19
|
+
return paths;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
module.exports = { normalizeRelativePath, parseGitmodulesPaths };
|