Skip to content

Commit

Permalink
Merge pull request #23016 from storybookjs/release-dependencies-label
Browse files Browse the repository at this point in the history
Release: Fix release and changelog generation
(cherry picked from commit b50a3b5)
  • Loading branch information
JReinhold authored and github-actions[bot] committed Jun 14, 2023
1 parent 2558126 commit 221fb4b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions scripts/release/__tests__/generate-pr-description.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 4 additions & 13 deletions scripts/release/generate-pr-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions scripts/release/unreleased-changes-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }> => {
Expand All @@ -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;
Expand Down
24 changes: 21 additions & 3 deletions scripts/release/utils/get-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -187,15 +204,16 @@ 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;
const { pull, commit, user } = links;
return pull
? `- ${title} - ${pull}, thanks ${user}!`
: `- ⚠️ _Direct commit_ ${title} - ${commit} by ${user}`;
});
})
.sort();
const text = [heading, '', ...formattedEntries].join('\n');

console.log(`✅ Generated Changelog:`);
Expand Down

0 comments on commit 221fb4b

Please sign in to comment.