Skip to content

Commit

Permalink
ci: cli release (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkasany committed Dec 7, 2023
1 parent 5dec24f commit c2e5bec
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 25 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create Cli Release

on:
push:
tags:
- 'cli-v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build-cli
- run: cd md-cli && npm ci && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Create Release

on:
push:
tags:
- "v*"

name: Create Release

jobs:
build:
name: Create Release
Expand Down
44 changes: 44 additions & 0 deletions bin/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(async function () {
const fs = require('fs');
const path = require('path');
const packageJson = require('../md-cli/package.json');
const child_process = require('child_process');
// 自动更新版本
// version可以传递如 6.1.1 | patch | minor | major
const execCommand = arr => (Array.isArray(arr) ? arr : [arr]).forEach(c => {
try {
console.log(`start: ${c}...`)
console.log(child_process.execSync(c).toString('utf8'))
} catch (error) {
console.log('\x1B[31m%s\x1B[0m', error.stdout.toString())
process.exit(1)
}
})
const getNewVersion = (oldVersion, version = 'patch') => {
// [<newversion> | major | minor | patch]
if (/^([0-9]+\.*)+$/.test(version)) return version
const types = ['major', 'minor', 'patch']
const index = types.indexOf(version)
if (index >= 0) {
const versionArr = oldVersion.split('.')
versionArr[index] = Number(versionArr[index]) + 1
return versionArr.map((e, i) => i > index ? 0 : e).join('.')
}
return getNewVersion(oldVersion)
}
const newVersionObj = {
version: getNewVersion(packageJson.version, process.argv[2]),
};
fs.writeFileSync(
path.resolve(__dirname, '../md-cli/package.json'),
JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) +
'\n'
);
console.log(newVersionObj);
execCommand([
`git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`,
`git tag cli-v${newVersionObj.version}`,
'git push && git push --tags',
])
console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建')
}())
2 changes: 2 additions & 0 deletions md-cli/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.tgz
httpData/
1 change: 1 addition & 0 deletions md-cli/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org
63 changes: 46 additions & 17 deletions md-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "md",
"version": "1.5.9",
"version": "1.6.0",
"private": false,
"scripts": {
"release:cli": "node ./bin/release.js",
"prepare": "husky install",
"lint": "vue-cli-service lint src",
"start": "npm run lint -- --fix && run-p serve",
Expand All @@ -16,6 +17,7 @@
"axios": "^1.6.0",
"buffer-from": "^1.1.2",
"codemirror": "^5.65.7",
"core-js": "^3.34.0",
"cos-js-sdk-v5": "^1.3.9",
"crypto-js": "^4.2.0",
"element-ui": "^2.15.9",
Expand Down

0 comments on commit c2e5bec

Please sign in to comment.