Skip to content

chore(ci): generate a pretty changelog for the release #4078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions scripts/ci/codegen/createGitHubReleases.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fsp from 'fs/promises';
import { ensureGitHubToken, getOctokit, OWNER, run, setVerbose, toAbsolutePath } from '../../common.js';
import { isPreRelease } from '../../release/versionsHistory.js';
import type { Language } from '../../types.js';
import { cloneRepository } from '../utils.js';

import { resolve } from 'path';
import { commitStartRelease } from './text.js';

async function createGitHubRelease(lang: Language): Promise<void> {
Expand Down Expand Up @@ -38,14 +40,27 @@ async function createGitHubRelease(lang: Language): Promise<void> {
previousVersion = tags[tags.length - 1];
}

// extract the changelog from CHANGELOG.md, until the first ## to the second ##
const fullChangelog = (await fsp.readFile(resolve(tempGitDir, 'CHANGELOG.md')))
.toString()
.matchAll(/^##.*?\n(.*?)##/gms);
if (!fullChangelog) {
throw new Error('unable to find changelog');
}

const changelog = [...fullChangelog][0][1].trim().replaceAll(/- \[/g, '* [');

const repository = `algoliasearch-client-${lang}`;
const repositoryLink = `https://github.com/${OWNER}/${repository}`;
const content = `
New ${isMajor ? '**major** ' : ''}version released!
# New ${isMajor ? '**major** ' : ''}version released!
## What's Changed
${changelog}

**Full Changelog**: ${repositoryLink}/compare/${previousVersion}...${newVersion}

→ [Browse the Algolia documentation](https://www.algolia.com/doc/libraries/${lang})
→ [Browse the changelog](${repositoryLink}/blob/main/CHANGELOG.md)
→ [Browse the commits](${repositoryLink}/compare/${previousVersion}...${newVersion})`;
`;

try {
await getOctokit().repos.createRelease({
Expand Down
Loading