From 8b2626e16db150a19a3ad21ba50069d25ba9c8ef Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Fri, 23 Feb 2024 02:36:24 -0800 Subject: [PATCH] chore: add changelog generation in release mode. --- release/core/publish/index.ts | 37 +++++++++++++------ .../release-notes/steps/confirm-changelogs.ts | 1 - release/utils/flags-config.ts | 6 +-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/release/core/publish/index.ts b/release/core/publish/index.ts index 70bcd7347e0..38590a605cd 100644 --- a/release/core/publish/index.ts +++ b/release/core/publish/index.ts @@ -1,14 +1,18 @@ import { publish_flags_config } from '../../utils/flags-config'; import { parseRawFlags } from '../../utils/parse-args'; -import { getGitState } from '../../utils/git'; +import { GIT_TAG, getAllPackagesForGitTag, getGitState } from '../../utils/git'; import { printHelpDocs } from '../../help/docs'; import { bumpAllPackages, restorePackagesForDryRun } from './steps/bump-versions'; import { generatePackageTarballs } from './steps/generate-tarballs'; import { printStrategy } from './steps/print-strategy'; -import { applyStrategy } from './steps/generate-strategy'; +import { AppliedStrategy, applyStrategy } from './steps/generate-strategy'; import { confirmStrategy } from './steps/confirm-strategy'; import { publishPackages } from './steps/publish-packages'; import { gatherPackages, loadStrategy } from '../../utils/package'; +import { CHANNEL, SEMVER_VERSION } from '../../utils/channel'; +import { confirmCommitChangelogs } from '../release-notes/steps/confirm-changelogs'; +import { updateChangelogs } from '../release-notes/steps/update-changelogs'; +import { getChanges } from '../release-notes/steps/get-changes'; export async function executePublish(args: string[]) { // get user supplied config @@ -26,25 +30,34 @@ export async function executePublish(args: string[]) { // get configured strategy const strategy = await loadStrategy(); - // get packages + // get packages present on our current branch const packages = await gatherPackages(strategy.config); + // get packages present in the git tag version + const fromVersion = config.full.get('from') as SEMVER_VERSION | undefined; + const fromTag = `v${fromVersion}` as GIT_TAG; + const baseVersionPackages = fromVersion ? await getAllPackagesForGitTag(fromTag) : packages; + // get applied strategy - const applied = await applyStrategy(config.full, strategy, packages); + const applied = await applyStrategy(config.full, strategy, baseVersionPackages, packages); // print strategy to be applied await printStrategy(config.full, applied); await confirmStrategy(); - // TODO: Generate Release Notes / PR flow? - // Ideally we do per-package changelogs + a root changelog thats rolls up - // those changes into one set of release notes. - // this step probably would create an artifact like .changelog.json - // and open a PR, and then early exit. Then if the script is run again - // it would check if the PR is merged and if so it would continue. - // await generateReleaseNotes(config, packages, applied.public_pks); - // await confirmReleaseNotesMerged(); + const channel = config.full.get('channel') as CHANNEL; + if (channel !== 'canary' && channel !== 'beta') { + // generate the list of changes + const newChanges = await getChanges(strategy, packages, fromTag); + + // update all changelogs, including the primary changelog + // and the changelogs for each package in changelogRoots + // this will not commit the changes + const changedFiles = await updateChangelogs(fromTag, newChanges, config.full, strategy, packages, applied); + + await confirmCommitChangelogs(changedFiles, config.full, applied); + } // Bump package.json versions & commit/tag // ======================== diff --git a/release/core/release-notes/steps/confirm-changelogs.ts b/release/core/release-notes/steps/confirm-changelogs.ts index 1c9c3a88683..d806a35e855 100644 --- a/release/core/release-notes/steps/confirm-changelogs.ts +++ b/release/core/release-notes/steps/confirm-changelogs.ts @@ -1,7 +1,6 @@ import { BunFile } from 'bun'; import { confirm } from '../../publish/steps/confirm-strategy'; import { exec } from '../../../utils/cmd'; -import { SEMVER_VERSION } from '../../../utils/channel'; import chalk from 'chalk'; import { AppliedStrategy } from '../../publish/steps/generate-strategy'; diff --git a/release/utils/flags-config.ts b/release/utils/flags-config.ts index f27693a1b36..0c3eb371dc6 100644 --- a/release/utils/flags-config.ts +++ b/release/utils/flags-config.ts @@ -152,11 +152,11 @@ export const publish_flags_config: FlagConfig = { } }, }, - commit_changelog: { + commit: { name: 'Commit', - flag: 'commit_changelog', + flag: 'commit', flag_aliases: ['c'], - flag_mispellings: ['cm', 'comit', 'changelog'], + flag_mispellings: ['cm', 'comit', 'changelog', 'commit_changelog'], description: 'Whether to commit the changes to the changelogs', type: Boolean, examples: [],