From d06bf1073328373ec3bf81bbba12a85c88c6b6d0 Mon Sep 17 00:00:00 2001 From: cvetty Date: Sun, 15 Dec 2024 14:51:44 +0200 Subject: [PATCH] Update the release notes generation --- .github/actions/release/script.js | 52 ++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/.github/actions/release/script.js b/.github/actions/release/script.js index a189259..c8f8c84 100644 --- a/.github/actions/release/script.js +++ b/.github/actions/release/script.js @@ -8,6 +8,53 @@ module.exports = async ({ github, context, inputs }) => { release_id: inputs.releaseId, }); + // Get the commit SHA that the release is pointing to + const { data: commit } = await github.rest.repos.getCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: release.target_commitish, + }); + + // Create the new tag + console.log("Creating release tag..."); + try { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${inputs.tagName}`, + sha: commit.sha, + }); + } catch (error) { + // If the tag already exists, we can continue + if (error.status !== 422) { + throw error; + } + console.log(`Tag ${inputs.tagName} already exists`); + } + + console.log("Getting the latest tag"); + const { data: tags } = await github.rest.repos.listTags({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + const latestTag = tags.find( + (tag) => + tag.name.startsWith(`${majorVersion}.`) && !tag.name.includes("-beta"), + ); + if (latestTag) { + console.log(`Found latest tag: ${latestTag.name}`); + } else { + console.log(`No matching tags found for major version ${majorVersion}`); + } + + const { data: notes } = await github.rest.repos.generateReleaseNotes({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: tagName, + target_commitish: inputs.branchName, + previous_tag_name: latestTag?.name, + }); + console.log("Updating release tag..."); await github.rest.repos.updateRelease({ owner: context.repo.owner, @@ -17,6 +64,7 @@ module.exports = async ({ github, context, inputs }) => { tag_name: inputs.tagName, draft: false, prerelease: false, + body: notes.body, }); // Cleanup beta releases @@ -42,10 +90,6 @@ module.exports = async ({ github, context, inputs }) => { // Cleanup beta tags console.log("Cleaning up beta tags..."); - const { data: tags } = await github.rest.repos.listTags({ - owner: context.repo.owner, - repo: context.repo.repo, - }); for (const tag of tags) { if (tag.name.startsWith(`${majorVersion}.`) && tag.name.includes("-beta")) { console.log(`Deleting beta tag: ${tag.name}`);