From 951c68179dcf415f58edf37932f328563ed800b3 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Mon, 12 Jun 2023 11:10:23 +0200 Subject: [PATCH] Merge pull request #23016 from storybookjs/release-dependencies-label Release: Fix release and changelog generation (cherry picked from commit b50a3b5345bf9d4503420673dbcbe166bf5b6d49) --- .../__tests__/generate-pr-description.test.ts | 4 ++-- scripts/release/generate-pr-description.ts | 17 ++++--------- scripts/release/unreleased-changes-exists.ts | 6 ++--- scripts/release/utils/get-changes.ts | 24 ++++++++++++++++--- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/scripts/release/__tests__/generate-pr-description.test.ts b/scripts/release/__tests__/generate-pr-description.test.ts index d4858a30c70a..b84c7a5d8dae 100644 --- a/scripts/release/__tests__/generate-pr-description.test.ts +++ b/scripts/release/__tests__/generate-pr-description.test.ts @@ -185,7 +185,7 @@ For each pull request below, you need to either manually cherry pick it, or disc And for each change below: 1. Ensure the change is appropriate for the version bump. E.g. patch release should only contain patches, not new or de-stabilizing features. If a change is not appropriate, revert the PR. - 2. Ensure the PR is labeled correctly with \\"BREAKING CHANGE\\", \\"feature request\\", \\"maintainance\\", \\"bug\\", \\"build\\" or \\"documentation\\". + 2. Ensure the PR is labeled correctly with one of: \\"BREAKING CHANGE\\", \\"feature request\\", \\"bug\\", \\"maintenance\\", \\"dependencies\\", \\"documentation\\", \\"build\\", \\"unknown\\". 3. Ensure the PR title is correct, and follows the format \\"[Area]: [Summary]\\", e.g. *\\"React: Fix hooks in CSF3 render functions\\"*. If it is not correct, change the title in the PR. - Areas include: React, Vue, Core, Docs, Controls, etc. - First word of summary indicates the type: “Add”, “Fix”, “Upgrade”, etc. @@ -305,7 +305,7 @@ For each pull request below, you need to either manually cherry pick it, or disc And for each change below: 1. Ensure the change is appropriate for the version bump. E.g. patch release should only contain patches, not new or de-stabilizing features. If a change is not appropriate, revert the PR. - 2. Ensure the PR is labeled correctly with \\"BREAKING CHANGE\\", \\"feature request\\", \\"maintainance\\", \\"bug\\", \\"build\\" or \\"documentation\\". + 2. Ensure the PR is labeled correctly with one of: \\"BREAKING CHANGE\\", \\"feature request\\", \\"bug\\", \\"maintenance\\", \\"dependencies\\", \\"documentation\\", \\"build\\", \\"unknown\\". 3. Ensure the PR title is correct, and follows the format \\"[Area]: [Summary]\\", e.g. *\\"React: Fix hooks in CSF3 render functions\\"*. If it is not correct, change the title in the PR. - Areas include: React, Vue, Core, Docs, Controls, etc. - First word of summary indicates the type: “Add”, “Fix”, “Upgrade”, etc. diff --git a/scripts/release/generate-pr-description.ts b/scripts/release/generate-pr-description.ts index 3bfe2af2292c..35654d9d601c 100644 --- a/scripts/release/generate-pr-description.ts +++ b/scripts/release/generate-pr-description.ts @@ -5,7 +5,7 @@ import { z } from 'zod'; import dedent from 'ts-dedent'; import { setOutput } from '@actions/core'; import type { Change } from './utils/get-changes'; -import { getChanges } from './utils/get-changes'; +import { getChanges, LABELS_BY_IMPORTANCE } from './utils/get-changes'; import { getCurrentVersion } from './get-current-version'; program @@ -43,17 +43,6 @@ type Options = { verbose: boolean; }; -const LABELS_BY_IMPORTANCE = { - 'BREAKING CHANGE': '❗ Breaking Change', - 'feature request': '✨ Feature Request', - bug: '🐛 Bug', - maintenance: '🔧 Maintenance', - dependencies: '📦 Dependencies', - documentation: '📝 Documentation', - build: '🏗️ Build', - unknown: '❔ Missing Label', -} as const; - const CHANGE_TITLES_TO_IGNORE = [ /^bump version.*/i, /^merge branch.*/i, @@ -167,7 +156,9 @@ export const generateReleaseDescription = ({ And for each change below: 1. Ensure the change is appropriate for the version bump. E.g. patch release should only contain patches, not new or de-stabilizing features. If a change is not appropriate, revert the PR. - 2. Ensure the PR is labeled correctly with "BREAKING CHANGE", "feature request", "maintainance", "bug", "build" or "documentation". + 2. Ensure the PR is labeled correctly with one of: ${Object.keys(LABELS_BY_IMPORTANCE) + .map((label) => `"${label}"`) + .join(', ')}. 3. Ensure the PR title is correct, and follows the format "[Area]: [Summary]", e.g. *"React: Fix hooks in CSF3 render functions"*. If it is not correct, change the title in the PR. - Areas include: React, Vue, Core, Docs, Controls, etc. - First word of summary indicates the type: “Add”, “Fix”, “Upgrade”, etc. diff --git a/scripts/release/unreleased-changes-exists.ts b/scripts/release/unreleased-changes-exists.ts index 8d8be843e833..c6ea25b80831 100644 --- a/scripts/release/unreleased-changes-exists.ts +++ b/scripts/release/unreleased-changes-exists.ts @@ -5,7 +5,7 @@ import { z } from 'zod'; import { setOutput } from '@actions/core'; import { intersection } from 'lodash'; import type { Change } from './utils/get-changes'; -import { getChanges } from './utils/get-changes'; +import { RELEASED_LABELS, getChanges } from './utils/get-changes'; import { getCurrentVersion } from './get-current-version'; program @@ -35,8 +35,6 @@ const validateOptions = (options: { [key: string]: any }): options is Options => return true; }; -const LABELS_TO_RELEASE = ['BREAKING CHANGE', 'feature request', 'bug', 'maintenance'] as const; - export const run = async ( options: unknown ): Promise<{ changesToRelease: Change[]; hasChangesToRelease: boolean }> => { @@ -59,7 +57,7 @@ export const run = async ( }); const changesToRelease = changes.filter( - ({ labels }) => intersection(LABELS_TO_RELEASE, labels).length > 0 + ({ labels }) => intersection(Object.keys(RELEASED_LABELS), labels).length > 0 ); const hasChangesToRelease = changesToRelease.length > 0; diff --git a/scripts/release/utils/get-changes.ts b/scripts/release/utils/get-changes.ts index 1108bb25559e..5a250bfd893c 100644 --- a/scripts/release/utils/get-changes.ts +++ b/scripts/release/utils/get-changes.ts @@ -6,7 +6,24 @@ import { getPullInfoFromCommit } from './get-github-info'; import { getUnpickedPRs } from './get-unpicked-prs'; import { git } from './git-client'; -const LABELS_FOR_CHANGELOG = ['BREAKING CHANGE', 'feature request', 'bug', 'maintenance']; +export const RELEASED_LABELS = { + 'BREAKING CHANGE': '❗ Breaking Change', + 'feature request': '✨ Feature Request', + bug: '🐛 Bug', + maintenance: '🔧 Maintenance', + dependencies: '📦 Dependencies', +} as const; + +export const UNRELEASED_LABELS = { + documentation: '📝 Documentation', + build: '🏗️ Build', + unknown: '❔ Missing Label', +} as const; + +export const LABELS_BY_IMPORTANCE = { + ...RELEASED_LABELS, + ...UNRELEASED_LABELS, +} as const; const getCommitAt = async (id: string, verbose?: boolean) => { if (!semver.valid(id)) { @@ -187,7 +204,7 @@ export const getChangelogText = ({ return false; } // only include PRs that with labels listed in LABELS_FOR_CHANGELOG - return entry.labels?.some((label) => LABELS_FOR_CHANGELOG.includes(label)); + return entry.labels?.some((label) => Object.keys(RELEASED_LABELS).includes(label)); }) .map((entry) => { const { title, links } = entry; @@ -195,7 +212,8 @@ export const getChangelogText = ({ return pull ? `- ${title} - ${pull}, thanks ${user}!` : `- ⚠️ _Direct commit_ ${title} - ${commit} by ${user}`; - }); + }) + .sort(); const text = [heading, '', ...formattedEntries].join('\n'); console.log(`✅ Generated Changelog:`);