Skip to content

Commit c2e5bec

Browse files
authored
ci: cli release (#261)
1 parent 5dec24f commit c2e5bec

9 files changed

+126
-25
lines changed

.github/workflows/release-cli.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Create Cli Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'cli-v*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
# Setup .npmrc file to publish to npm
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: '20'
17+
registry-url: 'https://registry.npmjs.org'
18+
- run: npm install
19+
- run: npm run build-cli
20+
- run: cd md-cli && npm ci && npm publish
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
23+

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
name: Create Release
2+
13
on:
24
push:
35
tags:
46
- "v*"
57

6-
name: Create Release
7-
88
jobs:
99
build:
1010
name: Create Release

bin/release.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(async function () {
2+
const fs = require('fs');
3+
const path = require('path');
4+
const packageJson = require('../md-cli/package.json');
5+
const child_process = require('child_process');
6+
// 自动更新版本
7+
// version可以传递如 6.1.1 | patch | minor | major
8+
const execCommand = arr => (Array.isArray(arr) ? arr : [arr]).forEach(c => {
9+
try {
10+
console.log(`start: ${c}...`)
11+
console.log(child_process.execSync(c).toString('utf8'))
12+
} catch (error) {
13+
console.log('\x1B[31m%s\x1B[0m', error.stdout.toString())
14+
process.exit(1)
15+
}
16+
})
17+
const getNewVersion = (oldVersion, version = 'patch') => {
18+
// [<newversion> | major | minor | patch]
19+
if (/^([0-9]+\.*)+$/.test(version)) return version
20+
const types = ['major', 'minor', 'patch']
21+
const index = types.indexOf(version)
22+
if (index >= 0) {
23+
const versionArr = oldVersion.split('.')
24+
versionArr[index] = Number(versionArr[index]) + 1
25+
return versionArr.map((e, i) => i > index ? 0 : e).join('.')
26+
}
27+
return getNewVersion(oldVersion)
28+
}
29+
const newVersionObj = {
30+
version: getNewVersion(packageJson.version, process.argv[2]),
31+
};
32+
fs.writeFileSync(
33+
path.resolve(__dirname, '../md-cli/package.json'),
34+
JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) +
35+
'\n'
36+
);
37+
console.log(newVersionObj);
38+
execCommand([
39+
`git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`,
40+
`git tag cli-v${newVersionObj.version}`,
41+
'git push && git push --tags',
42+
])
43+
console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建')
44+
}())

md-cli/.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.tgz
2+
httpData/

md-cli/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

md-cli/package-lock.json

+46-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

md-cli/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@doocs/md-cli",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "✍ 一款高度简洁的微信 Markdown 编辑器:支持 Markdown 所有基础语法、色盘取色、一键复制并粘贴到公众号后台、多图上传、一键下载文档、自定义 CSS 样式、一键重置等特性",
55
"main": "index.js",
66
"scripts": {
@@ -21,9 +21,9 @@
2121
"license": "ISC",
2222
"dependencies": {
2323
"@wll8/process-manager": "^1.0.1",
24-
"form-data": "2.3.3",
24+
"form-data": "4.0.0",
2525
"get-port": "5.1.1",
2626
"mockm": "^1.1.27-alpha.2",
27-
"node-fetch": "^3.1.0"
27+
"node-fetch": "^3.2.10"
2828
}
2929
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "md",
3-
"version": "1.5.9",
3+
"version": "1.6.0",
44
"private": false,
55
"scripts": {
6+
"release:cli": "node ./bin/release.js",
67
"prepare": "husky install",
78
"lint": "vue-cli-service lint src",
89
"start": "npm run lint -- --fix && run-p serve",
@@ -16,6 +17,7 @@
1617
"axios": "^1.6.0",
1718
"buffer-from": "^1.1.2",
1819
"codemirror": "^5.65.7",
20+
"core-js": "^3.34.0",
1921
"cos-js-sdk-v5": "^1.3.9",
2022
"crypto-js": "^4.2.0",
2123
"element-ui": "^2.15.9",

0 commit comments

Comments
 (0)