mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 13:15:12 +00:00
chore: improve accuracy of 4.x changelog (#28706)
This commit is contained in:
parent
cfd9bf61f2
commit
8fa5883ac8
@ -1,7 +1,7 @@
|
|||||||
import { execSync } from 'node:child_process'
|
|
||||||
import { promises as fsp } from 'node:fs'
|
import { promises as fsp } from 'node:fs'
|
||||||
import { $fetch } from 'ofetch'
|
import { $fetch } from 'ofetch'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
|
import { compare } from 'semver'
|
||||||
import { glob } from 'tinyglobby'
|
import { glob } from 'tinyglobby'
|
||||||
import { exec } from 'tinyexec'
|
import { exec } from 'tinyexec'
|
||||||
import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen'
|
import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen'
|
||||||
@ -106,17 +106,35 @@ export async function determineBumpType () {
|
|||||||
return determineSemverChange(commits, config)
|
return determineSemverChange(commits, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getLatestTag () {
|
||||||
|
const { stdout: latestTag } = await exec('git', ['describe', '--tags', '--abbrev=0'])
|
||||||
|
return latestTag.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLatestReleasedTag () {
|
||||||
|
const latestReleasedTag = await exec('git', ['tag', '-l']).then(r => r.stdout.trim().split('\n').filter(t => /v3\.\d+\.\d+/.test(t)).sort(compare)).then(r => r.pop()!.trim())
|
||||||
|
return latestReleasedTag
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPreviousReleasedCommits () {
|
||||||
|
const config = await loadChangelogConfig(process.cwd())
|
||||||
|
const latestTag = await getLatestTag()
|
||||||
|
const latestReleasedTag = await getLatestReleasedTag()
|
||||||
|
const commits = parseCommits(await getGitDiff(latestTag, latestReleasedTag), config)
|
||||||
|
return commits
|
||||||
|
}
|
||||||
|
|
||||||
export async function getLatestCommits () {
|
export async function getLatestCommits () {
|
||||||
const config = await loadChangelogConfig(process.cwd())
|
const config = await loadChangelogConfig(process.cwd())
|
||||||
const { stdout: latestTag } = await exec('git', ['describe', '--tags', '--abbrev=0'])
|
const latestTag = await getLatestTag()
|
||||||
|
|
||||||
return parseCommits(await getGitDiff(latestTag.trim()), config)
|
return parseCommits(await getGitDiff(latestTag), config)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getContributors () {
|
export async function getContributors () {
|
||||||
const contributors = [] as Array<{ name: string, username: string }>
|
const contributors = [] as Array<{ name: string, username: string }>
|
||||||
const emails = new Set<string>()
|
const emails = new Set<string>()
|
||||||
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim()
|
const latestTag = await getLatestTag()
|
||||||
const rawCommits = await getGitDiff(latestTag)
|
const rawCommits = await getGitDiff(latestTag)
|
||||||
for (const commit of rawCommits) {
|
for (const commit of rawCommits) {
|
||||||
if (emails.has(commit.author.email) || commit.author.name === 'renovate[bot]') { continue }
|
if (emails.has(commit.author.email) || commit.author.name === 'renovate[bot]') { continue }
|
||||||
|
@ -3,15 +3,19 @@ import { $fetch } from 'ofetch'
|
|||||||
import { inc } from 'semver'
|
import { inc } from 'semver'
|
||||||
import { generateMarkDown, getCurrentGitBranch, loadChangelogConfig } from 'changelogen'
|
import { generateMarkDown, getCurrentGitBranch, loadChangelogConfig } from 'changelogen'
|
||||||
import { consola } from 'consola'
|
import { consola } from 'consola'
|
||||||
import { determineBumpType, getContributors, getLatestCommits, loadWorkspace } from './_utils'
|
import { determineBumpType, getContributors, getLatestCommits, getLatestReleasedTag, getLatestTag, getPreviousReleasedCommits, loadWorkspace } from './_utils'
|
||||||
|
|
||||||
|
const handleSeparateBranch = true
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
const releaseBranch = await getCurrentGitBranch()
|
const releaseBranch = await getCurrentGitBranch()
|
||||||
const workspace = await loadWorkspace(process.cwd())
|
const workspace = await loadWorkspace(process.cwd())
|
||||||
const config = await loadChangelogConfig(process.cwd(), {})
|
const config = await loadChangelogConfig(process.cwd(), {})
|
||||||
|
|
||||||
|
const prevMessages = new Set(handleSeparateBranch ? await getPreviousReleasedCommits().then(r => r.map(c => c.message)) : [])
|
||||||
|
|
||||||
const commits = await getLatestCommits().then(commits => commits.filter(
|
const commits = await getLatestCommits().then(commits => commits.filter(
|
||||||
c => config.types[c.type] && !(c.type === 'chore' && c.scope === 'deps'),
|
c => config.types[c.type] && !(c.type === 'chore' && c.scope === 'deps') && !prevMessages.has(c.message),
|
||||||
))
|
))
|
||||||
const bumpType = await determineBumpType() || 'patch'
|
const bumpType = await determineBumpType() || 'patch'
|
||||||
|
|
||||||
@ -38,6 +42,9 @@ async function main () {
|
|||||||
const [currentPR] = await $fetch(`https://api.github.com/repos/nuxt/nuxt/pulls?head=nuxt:v${newVersion}`)
|
const [currentPR] = await $fetch(`https://api.github.com/repos/nuxt/nuxt/pulls?head=nuxt:v${newVersion}`)
|
||||||
const contributors = await getContributors()
|
const contributors = await getContributors()
|
||||||
|
|
||||||
|
const latestTag = await getLatestTag()
|
||||||
|
const previousReleasedTag = handleSeparateBranch ? await getLatestReleasedTag() : latestTag
|
||||||
|
|
||||||
const releaseNotes = [
|
const releaseNotes = [
|
||||||
currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`,
|
currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`,
|
||||||
'## 👉 Changelog',
|
'## 👉 Changelog',
|
||||||
@ -45,7 +52,8 @@ async function main () {
|
|||||||
.replace(/^## v.*\n/, '')
|
.replace(/^## v.*\n/, '')
|
||||||
.replace(`...${releaseBranch}`, `...v${newVersion}`)
|
.replace(`...${releaseBranch}`, `...v${newVersion}`)
|
||||||
.replace(/### ❤️ Contributors[\s\S]*$/, '')
|
.replace(/### ❤️ Contributors[\s\S]*$/, '')
|
||||||
.replace(/[\n\r]+/g, '\n'),
|
.replace(/[\n\r]+/g, '\n')
|
||||||
|
.replace(latestTag, previousReleasedTag),
|
||||||
'### ❤️ Contributors',
|
'### ❤️ Contributors',
|
||||||
contributors.map(c => `- ${c.name} (@${c.username})`).join('\n'),
|
contributors.map(c => `- ${c.name} (@${c.username})`).join('\n'),
|
||||||
].join('\n')
|
].join('\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user