ci: cli release

This commit is contained in:
thinkasany 2023-12-07 10:39:07 +08:00
parent 5dec24f819
commit 441f4db399
7 changed files with 122 additions and 20 deletions

24
.github/workflows/npm-release.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Public Npm
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 }}

44
bin/release.js Normal file
View File

@ -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
md-cli/.npmignore Normal file
View File

@ -0,0 +1,2 @@
.tgz
httpData/

1
md-cli/.npmrc Normal file
View File

@ -0,0 +1 @@
registry=https://registry.npmjs.org

View File

@ -10,10 +10,10 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@wll8/process-manager": "^1.0.1", "@wll8/process-manager": "^1.0.1",
"form-data": "2.3.3", "form-data": "4.0.0",
"get-port": "5.1.1", "get-port": "5.1.1",
"mockm": "^1.1.27-alpha.2", "mockm": "^1.1.27-alpha.2",
"node-fetch": "^3.1.0" "node-fetch": "^3.2.10"
}, },
"bin": { "bin": {
"md-cli": "index.js" "md-cli": "index.js"
@ -1964,16 +1964,16 @@
} }
}, },
"node_modules/form-data": { "node_modules/form-data": {
"version": "2.3.3", "version": "4.0.0",
"resolved": "https://registry.npmmirror.com/form-data/-/form-data-2.3.3.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": { "dependencies": {
"asynckit": "^0.4.0", "asynckit": "^0.4.0",
"combined-stream": "^1.0.6", "combined-stream": "^1.0.8",
"mime-types": "^2.1.12" "mime-types": "^2.1.12"
}, },
"engines": { "engines": {
"node": ">= 0.12" "node": ">= 6"
} }
}, },
"node_modules/formdata-polyfill": { "node_modules/formdata-polyfill": {
@ -3238,9 +3238,9 @@
} }
}, },
"node_modules/node-fetch": { "node_modules/node-fetch": {
"version": "3.2.0", "version": "3.3.2",
"resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-3.2.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
"integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
"dependencies": { "dependencies": {
"data-uri-to-buffer": "^4.0.0", "data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4", "fetch-blob": "^3.1.4",
@ -3248,6 +3248,10 @@
}, },
"engines": { "engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
} }
}, },
"node_modules/node-http-proxy-json": { "node_modules/node-http-proxy-json": {
@ -3753,6 +3757,20 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/request/node_modules/form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
"optional": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 0.12"
}
},
"node_modules/request/node_modules/qs": { "node_modules/request/node_modules/qs": {
"version": "6.5.3", "version": "6.5.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz",
@ -6405,12 +6423,12 @@
"optional": true "optional": true
}, },
"form-data": { "form-data": {
"version": "2.3.3", "version": "4.0.0",
"resolved": "https://registry.npmmirror.com/form-data/-/form-data-2.3.3.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": { "requires": {
"asynckit": "^0.4.0", "asynckit": "^0.4.0",
"combined-stream": "^1.0.6", "combined-stream": "^1.0.8",
"mime-types": "^2.1.12" "mime-types": "^2.1.12"
} }
}, },
@ -7340,9 +7358,9 @@
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="
}, },
"node-fetch": { "node-fetch": {
"version": "3.2.0", "version": "3.3.2",
"resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-3.2.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
"integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
"requires": { "requires": {
"data-uri-to-buffer": "^4.0.0", "data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4", "fetch-blob": "^3.1.4",
@ -7726,6 +7744,17 @@
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },
"dependencies": { "dependencies": {
"form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
"optional": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
},
"qs": { "qs": {
"version": "6.5.3", "version": "6.5.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz",

View File

@ -21,9 +21,9 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@wll8/process-manager": "^1.0.1", "@wll8/process-manager": "^1.0.1",
"form-data": "2.3.3", "form-data": "4.0.0",
"get-port": "5.1.1", "get-port": "5.1.1",
"mockm": "^1.1.27-alpha.2", "mockm": "^1.1.27-alpha.2",
"node-fetch": "^3.1.0" "node-fetch": "^3.2.10"
} }
} }

View File

@ -1,8 +1,9 @@
{ {
"name": "md", "name": "md",
"version": "1.5.9", "version": "1.6.0",
"private": false, "private": false,
"scripts": { "scripts": {
"release": "node ./bin/release.js",
"prepare": "husky install", "prepare": "husky install",
"lint": "vue-cli-service lint src", "lint": "vue-cli-service lint src",
"start": "npm run lint -- --fix && run-p serve", "start": "npm run lint -- --fix && run-p serve",
@ -16,6 +17,7 @@
"axios": "^1.6.0", "axios": "^1.6.0",
"buffer-from": "^1.1.2", "buffer-from": "^1.1.2",
"codemirror": "^5.65.7", "codemirror": "^5.65.7",
"core-js": "^3.34.0",
"cos-js-sdk-v5": "^1.3.9", "cos-js-sdk-v5": "^1.3.9",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"element-ui": "^2.15.9", "element-ui": "^2.15.9",