Skip to content

Commit

Permalink
chore(cdk-release): do not get commits if Changelog generation is ski…
Browse files Browse the repository at this point in the history
…pped (#15467)

Our build in the Pipeline bump the version to a prerelease one before running the integ tests.
We recently switched to using the `cdk-release` tool,
and it always fetches the Git history when doing the bump.
But that's a problem, as our Pipeline build does not run in a Git repository,
and querying the Git history there crashes.

Make it so that querying the Git history is skipped when Changelog generation is skipped
(as that's when those commits are actually used).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Jul 8, 2021
1 parent fc01d22 commit bf656e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 9 additions & 1 deletion tools/cdk-release/lib/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ export interface ConventionalCommit {
* @param gitTag the string representing the Git tag,
* will be used to limit the returned commits to only those added after that tag
*/
export async function getConventionalCommitsFromGitHistory(gitTag: string): Promise<ConventionalCommit[]> {
export async function getConventionalCommitsFromGitHistory(args: ReleaseOptions, gitTag: string): Promise<ConventionalCommit[]> {
// Since the commits are needed mainly for the Changelog generation,
// skip getting them if skipChangelog is `true`.
// This is needed to make our build succeed in environments without a Git repository,
// like CodeBuild in CodePipeline
if (args.skip?.changelog) {
return [];
}

const ret = new Array<any>();
return new Promise((resolve, reject) => {
const conventionalCommitsStream = gitRawCommits({
Expand Down
2 changes: 1 addition & 1 deletion tools/cdk-release/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = async function main(opts: ReleaseOptions): Promise<void> {
const currentVersion = packageInfo.version;
debug(args, 'Current version is: ' + currentVersion);

const commits = await getConventionalCommitsFromGitHistory(`v${currentVersion}`);
const commits = await getConventionalCommitsFromGitHistory(args, `v${currentVersion}`);
const filteredCommits = filterCommits(args, commits);
debugObject(args, 'Found and filtered commits', filteredCommits);

Expand Down
13 changes: 12 additions & 1 deletion tools/cdk-release/test/changelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConventionalCommit, filterCommits } from '../lib/conventional-commits';
import { ConventionalCommit, filterCommits, getConventionalCommitsFromGitHistory } from '../lib/conventional-commits';
import { changelog } from '../lib/lifecycles/changelog';
import { ReleaseOptions } from '../lib/types';

Expand Down Expand Up @@ -88,6 +88,17 @@ describe('Changelog generation', () => {
`);
});

test('makes it so that no Git commits are queried if Changelog generation is skipped', async () => {
const commits = await getConventionalCommitsFromGitHistory({
...args,
skip: {
changelog: true,
},
}, '3.9.2');

expect(commits).toHaveLength(0);
});
});

interface PartialCommit extends Partial<ConventionalCommit> {
Expand Down

0 comments on commit bf656e4

Please sign in to comment.