ci(scripts): create draft release with release script, cleanup [skip ci]

This commit is contained in:
Elliot DeNolf
2025-01-03 09:00:01 -05:00
parent 766b67f0be
commit 6dcf817c22
3 changed files with 87 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
type Args = {
branch: string
tag: string
releaseNotes: string
}
export const createDraftGitHubRelease = async ({
branch,
tag,
releaseNotes,
}: Args): Promise<{ releaseUrl: string }> => {
// https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
const res = await fetch(`https://api.github.com/repos/payloadcms/payload/releases`, {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${process.env.GITHUB_TOKEN}`,
},
method: 'POST',
body: JSON.stringify({
tag_name: tag,
target_commitish: branch,
name: tag,
body: releaseNotes,
draft: true,
prerelease: false,
generate_release_notes: false,
}),
})
if (!res.ok) {
throw new Error(`Failed to create release: ${await res.text()}`)
}
const resBody = await res.json()
return { releaseUrl: resBody.html_url }
}

View File

@@ -30,6 +30,10 @@ type ChangelogResult = {
* The release notes, includes contributors. This is the content used for the releaseUrl
*/
releaseNotes: string
/**
* The release tag, includes prefix 'v'
*/
releaseTag: string
}
export const generateReleaseNotes = async (args: Args = {}): Promise<ChangelogResult> => {
@@ -49,6 +53,10 @@ export const generateReleaseNotes = async (args: Args = {}): Promise<ChangelogRe
const calculatedBump = bump || recommendedBump
if (!calculatedBump) {
throw new Error('Could not determine bump type')
}
const proposedReleaseVersion = 'v' + semver.inc(fromVersion, calculatedBump, undefined, tag)
console.log(`Generating release notes for ${fromVersion} to ${toVersion}...`)
@@ -155,6 +163,7 @@ export const generateReleaseNotes = async (args: Args = {}): Promise<ChangelogRe
releaseUrl,
changelog,
releaseNotes,
releaseTag: proposedReleaseVersion,
}
}
@@ -216,7 +225,7 @@ async function getContributors(commits: GitCommit[]): Promise<Contributor[]> {
const coAuthors = Array.from(
commit.body.matchAll(coAuthorPattern),
(match) => match.groups,
).filter((e) => !e.email.includes('[bot]'))
).filter((e) => !e?.email.includes('[bot]')) as { name: string; email: string }[]
if (!coAuthors.length) {
continue