Created
January 11, 2022 01:20
-
-
Save billju/c9e2258981c24794b8345044d916d509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { execSync } = require('child_process'); | |
// 讀取版號 | |
const package = JSON.parse(fs.readFileSync('package.json')); | |
let version = process.argv[2]; // 指令引數 | |
if (!version) { | |
// 自動增加版號 | |
version = parseInt(package.version.replace(/\./g, '')); | |
version = (version + 1).toString(); | |
version = '0'.repeat(Math.max(3 - version.length)) + version; | |
version = version.split('').join('.'); | |
} | |
// 開release分支 | |
execSync(`git branch release/v${version}`); | |
execSync(`git checkout release/v${version}`); | |
// 輸入自訂義版號 node scripts/git-release [version] | |
package.version = version; | |
fs.writeFileSync('package.json', JSON.stringify(package, '', '\t')); | |
// 讀取修改歷程 (%s提交訊息) | |
let logs = execSync('git log --pretty="* %s"').toString().split('\n'); | |
let endIndex = logs.findIndex((x) => x.match(/^\* release/)); | |
logs = logs.slice(0, endIndex).filter((x) => !x.match(/^\* Merge/)); | |
let message = [`release: ROE v${version}`, ...logs].join('" -m "'); | |
console.log(message); | |
// 提交訊息 | |
execSync(`git add .`); | |
execSync(`git commit -m "${message}""`); | |
// 合併分支 (--no-ff代表會建節點) | |
execSync(`git checkout develop`); | |
execSync(`git merge release/v${version} --no-ff"`); | |
execSync(`git checkout master`); | |
execSync(`git merge release/v${version} --no-ff"`); | |
execSync(`git tag -a v${version} -m ""`); | |
// 推送分支 | |
execSync(`git push origin develop`); | |
execSync(`git push origin master`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment