forked from bluelovers/idea-l10n-zht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci-postpublish.ts
165 lines (135 loc) · 3.24 KB
/
ci-postpublish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { gitDiffFrom } from 'git-diff-from';
import { __root } from '../test/__root';
import { gitlog } from 'gitlog2';
import Bluebird from 'bluebird';
import micromatch, { not, match } from 'micromatch';
import { updateChangelogByCwd } from '@yarn-tool/changelog';
import { console } from 'debug-color2';
import { getGitLogs } from '../lib/git/git-logs';
import { lazyCommitFiles } from '../lib/git/commit';
import { outputFile, outputJSON, readJSON } from 'fs-extra';
import { __file_publish_tags_json } from '../lib/const';
import { array_unique_overwrite } from 'array-hyper-unique';
import { LF } from 'crlf-normalize';
import { getSourceInfoSync } from '../lib/build/get-source-info';
import { getBranchInfo } from '../lib/git/branch-info';
import { updatePublishTags } from '../lib/git/update-publish-tags';
export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)
.then((from) =>
{
from ||= 'origin/master';
console.dir({
from,
});
//from = '2d01cffc5da15e0a34a40b40ec3b7d0cc7612dda';
const latestLog = getGitLogs()[0]
let to = latestLog.hash;
console.log(`input`);
console.dir({
from,
to,
head: {
subject: latestLog.subject,
},
});
return Bluebird.props({
info: gitDiffFrom(from, to, {
cwd: __root,
}),
latestLog,
})
})
.then(async ({
info,
latestLog,
}) =>
{
const files = not(info.files, [
'CHANGELOG.md',
'test/**',
'.run/**',
'docs/**',
'coverage/**',
'test/**',
'*.*',
'.*',
]);
//console.dir(files);
//console.dir(info);
console.log(`result`);
const isSameHash = info.from === info.to;
const isBuildCommit = latestLog.subject.startsWith('build(release): update build');
const result = {
from: info.from,
to: info.to,
changed: files.length,
isSameHash,
isBuildCommit,
};
console.dir(result);
if (isSameHash)
{
console.error(`git 沒有變化 或 遠端與本地無法比對差異`)
if (!isBuildCommit)
{
return
}
console.yellow.warn(`前次任務可能未正確執行 CHANGELOG,嘗試檢測差異列表`)
}
let _do = await Promise.resolve().then(() =>
{
let _files: string[];
if (files.length)
{
if (includeJar(files))
{
_files = files
}
}
else if (isBuildCommit && includeJar(latestLog.files))
{
_files = latestLog.files
}
if (typeof _files?.length === 'number')
{
if (_files.length < 10)
{
console.log(`files`);
console.dir(_files);
}
return true
}
return false;
});
if (_do)
{
const { isMasterBranch } = getBranchInfo();
if (isMasterBranch)
{
await updateChangelogByCwd(__root, {
type: 'independent',
});
}
const __pluginVersion = getSourceInfoSync().pluginMeta.version;
await updatePublishTags();
await lazyCommitFiles([
'./CHANGELOG.md',
], `build(changelog): update CHANGELOG ( ${__pluginVersion} )`).catch(() => void 0);
await lazyCommitFiles([
'./lib/const/publish-tags.json',
], `build(cache): update publish tags`).catch(() => void 0);
}
else
{
console.warn(`編譯版本沒有任何變化`)
}
return result
})
//.tap(console.dir)
;
function includeJar(files: string[])
{
return micromatch(files, [
'plugin-dev-out/*.jar',
]).length > 0
}