Skip to content

Commit

Permalink
Update the release notes generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty committed Dec 15, 2024
1 parent 867aeb0 commit 7d87c7e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/actions/draft-release/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = async ({ github, context, inputs }) => {
const tagName = `unreleased[${inputs.branchName}]`;
const tagName = `${inputs.branchName}-unreleased`;
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/pre-release/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = async ({ github, context, inputs }) => {
const draftTagName = `unreleased[${inputs.branchName}]`;
const draftTagName = `${inputs.branchName}-unreleased`;

const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
Expand Down
52 changes: 48 additions & 4 deletions .github/actions/release/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,6 +64,7 @@ module.exports = async ({ github, context, inputs }) => {
tag_name: inputs.tagName,
draft: false,
prerelease: false,
body: notes.body,
});

// Cleanup beta releases
Expand All @@ -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}`);
Expand Down

0 comments on commit 7d87c7e

Please sign in to comment.