ci: Use @aklinker1/zero-changelog for release notes (#2515)
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
import {
|
||||
determineSemverChange,
|
||||
generateMarkDown,
|
||||
loadChangelogConfig,
|
||||
parseChangelogMarkdown,
|
||||
parseCommits,
|
||||
} from 'changelogen';
|
||||
import { consola } from 'consola';
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { getPkgTag, grabPackageDetails, listCommitsInDir } from './git';
|
||||
|
||||
const pkg = process.argv[2];
|
||||
if (!pkg) {
|
||||
throw Error(
|
||||
'Package name missing. Usage: bun run scripts/bump-package-version.ts <package-name>',
|
||||
);
|
||||
}
|
||||
const { pkgDir, pkgName, currentVersion, prevTag, changelogPath, pkgJsonPath } =
|
||||
await grabPackageDetails(pkg);
|
||||
consola.info('Bumping:', { pkg, pkgDir, pkgName, currentVersion });
|
||||
|
||||
// Get commits
|
||||
const config = await loadChangelogConfig(process.cwd());
|
||||
consola.info('Config:', config);
|
||||
const additionalDirs = pkg === 'wxt' ? ['docs'] : [];
|
||||
const rawCommits = await listCommitsInDir(pkgDir, prevTag, additionalDirs);
|
||||
const commits = parseCommits(rawCommits, config);
|
||||
|
||||
// Bump version
|
||||
const originalBumpType = determineSemverChange(commits, config) ?? 'patch';
|
||||
let bumpType = originalBumpType;
|
||||
if (currentVersion.startsWith('0.')) {
|
||||
if (bumpType === 'major') {
|
||||
bumpType = 'minor';
|
||||
} else if (bumpType === 'minor') {
|
||||
bumpType = 'patch';
|
||||
}
|
||||
}
|
||||
await Bun.$`bun pm version ${bumpType}`.cwd(pkgDir);
|
||||
const updatedPkgJson = await Bun.file(pkgJsonPath).json();
|
||||
const newVersion: string = updatedPkgJson.version;
|
||||
const newTag = getPkgTag(pkg, newVersion);
|
||||
consola.info('Bump:', { currentVersion, bumpType, newVersion });
|
||||
|
||||
// Generate changelog
|
||||
const versionChangelog = await generateMarkDown(commits, {
|
||||
...config,
|
||||
from: prevTag,
|
||||
to: newTag,
|
||||
});
|
||||
let versionChangelogBody = versionChangelog
|
||||
.split('\n')
|
||||
.slice(1)
|
||||
.join('\n')
|
||||
.trim();
|
||||
if (originalBumpType === 'major') {
|
||||
versionChangelogBody = versionChangelogBody.replace(
|
||||
'[compare changes]',
|
||||
`[⚠️ breaking changes](https://wxt.dev/guide/resources/upgrading.html) • [compare changes]`,
|
||||
);
|
||||
}
|
||||
const { releases: prevReleases } = await Bun.file(changelogPath)
|
||||
.text()
|
||||
.then(parseChangelogMarkdown)
|
||||
.catch(() => ({ releases: [] }));
|
||||
const allReleases = [
|
||||
{
|
||||
version: newVersion,
|
||||
body: versionChangelogBody,
|
||||
},
|
||||
...prevReleases,
|
||||
];
|
||||
|
||||
const newChangelog =
|
||||
'# Changelog\n\n' +
|
||||
allReleases
|
||||
.map((release) => [`## v${release.version}`, release.body].join('\n\n'))
|
||||
.join('\n\n');
|
||||
await Bun.write(changelogPath, newChangelog);
|
||||
consola.success('Updated changelog');
|
||||
|
||||
// Update WXT version in templates when releasing wxt package
|
||||
const templatePkgJsonPaths: string[] = [];
|
||||
if (pkg === 'wxt') {
|
||||
const templatesDir = 'templates';
|
||||
const templateDirs = await readdir(templatesDir);
|
||||
for (const templateDir of templateDirs) {
|
||||
const templatePkgJsonPath = join(templatesDir, templateDir, 'package.json');
|
||||
const templatePkgJsonFile = Bun.file(templatePkgJsonPath);
|
||||
if (await templatePkgJsonFile.exists()) {
|
||||
const templatePkgJson = await templatePkgJsonFile.json();
|
||||
if (templatePkgJson.devDependencies?.wxt) {
|
||||
templatePkgJson.devDependencies.wxt = `^${newVersion}`;
|
||||
await templatePkgJsonFile.write(
|
||||
JSON.stringify(templatePkgJson, null, 2),
|
||||
);
|
||||
templatePkgJsonPaths.push(templatePkgJsonPath);
|
||||
consola.success(`Updated wxt version in ${templatePkgJsonPath}`);
|
||||
}
|
||||
} else {
|
||||
console.warn(`No package.json found in ${templatePkgJsonPath}`, {
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run a bun install to update the lockfile after the version change
|
||||
await Bun.$`bun install --ignore-scripts`;
|
||||
|
||||
// Commit changes
|
||||
await Bun.$`git add "${pkgJsonPath}" "${changelogPath}" bun.lock`;
|
||||
for (const packageJsonPath of templatePkgJsonPaths) {
|
||||
await Bun.$`git add "${packageJsonPath}"`;
|
||||
}
|
||||
await Bun.$`git commit -m "chore(release): ${pkgName} v${newVersion}"`;
|
||||
await Bun.$`git tag ${newTag}`;
|
||||
consola.success('Committed version and changelog');
|
||||
@@ -1,34 +0,0 @@
|
||||
import {
|
||||
createGithubRelease,
|
||||
GithubRelease,
|
||||
loadChangelogConfig,
|
||||
parseChangelogMarkdown,
|
||||
} from 'changelogen';
|
||||
import { grabPackageDetails } from './git';
|
||||
import consola from 'consola';
|
||||
|
||||
const pkg = process.argv[2];
|
||||
if (!pkg) {
|
||||
throw Error(
|
||||
'Package name missing. Usage: bun run scripts/create-github-release.ts <package-name>',
|
||||
);
|
||||
}
|
||||
|
||||
const { pkgName, prevTag, currentVersion, changelogPath } =
|
||||
await grabPackageDetails(pkg);
|
||||
consola.info('Creating release for:', { pkg, pkgName, prevTag });
|
||||
|
||||
const { releases } = await Bun.file(changelogPath)
|
||||
.text()
|
||||
.then(parseChangelogMarkdown)
|
||||
.catch(() => ({ releases: [] }));
|
||||
|
||||
const config = await loadChangelogConfig(process.cwd());
|
||||
config.tokens.github = process.env.GITHUB_TOKEN;
|
||||
await createGithubRelease(config, {
|
||||
tag_name: prevTag,
|
||||
name: `${pkgName} v${currentVersion}`,
|
||||
body: releases[0].body,
|
||||
make_latest: String(pkg === 'wxt'),
|
||||
} as GithubRelease & { make_latest: string });
|
||||
consola.success('Created release');
|
||||
@@ -1,42 +0,0 @@
|
||||
import { RawGitCommit, getGitDiff } from 'changelogen';
|
||||
import { consola } from 'consola';
|
||||
|
||||
export async function grabPackageDetails(pkg: string) {
|
||||
const pkgDir = `packages/${pkg}`;
|
||||
const pkgJsonPath = `${pkgDir}/package.json`;
|
||||
const pkgJson = await Bun.file(pkgJsonPath).json();
|
||||
const currentVersion: string = pkgJson.version;
|
||||
return {
|
||||
pkgDir,
|
||||
pkgJsonPath,
|
||||
changelogPath: `${pkgDir}/CHANGELOG.md`,
|
||||
pkgJson,
|
||||
pkgName: pkgJson.name,
|
||||
currentVersion,
|
||||
prevTag: getPkgTag(pkg, currentVersion),
|
||||
};
|
||||
}
|
||||
|
||||
export function getPkgTag(pkg: string, version: string | undefined) {
|
||||
return `${pkg}-v${version}`;
|
||||
}
|
||||
|
||||
export async function listCommitsInDir(
|
||||
dir: string,
|
||||
lastTag: string,
|
||||
additionalDirs: string[] = [],
|
||||
): Promise<RawGitCommit[]> {
|
||||
const allDirs = [dir, ...additionalDirs];
|
||||
consola.info('Listing commits:', { lastTag, dirs: allDirs });
|
||||
const commits = await getGitDiff(lastTag);
|
||||
consola.info('All commits:', commits.length);
|
||||
consola.debug(commits);
|
||||
// commit.body contains all the files that were modified/added. So just check to make sure "\t" + "packages/storage" + "/" is in the body to include
|
||||
// '"\n\nM\tpackages/wxt/vitest.config.ts\n"'
|
||||
const filtered = commits.filter((commit) =>
|
||||
allDirs.some((dir) => commit.body.includes(`\t${dir}/`)),
|
||||
);
|
||||
consola.info('Filtered:', filtered.length);
|
||||
consola.debug(filtered);
|
||||
return filtered;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import {
|
||||
getGithubReleaseByTag,
|
||||
loadChangelogConfig,
|
||||
parseChangelogMarkdown,
|
||||
updateGithubRelease,
|
||||
} from 'changelogen';
|
||||
import { getPkgTag, grabPackageDetails } from './git';
|
||||
import consola from 'consola';
|
||||
|
||||
const pkg = process.argv[2];
|
||||
if (!pkg) {
|
||||
throw Error(
|
||||
'Package name missing. Usage: bun run scripts/sync-releases.ts <package-name>',
|
||||
);
|
||||
}
|
||||
|
||||
// Update
|
||||
const { changelogPath, pkgName } = await grabPackageDetails(pkg);
|
||||
const { releases } = await Bun.file(changelogPath)
|
||||
.text()
|
||||
.then(parseChangelogMarkdown)
|
||||
.catch(() => ({ releases: [] }));
|
||||
const config = await loadChangelogConfig(process.cwd());
|
||||
config.tokens.github = process.env.GITHUB_TOKEN;
|
||||
|
||||
// Update releases
|
||||
for (const release of releases) {
|
||||
const tag = getPkgTag(pkg, release.version);
|
||||
try {
|
||||
const existing = await getGithubReleaseByTag(config, tag);
|
||||
if (existing.body !== release.body) {
|
||||
await updateGithubRelease(config, existing.id!, {
|
||||
tag_name: tag,
|
||||
name: `${pkgName} v${release.version}`,
|
||||
body: release.body,
|
||||
});
|
||||
}
|
||||
consola.success(`Synced \`${tag}\``);
|
||||
} catch (err) {
|
||||
consola.fail(`\`${tag}\``, err);
|
||||
}
|
||||
}
|
||||
consola.success('Done');
|
||||
Reference in New Issue
Block a user