From dad50e92ab5d12038f7df3982bd27b37401429a6 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 1 Sep 2018 18:50:43 +0200 Subject: [PATCH 1/2] build: skip duplicate commit entries in changelog Ensures that commits are not showing up multiple times in the changelog. Commits can show up multiple times, if a changelog has been generated on a publish branch and has been copied over to "master". In that case, the changelog will already contain the commits that have been cherry-picked into the publish branch. These shouldn't be added twice. Closes #12915 --- tools/gulp/tasks/changelog.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/gulp/tasks/changelog.ts b/tools/gulp/tasks/changelog.ts index 2b3c3e0bda74..de7229562476 100644 --- a/tools/gulp/tasks/changelog.ts +++ b/tools/gulp/tasks/changelog.ts @@ -1,7 +1,8 @@ -import {task, src, dest} from 'gulp'; +import {grey, red, yellow} from 'chalk'; +import {readFileSync} from 'fs'; +import {dest, src, task} from 'gulp'; import {buildConfig} from 'material2-build-tools'; import {join} from 'path'; -import {yellow, red} from 'chalk'; // This imports lack of type definitions. const gulpChangelog = require('gulp-conventional-changelog'); @@ -26,7 +27,7 @@ task('changelog', async () => { } return src(changelogFile) - .pipe(gulpChangelog(changelogOptions)) + .pipe(gulpChangelog(changelogOptions, null, null, null, createDedupeWriterOptions())) .pipe(dest('./')); }); @@ -58,3 +59,31 @@ function getLatestSemverTag(): Promise { return gitSemverTags((err: Error, tags: string[]) => err ? reject(err) : resolve(tags[0])); }); } + +/** + * Creates changelog writer options which ensure that commits are not showing up multiple times. + * + * Commits can show up multiple times, if a changelog has been generated on a publish branch + * and has been copied over to "master". In that case, the changelog will already contain the + * commits that have been cherry-picked into the publish branch. These shouldn't be added twice. + */ +function createDedupeWriterOptions() { + const previousContent = readFileSync(changelogFile, 'utf8'); + + return { + // Change writer option that can be used to modify the content of a new changelog section. + // See: conventional-changelog/tree/master/packages/conventional-changelog-writer + finalizeContext: (context: any) => { + context.commitGroups.forEach((group: any) => { + group.commits = group.commits.filter((commit: any) => { + if (previousContent.includes(commit.hash)) { + console.log(grey(`Skipping: "${commit.header}" (${commit.hash})`)); + return false; + } + return true; + }); + }); + return context; + } + }; +} From 4fae10f4a22cd27e7a4af107d9ef0e2bc5b927fa Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 1 Sep 2018 18:54:52 +0200 Subject: [PATCH 2/2] Compare by commit header instead of SHA --- tools/gulp/tasks/changelog.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/gulp/tasks/changelog.ts b/tools/gulp/tasks/changelog.ts index de7229562476..b0b88df78077 100644 --- a/tools/gulp/tasks/changelog.ts +++ b/tools/gulp/tasks/changelog.ts @@ -76,7 +76,9 @@ function createDedupeWriterOptions() { finalizeContext: (context: any) => { context.commitGroups.forEach((group: any) => { group.commits = group.commits.filter((commit: any) => { - if (previousContent.includes(commit.hash)) { + // Note that we cannot compare the SHA's because the commits will have a different SHA + // if they are being cherry-picked into a different branch. + if (previousContent.includes(commit.header)) { console.log(grey(`Skipping: "${commit.header}" (${commit.hash})`)); return false; }