@wjwjq/release-helper 0.1.5 → 0.1.7
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/dist/.release/release.conf.yaml +2 -0
- package/dist/cli.js +1 -1
- package/dist/deploy/script/common.sh +36 -29
- package/dist/deploy/script/prompt.sh +6 -0
- package/dist/pack.js +22 -21
- package/dist/prepare.js +20 -10
- package/dist/publish.js +7 -9
- package/dist/release.js +4 -5
- package/dist/start_prepare.js +3 -3
- package/package.json +1 -1
- package/pnpm-lock.yaml +0 -2443
- package/src/.release/README.md +0 -73
- package/src/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +0 -418
- package/src/.release/nginx/ca/ca.crt +0 -32
- package/src/.release/nginx/ca/ca.key +0 -54
- package/src/.release/nginx/ca/client.crt +0 -100
- package/src/.release/nginx/ca/client.csr +0 -16
- package/src/.release/nginx/ca/client.p12 +0 -0
- package/src/.release/nginx/ca/client.pem +0 -30
- package/src/.release/nginx/ca/server.crt +0 -101
- package/src/.release/nginx/ca/server.csr +0 -17
- package/src/.release/nginx/ca/server.key +0 -27
- package/src/.release/nginx/ca/server.pem +0 -30
- package/src/.release/nginx/nginx.conf +0 -179
- package/src/.release/release.conf.yaml +0 -15
- package/src/cli.ts +0 -99
- package/src/deploy/pkg/nginx/nginx.logrotate.tpl +0 -14
- package/src/deploy/pkg/nginx/nginx.service.tpl +0 -32
- package/src/deploy/pkg/nginx_binary/compile.sh +0 -39
- package/src/deploy/pkg/nginx_binary/nginx-arm-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
- package/src/deploy/script/common.sh +0 -196
- package/src/deploy/script/install.sh +0 -7
- package/src/deploy/script/nginx.sh +0 -265
- package/src/deploy/script/prompt.sh +0 -110
- package/src/deploy/script/readme.md +0 -10
- package/src/deploy/script/upgrade.sh +0 -7
- package/src/logger.ts +0 -18
- package/src/pack.ts +0 -152
- package/src/prepare.ts +0 -120
- package/src/publish.ts +0 -308
- package/src/release.ts +0 -292
- package/src/start_prepare.ts +0 -13
package/src/release.ts
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import * as inquirer from "@inquirer/prompts"
|
|
2
|
-
import process from "process"
|
|
3
|
-
import pc from "picocolors"
|
|
4
|
-
|
|
5
|
-
import { pack } from './pack'
|
|
6
|
-
import { getGitTags, isGitFlowRepo, publish, selectLatestTag } from './publish'
|
|
7
|
-
|
|
8
|
-
import { __releaseDir, releaseConf, $, checkEnvInfo } from './prepare'
|
|
9
|
-
import { ResultPromise } from "execa"
|
|
10
|
-
|
|
11
|
-
import { logger } from './logger';
|
|
12
|
-
|
|
13
|
-
export async function release(fromPublishCmd = false) {
|
|
14
|
-
try {
|
|
15
|
-
await checkEnvInfo();
|
|
16
|
-
|
|
17
|
-
await hasUncommittedChanges();
|
|
18
|
-
|
|
19
|
-
// 保存当前分支信息,打包发布完成后切回当前分支
|
|
20
|
-
let { stdout: originalBranch } = await $(`git branch --show-current`)
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* a. 指定版本号tag
|
|
25
|
-
*
|
|
26
|
-
* b. 是否遵循git flow 发布流程,
|
|
27
|
-
*
|
|
28
|
-
* 1. 是 --> 测是否是develop分支,
|
|
29
|
-
*
|
|
30
|
-
* --> 是 同步develop,走git flow release到master, 并从远程master 切tag 打包并上传
|
|
31
|
-
* --> 否 检测是否为release 分支,
|
|
32
|
-
* --> 是, 走git flow release 到master, 并从远程master 切tag 打包并上传
|
|
33
|
-
* --> 提示,分支错误
|
|
34
|
-
* 2. 否 --> 选择指定的远程分支,
|
|
35
|
-
* c. 选择从哪个分支生成release msgs
|
|
36
|
-
* --> 默认最新发布分支
|
|
37
|
-
* --> 自定义
|
|
38
|
-
* d. 从指定分支或master 并打tag 和打包并上传
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
// 获取版本号
|
|
42
|
-
let version = await inquirer
|
|
43
|
-
.input({
|
|
44
|
-
message: '请输入版本号:',
|
|
45
|
-
},)
|
|
46
|
-
|
|
47
|
-
if (version == '') {
|
|
48
|
-
logger.error('版本号不能为空!')
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
// 补齐v开头 如果是数字开头
|
|
52
|
-
if (/^\d/.test(version)) {
|
|
53
|
-
version = `v${version}`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 版本号检测
|
|
57
|
-
const tags = await getGitTags();
|
|
58
|
-
if (tags.some(tag => tag === version)) {
|
|
59
|
-
logger.error('版本号已存在,请更换版本号!')
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
let remoteTargetBranch = 'master';
|
|
65
|
-
if (fromPublishCmd) {
|
|
66
|
-
remoteTargetBranch = await doCustomSpecifyBranchRelease()
|
|
67
|
-
} else {
|
|
68
|
-
const releaseWay = await inquirer
|
|
69
|
-
.select(
|
|
70
|
-
{
|
|
71
|
-
message: '请选择发布方式:',
|
|
72
|
-
default: '1',
|
|
73
|
-
choices: [
|
|
74
|
-
{
|
|
75
|
-
name: 'Git flow流程发布',
|
|
76
|
-
value: '1',
|
|
77
|
-
description: '遵循Git flow流程,需保证仓库已初始化为git flow模式, 以master为远程分支,打Tag',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: '自定义分支打包发布',
|
|
81
|
-
value: '2',
|
|
82
|
-
description: '自定义指定远程分支,打Tag的方式',
|
|
83
|
-
},
|
|
84
|
-
]
|
|
85
|
-
},
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
if (releaseWay === '1') {
|
|
89
|
-
remoteTargetBranch = await doGitFlowRelease(version);
|
|
90
|
-
} else if (releaseWay === '2') {
|
|
91
|
-
remoteTargetBranch = await doCustomSpecifyBranchRelease()
|
|
92
|
-
} else {
|
|
93
|
-
logger.error(`发布方式不能为空`)
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (remoteTargetBranch == null) {
|
|
98
|
-
logger.error(`目标发布分支不能为空`)
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
logger.tip(`start build and pack`)
|
|
104
|
-
|
|
105
|
-
// 切换到指定分支 同步remote后 打包
|
|
106
|
-
await execGitCheckout(remoteTargetBranch);
|
|
107
|
-
|
|
108
|
-
await execGitPullOrigin(remoteTargetBranch);
|
|
109
|
-
|
|
110
|
-
// 选择从哪个tag开始生成release 信息
|
|
111
|
-
const userSelectedLatestTag = await selectLatestTag(version);
|
|
112
|
-
|
|
113
|
-
await execWithPipe(releaseConf.buildCmd)
|
|
114
|
-
|
|
115
|
-
const source = await pack(version);
|
|
116
|
-
|
|
117
|
-
if (source === undefined) {
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
await publish({ ...source, remoteBranch: remoteTargetBranch, userSelectedLatestTag });
|
|
123
|
-
|
|
124
|
-
logger.info(pc.green('done'))
|
|
125
|
-
|
|
126
|
-
// 切换回起始分支
|
|
127
|
-
await execGitCheckout(originalBranch)
|
|
128
|
-
} catch (error) {
|
|
129
|
-
console.error('Error:', error);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
async function doGitFlowRelease(version: string) {
|
|
135
|
-
// 检查 .git/config 中是否存在 gitflow 配置
|
|
136
|
-
const isGitFlow = await isGitFlowRepo();
|
|
137
|
-
if (!isGitFlow) {
|
|
138
|
-
logger.error('当前仓库 非git flow仓库,请使用git flow init 初始化后,再执行此命令')
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// 获取当前所属分支
|
|
143
|
-
let { stdout: currentBranch } = await $(`git branch --show-current`)
|
|
144
|
-
|
|
145
|
-
const releaseBranch = `release/${version}`
|
|
146
|
-
if (currentBranch !== 'develop' && currentBranch !== releaseBranch) {
|
|
147
|
-
// await hasUncommittedFiles();
|
|
148
|
-
/**
|
|
149
|
-
* 判断是否已存在 release/version 分支
|
|
150
|
-
* 是--> 如果本地是否此分支
|
|
151
|
-
* -->否 checkout -b 指定分支
|
|
152
|
-
* -->是 checkout 指定分支
|
|
153
|
-
* 否--> 切换到develop分支
|
|
154
|
-
*/
|
|
155
|
-
const { stdout } = await $('git branch -a');
|
|
156
|
-
const branches = stdout.split('\n').map(branch => branch.trim().replace(/^\* /, ''));
|
|
157
|
-
const preReleaseBranch = branches.includes(releaseBranch) ? releaseBranch : 'develop'
|
|
158
|
-
await execGitCheckout(preReleaseBranch)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (currentBranch === 'develop') {
|
|
162
|
-
await execGitPullOrigin(`develop`)
|
|
163
|
-
|
|
164
|
-
const flowReleaseRes = await execWithPipe(`git flow release start ${version}`)
|
|
165
|
-
if (!(flowReleaseRes.stdout.indexOf(`A new branch '${releaseBranch}' was created`) > -1)) {
|
|
166
|
-
logger.error('执行 git flow release 失败')
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
try {
|
|
171
|
-
await execGitPullOrigin(releaseBranch)
|
|
172
|
-
} catch (error) {
|
|
173
|
-
console.error("🚀 ~ doGitFlowRelease ~ error:", error)
|
|
174
|
-
if (!(error && error.toString().indexOf(`fatal: couldn't find remote ref ${releaseBranch}`) > -1)) {
|
|
175
|
-
logger.error(`同步分支: ${releaseBranch} 失败`)
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// 添加版本到package.json
|
|
182
|
-
try {
|
|
183
|
-
const npmVersionRes = await $(`npm version ${version} --no-git-tag-version`)
|
|
184
|
-
if (npmVersionRes.stderr) {
|
|
185
|
-
logger.error('添加版本信息到package.json失败')
|
|
186
|
-
process.exit(1);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
logger.info(pc.green(`添加 ${version} 版本信息到package.json 成功`))
|
|
190
|
-
} catch (error) {
|
|
191
|
-
if (error && error.toString().indexOf('npm error Version not changed') == -1) {
|
|
192
|
-
logger.error('添加版本信息到package.json失败')
|
|
193
|
-
process.exit(1);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const hasUncommitted = await hasUncommittedChanges(true);
|
|
197
|
-
|
|
198
|
-
if (hasUncommitted) {
|
|
199
|
-
await $(`git add -A`)
|
|
200
|
-
await $('git commit', ['-m', `Release version: ${version}`, '--no-verify'])
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
await execWithPipe(`git flow release finish`, [version, '-m', `Release version: ${version}`]);
|
|
204
|
-
// if (releaseFRes.stderr) {
|
|
205
|
-
// logger.error('执行 git flow release finish 失败')
|
|
206
|
-
// process.exit(1);
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
|
-
// 同步到远端
|
|
210
|
-
await $(`git push --all`)
|
|
211
|
-
await $(`git push --tags`)
|
|
212
|
-
|
|
213
|
-
return 'master'
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async function doCustomSpecifyBranchRelease() {
|
|
217
|
-
|
|
218
|
-
const { stdout } = await $('git branch -r');
|
|
219
|
-
const branches = stdout.split('\n').map(branch => branch.trim()).filter(item => !item.startsWith('origin/HEAD')).map(branch => ({ value: branch.replace('origin/', '') }));
|
|
220
|
-
|
|
221
|
-
const selectedBranch = await inquirer.select({
|
|
222
|
-
message: '请选择目标分支, 分支未找到,请先将本地分支推到远端,再执行此命令',
|
|
223
|
-
choices: branches
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
return selectedBranch;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
async function hasUncommittedChanges(boolReturned = false) {
|
|
231
|
-
// 检查当前分支是否存在未提交文件
|
|
232
|
-
const { stdout: uncommitted } = await $`git status --porcelain`
|
|
233
|
-
|
|
234
|
-
if (boolReturned) {
|
|
235
|
-
return !!uncommitted.toString().length
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (uncommitted.toString().length) {
|
|
239
|
-
logger.error('当前分支存在尚未提交的文件,请提交后再运行此命令')
|
|
240
|
-
return Promise.reject(true)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return Promise.resolve(false);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
async function execGitPullOrigin(remoteTargetBranch: string) {
|
|
248
|
-
logger.tip(`${ remoteTargetBranch} syncing...`)
|
|
249
|
-
|
|
250
|
-
const syncReleaseBranchRes = $('git', ['pull', 'origin', remoteTargetBranch])
|
|
251
|
-
syncReleaseBranchRes.stdout.pipe(process.stdout)
|
|
252
|
-
syncReleaseBranchRes.stderr.pipe(process.stderr)
|
|
253
|
-
const res = await syncReleaseBranchRes;
|
|
254
|
-
// fatal: unable to access 'https://github.com/user/repo.git/': Could not resolve host: xxx
|
|
255
|
-
// fatal: unable to access 'https://github.com/user/repo.git/':
|
|
256
|
-
// fatal: Couldn't find remote ref chore/releset_test ...
|
|
257
|
-
if (res.stdout.indexOf('fatal:') > -1 || res.stderr.indexOf('fatal:') > -1) {
|
|
258
|
-
logger.error(`同步${remoteTargetBranch} 失败`)
|
|
259
|
-
process.exit(1);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async function execWithPipe(...args: any[]) {
|
|
264
|
-
const execRes = $(...args as Parameters<typeof $>) as unknown as ResultPromise<{
|
|
265
|
-
encoding: "utf8";
|
|
266
|
-
}>
|
|
267
|
-
execRes.stdout.pipe(process.stdout);
|
|
268
|
-
execRes.stderr.pipe(process.stderr);
|
|
269
|
-
const result = await execRes
|
|
270
|
-
return result
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
async function execGitCheckout(remoteTargetBranch: string) {
|
|
275
|
-
await hasUncommittedChanges();
|
|
276
|
-
|
|
277
|
-
const { stdout: prevCurrentBranch } = await $(`git branch --show-current`)
|
|
278
|
-
|
|
279
|
-
if (prevCurrentBranch !== remoteTargetBranch) {
|
|
280
|
-
const execRes = $(`git checkout ${remoteTargetBranch}`)
|
|
281
|
-
execRes.stdout.pipe(process.stdout);
|
|
282
|
-
execRes.stderr.pipe(process.stderr);
|
|
283
|
-
const result = await execRes;
|
|
284
|
-
|
|
285
|
-
const { stdout: currentBranch } = await $(`git branch --show-current`)
|
|
286
|
-
|
|
287
|
-
if (currentBranch !== remoteTargetBranch) {
|
|
288
|
-
logger.error(`目标发布分支[${remoteTargetBranch}] checkout 失败`)
|
|
289
|
-
return Promise.reject(result);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
package/src/start_prepare.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logger";
|
|
2
|
-
import { prepare } from "./prepare";
|
|
3
|
-
|
|
4
|
-
(async function startPrepare(){
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
logger.info('start to generate .release configuration ')
|
|
8
|
-
await prepare();
|
|
9
|
-
logger.info('done')
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error(`release-helper error: `, error)
|
|
12
|
-
}
|
|
13
|
-
})()
|