From 3165a5b504b35286e9e6258f9f0b32db20050a5b Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 10 Mar 2020 02:43:37 -0700 Subject: [PATCH] Make changelog part of external rather than internal release Summary: This makes the changelog generating part of the bump-version process, rather than the build-release Reviewed By: passy Differential Revision: D20284211 fbshipit-source-id: f4a5c9bdb98c91f11a216957c9d5175c4b64fe70 --- CHANGELOG.md | 2 +- scripts/bump-version.sh | 3 ++ scripts/generate-changelog.js | 72 +++++++++++++++++++++++++++++++++++ static/CHANGELOG.md | 3 ++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 scripts/generate-changelog.js create mode 100644 static/CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index ff374a9fe..f5ff88011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Pre-history -Please see our [releases GitHub page](https://github.com/facebook/flipper/releases) for a full list of changes for every release. +Please see our [releases GitHub page](https://github.com/facebook/flipper/releases) for a full list of changes of old releases. diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index f82ea3a39..7e641eff4 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -89,6 +89,9 @@ jq '.version = $newVal' --arg newVal "$VERSION" "$SONAR_DIR"/package.json > tmp. #Update react-native-flipper to the very same version jq '.version = $newVal' --arg newVal "$VERSION" "$SONAR_DIR"/react-native/react-native-flipper/package.json > tmp.$$.json && mv tmp.$$.json "$SONAR_DIR"/react-native/react-native-flipper/package.json +#Generate changelog +"$SONAR_DIR"/scripts/generate-changelog.js + echo "Committing the files..." hg addremove diff --git a/scripts/generate-changelog.js b/scripts/generate-changelog.js new file mode 100755 index 000000000..01dc8374a --- /dev/null +++ b/scripts/generate-changelog.js @@ -0,0 +1,72 @@ +#!/usr/bin/env node +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +const path = require('path'); +const fs = require('fs'); +const cp = require('child_process'); + +const root = path.join(__dirname, '..'); + +const version = JSON.parse( + fs.readFileSync(path.join(root, 'package.json'), 'utf8'), +).version; + +const now = new Date(); +const date = `${now.getDate()}/${now.getMonth() + 1}/${now.getFullYear()}`; +const newlineMarker = '__NEWLINE_MARKER__'; +const fChangelog = path.join(root, 'CHANGELOG.md'); + +const lastCommit = cp + .execSync(`hg log --limit 1 --template '{node}'`, {cwd: root}) + .toString(); +const firstCommit = cp + .execSync( + `hg log --limit 1 --template '{node}' --keyword 'Flipper Release: v'`, + {cwd: root}, + ) + .toString(); + +console.log( + `Generating changelog for version ${version} based on ${firstCommit}..${lastCommit}`, +); + +// # get all commit summaries since last release | find all changelog entries, but make sure there is only one line per commit by temporarily replacing newlines +const hgLogCommand = `hg log -r "${firstCommit}::${lastCommit} and file('../*')" --template "{phabdiff} - {sub('\n','${newlineMarker}', desc)}\n"`; +const hgLog = cp.execSync(hgLogCommand).toString(); + +const diffRe = /^D\d+/; +const changeLogLineRe = /(^changelog:\s*?)(.*?)$/i; + +let contents = `# ${version} (${date})\n\n`; +let changes = 0; + +hgLog + .split('\n') + .filter(line => diffRe.test(line)) + .forEach(line => { + // Grab the diff nr from every line in the output + const diff = line.trim().match(diffRe)[0]; + // unfold the lines generated by hg log again + line.split(newlineMarker).forEach(diffline => { + // if a line starts with changelog:, grab the rest of the text and add it to the changelog + const match = diffline.match(changeLogLineRe); + if (match) { + changes++; + contents += ` * ${diff} - ${match[2]}\n`; + } + }); + }); + +if (!changes) { + console.log('No diffs with changelog items found in this release'); +} else { + contents += '\n\n' + fs.readFileSync(fChangelog, 'utf8'); + fs.writeFileSync(fChangelog, contents); +} diff --git a/static/CHANGELOG.md b/static/CHANGELOG.md new file mode 100644 index 000000000..85a0f2d3e --- /dev/null +++ b/static/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +See [static/CHANGELOG.md](static/CHANGELOG.md)