Skip to content

Commit

Permalink
build: Add generate CHANGELOG & push to remote
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinerer committed Oct 15, 2024
1 parent d81498a commit 660ac23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Help.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pnpm changeset:version
pnpm changelog core cli
# 查看日志记录
pnpm changelog
pnpm changelog --commit=commitId # 从commitId记录开始
pnpm changelog core cli --push # 生成 CHANGELOG 后直接 push (忽略 step4,5)


# 4. 提交 commit
Expand Down
16 changes: 12 additions & 4 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function formatCommits(commits, filter = (commit) => commit) {
async function generateLogs(name, logs) {
const pkg = await readPackageJson(name)
const content = await readPackageFile(name)
const result = updateChangelog(content, pkg.version, logs[name])
const result = updateChangelog(content, pkg.version, logs[name.toLowerCase()])
await writePackageFile(name, result)

return result
Expand All @@ -80,15 +80,17 @@ async function generateLogs(name, logs) {
const moduleRegex = /^[a-z]{1,10}\(\w+\).*/i
try {
// const commits = await getCommitsSince('d9acb96')
const commits = await getCommitsSinceLatestTag()
const commitId = args.commit || args.C
const getCommitLogs = () => (commitId ? getCommitsSince(commitId) : getCommitsSinceLatestTag())
const commits = await getCommitLogs()
const formattedCommits = formatCommits(commits, (commit) => {
return moduleRegex.test(commit.message)
}).reduce((acc, commit) => {
if (!commit.package) throw new Error('No package found in commit message: ' + commit.message)
if (!acc[commit.package]) {
acc[commit.package] = []
}
acc[commit.package].push(
acc[commit.package.toLowerCase()].push(
`- ${commit.text} ([${commit.hash.slice(0, 7)}](https://github.com/Meqn/pipflow/commit/${
commit.hash
}))`
Expand All @@ -109,8 +111,14 @@ async function generateLogs(name, logs) {
for (const name of args._) {
await generateLogs(name, formattedCommits)
}

if (args.push) {
await git.add(['*/*/package.json', '*/*/CHANGELOG.md'])
await git.commit('Version Packages')
await git.push('origin', 'main')
}
}
} catch (err) {
console.error('error:', err.message)
console.error(err)
}
})()

0 comments on commit 660ac23

Please sign in to comment.