ci(scripts): create draft release with release script, cleanup [skip ci]
This commit is contained in:
37
scripts/utils/createDraftGitHubRelease.ts
Normal file
37
scripts/utils/createDraftGitHubRelease.ts
Normal 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 }
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user