Skip to content

Commit

Permalink
chore(cdk-release): alpha package changes aren't written to alpha CHA…
Browse files Browse the repository at this point in the history
…NGELOG (#25836)

The reason is that the packages that have the changes in them are now called `@aws-cdk/aws-XXX-alpha`, but changes are usually stated as `feat(XXX): ...`.

The code generating name variants to catch the possible values of `XXX` was not taking the `-alhpa` suffix into account. Now is.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Jun 2, 2023
1 parent 502c375 commit 2bcd7f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
43 changes: 19 additions & 24 deletions tools/@aws-cdk/cdk-release/lib/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,24 @@ export function filterCommits(commits: ConventionalCommit[], opts: FilterCommits
.filter(commit => excludeScopes.length === 0 || !commit.scope || !excludeScopes.includes(commit.scope));
}

function createScopeVariations(names: string[]) {
const simplifiedNames = names.map(n => n.replace(/^@aws-cdk\//, ''));

return flatMap(simplifiedNames, (pkgName) => [
pkgName,
...(pkgName.startsWith('aws-')
? [
// if the package name starts with 'aws', like 'aws-s3',
// also include in the scopes variants without the prefix,
// and without the '-' in the prefix
// (so, 's3' and 'awss3')
pkgName.slice('aws-'.length),
pkgName.replace(/^aws-/, 'aws'),
]
: []
),
]);
}

function flatMap<T, U>(xs: T[], fn: (x: T) => U[]): U[] {
const ret = new Array<U>();
for (const x of xs) {
ret.push(...fn(x));
export function createScopeVariations(names: string[]) {
const simplifiedNames = new Set(names.map(n => n.replace(/^@aws-cdk\//, '')));

// if the package name starts with 'aws', like 'aws-s3',
// also include in the scopes variants without the prefix,
// and without the '-' in the prefix
// (so, 's3' and 'awss3')
const transforms: Array<(x: string) => string> = [
(name) => name.replace(/^aws-/, ''),
(name) => name.replace(/^aws-/, 'aws'),
(name) => name.replace(/-alpha$/, ''),
];

for (const transform of transforms) {
for (const name of simplifiedNames) {
simplifiedNames.add(transform(name));
}
}
return ret;

return Array.from(simplifiedNames);
}
6 changes: 5 additions & 1 deletion tools/@aws-cdk/cdk-release/test/conventional-commits.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from 'crypto';
import * as stream from 'stream';
import { ConventionalCommit, filterCommits, getConventionalCommitsFromGitHistory } from '../lib/conventional-commits';
import { ConventionalCommit, createScopeVariations, filterCommits, getConventionalCommitsFromGitHistory } from '../lib/conventional-commits';
import { ReleaseOptions } from '../lib/types';

// mock out Git interactions
Expand Down Expand Up @@ -104,6 +104,10 @@ describe('filterCommits', () => {
expect(filteredCommits.length).toEqual(1);
expect(filteredCommits[0].scope).toEqual('aws-stable');
});

test('scope variants take alpha packages into account', () => {
expect(createScopeVariations(['@aws-cdk/aws-batch-alpha'])).toContain('batch');
});
});

function mockGitCommits(messages: string[]) {
Expand Down

0 comments on commit 2bcd7f2

Please sign in to comment.