Skip to content

Commit

Permalink
feat(xo-lite): add changelog to gh release description
Browse files Browse the repository at this point in the history
  • Loading branch information
CzechSebastian committed Jan 24, 2025
1 parent 9af5818 commit 03c16e5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions @xen-orchestra/lite/scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ const ghApiUploadReleaseAsset = async (releaseId, assetName, file) => {
return JSON.parse(await res.text())
}

const getChangelogForVersion = async (version, changelogPath = './CHANGELOG.md') => {
const changelog = await fs.readFile(changelogPath, 'utf8')
const escapeRegex = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const escapedVersion = escapeRegex(version)

const versionRegex = new RegExp(`## \\*\\*${escapedVersion}\\*\\*.*?(?=\\n## \\*\\*|$)`, 's')

const match = changelog.match(versionRegex)
return match ? match[0].trim() : null
}

// Validate args and assign defaults -------------------------------------------

const headSha = (await $`git rev-parse HEAD`).stdout.trim()
Expand Down Expand Up @@ -330,7 +341,13 @@ if (ghRelease) {
step('GitHub release')

let release = (await ghApiCall('/releases')).find(release => release.tag_name === tag)
const releaseNotes = await getChangelogForVersion(version)

if (!releaseNotes) {
if (await no(`No changelog found for version ${version}. There might be a problem with the version number.`)) {
stop()
}
}
if (release !== undefined) {
if (
await no(
Expand All @@ -347,6 +364,7 @@ if (ghRelease) {
target_commitish: headSha,
name: tag,
draft: true,
body: releaseNotes,
})

console.log(`Created GitHub release ${tag}: ${chalk.blue(release.html_url)}`)
Expand Down

0 comments on commit 03c16e5

Please sign in to comment.