From 4fdef7059a0930907f4bbd74c54e2a019ac20687 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Wed, 2 Sep 2020 20:04:19 +0200 Subject: [PATCH] chore(release): update contributors when publishing a release (#3552) Grunt release publishing [used to](https://github.com/karma-runner/karma/blob/master/gruntfile.js#L103) update `contributors` in `package.json`, but this feature has been lost during the migration to `semantic-release`. This PR restores the same logic in `semantic-release` plugin. I considered using [semantic-release-contributors](https://www.npmjs.com/package/semantic-release-contributors) first, but it has couple of issues: - it only adds contributors since last release, so can not restore contributors, who were missed while semantic-release was used for publishing - it parses author data from commit and then serializes it back, which in some cases produces wrong results (e.g. David Jensen becomes an empty string, because parsing silently fails) Because of the above issues I've re-implemented logic from the [Grunt plugin](https://github.com/vojtajina/grunt-npm/blob/master/tasks/npm.js#L90) as a semantic-release plugin and applied changes produced by it. There are a many changes to existing contributors, because current logic sorts them by the amount of commits. --- package.json | 87 ++++++++++++++++++++---------------- release.config.js | 1 + tools/update-contributors.js | 23 ++++++++++ 3 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 tools/update-contributors.js diff --git a/package.json b/package.json index eab23bb73..349f8b92f 100644 --- a/package.json +++ b/package.json @@ -27,73 +27,72 @@ "dignifiedquire ", "johnjbarton ", "greenkeeperio-bot ", + "Yaroslav Admin ", "Karma Bot ", "Maksim Ryzhikov ", "ukasz Usarz ", - "Yaroslav Admin ", "Christian Budde Christensen ", "taichi ", "Wesley Cho ", + "semantic-release-bot ", "Liam Newman ", "lukasz ", + "Anton ", "Todd Wolfson ", "Michał Gołębiowski-Owczarek ", "Mark Trostler ", "Ciro Nunes ", - "Shyam Seshadri ", "Tim Cuthbertson ", - "Robo ", - "Christian Budde Christensen ", "Pawel Kozlowski ", + "Christian Budde Christensen ", + "Shyam Seshadri ", + "Robo ", "Mourad ", "Daniel Compton ", "Mark Ethan Trostler ", + "Kim Joar Bekkelund ", "vivganes ", + "joshjb84 ", "Georgii Dolzhykov ", - "Anton ", - "Brian Di Palma ", "Nick Malaguti ", - "Kim Joar Bekkelund ", - "joshjb84 ", - "David Souther ", + "Brian Di Palma ", + "Matthias Oßwald <1410947+matz3@users.noreply.github.com>", "Daniel Aleksandersen ", - "Jake Champion ", - "Marcello Nuccio ", - "Pieter Mees ", - "Brian Ford ", - "Aymeric Beaumet ", + "Andrew Martin ", + "Iristyle ", + "ywong ", "Chris Casola ", + "Aymeric Beaumet ", "Jeff Jewiss ", + "Pieter Mees ", + "Jake Champion ", + "Marcello Nuccio ", "Jérémy Judéaux ", - "Andrew Martin ", + "Brian Ford ", + "Chris Hunt ", + "Ilya Volodin ", + "David Souther ", "pavelgj ", "sylvain-hamel ", - "Ilya Volodin ", - "ywong ", - "Iristyle ", - "Chris Hunt ", "Robert Stein ", "ngiebel ", "Robin Liang ", "rdodev ", - "Matt Lewis ", - "Ruben Bridgewater ", - "Ezra Brooks ", - "David Herges ", - "Réda Housni Alaoui ", "Filipe Guerra ", - "Aseem Bansal ", + "Ruben Bridgewater ", "Bryan Smith ", - "Sammy Jelin ", + "Réda Housni Alaoui ", "David Pärsson ", - "Sergei Startsev ", + "Sammy Jelin ", "Jonas Pommerening ", + "Sergei Startsev ", "Sergey Simonchik ", "Sergey Simonchik ", - "Shane Russell ", "Jonathan Freeman ", - "Josh ", "Bulat Shakirzyanov ", + "Shane Russell ", + "Josh ", + "Andrew Morris ", "Greenkeeper ", "Stefan Dragnev ", "Steve Mao ", @@ -101,35 +100,39 @@ "Steve Van Opstal ", "Sylvain Hamel ", "KJ Tsanaktsidis ", + "Nico Jansen ", "Terry ", - "Andrew Morris ", "Cyrus Chan ", - "Thomas Parisot ", "Hugues Malphettes ", - "Tom Erik Støwer ", + "Thomas Parisot ", "Igor Minar ", "Keen Yee Liau ", "Igor Minar ", + "Tom Erik Støwer ", "Kelly Jensen ", "Ilya Goncharov ", "Kevin Huang ", + "Kevin WENNER ", "Parashuram ", "Vivek Ganesan ", "Vladimir Starkov ", "Pat Tullmann ", - "Kevin WENNER ", + "ChangZhuo Chen (陳昌倬) ", "PatrickJS ", "Levi Thomason ", - "ChangZhuo Chen (陳昌倬) ", - "comdiv ", + "Aseem Bansal ", "Luke Page ", + "comdiv ", "James Ford ", "James Talmage ", + "DarthCharles ", "Richard Harrington ", "karmarunnerbot ", - "DarthCharles ", - "Roarke Gaskill ", "Ethan J. Brown ", + "Ezra Brooks ", + "Roarke Gaskill ", + "Matt Lewis ", + "David Herges ", "Karol Fabjańczuk ", "Karolis Narkevicius ", "Keats ", @@ -144,6 +147,7 @@ "M1xA ", "Magnus Markling ", "Manfred Stock ", + "Manoel ", "Marko Anastasov ", "Martin Geisler ", "Martin Jul ", @@ -156,6 +160,7 @@ "Matthias Oßwald ", "Matti Paksula ", "Mattijs Kneppers ", + "Max Waterman ", "Merott Movahedi ", "Merrick Christensen ", "Michael Krotscheck ", @@ -170,9 +175,9 @@ "Nick McCurdy ", "Nick Payne ", "Nick Williams ", - "Nico Jansen ", "Nicolas Artman ", "Nicolas Ferrero ", + "Nikita Balakirev ", "Nir Moav ", "Nish ", "Nuno Job ", @@ -198,6 +203,7 @@ "Peter Yates ", "Philip Harrison ", "Pierre Vanduynslager ", + "Piotr Błażejewicz (Peter Blazejewicz) ", "Piper Chester ", "Rafal Lindemann ", "Remy Sharp ", @@ -234,6 +240,8 @@ "Thai Pangsakulyanont @ Taskworld ", "Thijs Triemstra ", "Thomas Parisot ", + "Tim Gates ", + "Tim Hartman ", "Tim Olshansky ", "Timo Tijhof ", "Tom MacWright ", @@ -289,6 +297,7 @@ "Alexander Pepper ", "Alexander Shtuchkin ", "Alexei ", + "Ameer Jhan ", "Anders Ekdahl ", "Anders Janmyr ", "Andreas Krummsdorf ", @@ -305,6 +314,7 @@ "Basemm ", "Benoit Charbonnier ", "Bhavesh Kakadiya ", + "Borewit ", "Brady Wied ", "Bram Borggreve ", "Breno Calazans ", @@ -321,6 +331,7 @@ "Chris Dawson ", "Christian Weiss ", "Christopher Hiller ", + "Chuf <42591821+GChuf@users.noreply.github.com>", "Ciro S. Costa ", "Daan Stolp ", "Damien Choizit ", diff --git a/release.config.js b/release.config.js index a3cca16aa..7bf58b9dd 100644 --- a/release.config.js +++ b/release.config.js @@ -8,6 +8,7 @@ module.exports = { '@semantic-release/github' ], prepare: [ + './tools/update-contributors', '@semantic-release/changelog', '@semantic-release/npm', '@semantic-release/git' diff --git a/tools/update-contributors.js b/tools/update-contributors.js new file mode 100644 index 000000000..8eb5d785c --- /dev/null +++ b/tools/update-contributors.js @@ -0,0 +1,23 @@ +const { execSync } = require('child_process') +const { readFileSync, writeFileSync } = require('fs') +const { resolve } = require('path') + +const prepare = async (pluginConfig, { logger }) => { + // Example output: + // 1042 Vojta Jina + // 412 Friedel Ziegelmayer + // 206 dignifiedquire + // 139 johnjbarton + const stdout = execSync('git log --pretty=short | git shortlog -nse', { encoding: 'utf8' }) + + const pkgPath = resolve(__dirname, '..', 'package.json') + const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) + + // First line is already included as author field. Last line is dropped as it is an empty line. + pkg.contributors = stdout.split('\n').slice(1, -1).map((line) => line.replace(/^[\W\d]+/, '')) + writeFileSync(pkgPath, JSON.stringify(pkg, undefined, ' ') + '\n', 'utf8') + + logger.info('Updated contributors list.') +} + +module.exports = { prepare }