Skip to content

Commit

Permalink
chore(release): update contributors when publishing a release (#3552)
Browse files Browse the repository at this point in the history
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 <david@frode.(none)> 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.
  • Loading branch information
devoto13 authored Sep 2, 2020
1 parent ac7b73a commit 4fdef70
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 38 deletions.
87 changes: 49 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,109 +27,112 @@
"dignifiedquire <[email protected]>",
"johnjbarton <[email protected]>",
"greenkeeperio-bot <[email protected]>",
"Yaroslav Admin <[email protected]>",
"Karma Bot <[email protected]>",
"Maksim Ryzhikov <[email protected]>",
"ukasz Usarz <[email protected]>",
"Yaroslav Admin <[email protected]>",
"Christian Budde Christensen <[email protected]>",
"taichi <[email protected]>",
"Wesley Cho <[email protected]>",
"semantic-release-bot <[email protected]>",
"Liam Newman <[email protected]>",
"lukasz <[email protected]>",
"Anton <[email protected]>",
"Todd Wolfson <[email protected]>",
"Michał Gołębiowski-Owczarek <[email protected]>",
"Mark Trostler <[email protected]>",
"Ciro Nunes <[email protected]>",
"Shyam Seshadri <[email protected]>",
"Tim Cuthbertson <[email protected]>",
"Robo <[email protected]>",
"Christian Budde Christensen <[email protected]>",
"Pawel Kozlowski <[email protected]>",
"Christian Budde Christensen <[email protected]>",
"Shyam Seshadri <[email protected]>",
"Robo <[email protected]>",
"Mourad <[email protected]>",
"Daniel Compton <[email protected]>",
"Mark Ethan Trostler <[email protected]>",
"Kim Joar Bekkelund <[email protected]>",
"vivganes <[email protected]>",
"joshjb84 <[email protected]>",
"Georgii Dolzhykov <[email protected]>",
"Anton <[email protected]>",
"Brian Di Palma <[email protected]>",
"Nick Malaguti <[email protected]>",
"Kim Joar Bekkelund <[email protected]>",
"joshjb84 <[email protected]>",
"David Souther <[email protected]>",
"Brian Di Palma <[email protected]>",
"Matthias Oßwald <[email protected]>",
"Daniel Aleksandersen <[email protected]>",
"Jake Champion <[email protected]>",
"Marcello Nuccio <[email protected]>",
"Pieter Mees <[email protected]>",
"Brian Ford <[email protected]>",
"Aymeric Beaumet <[email protected]>",
"Andrew Martin <[email protected]>",
"Iristyle <Iristyle@github>",
"ywong <[email protected]>",
"Chris Casola <[email protected]>",
"Aymeric Beaumet <[email protected]>",
"Jeff Jewiss <[email protected]>",
"Pieter Mees <[email protected]>",
"Jake Champion <[email protected]>",
"Marcello Nuccio <[email protected]>",
"Jérémy Judéaux <[email protected]>",
"Andrew Martin <[email protected]>",
"Brian Ford <[email protected]>",
"Chris Hunt <[email protected]>",
"Ilya Volodin <[email protected]>",
"David Souther <[email protected]>",
"pavelgj <[email protected]>",
"sylvain-hamel <[email protected]>",
"Ilya Volodin <[email protected]>",
"ywong <[email protected]>",
"Iristyle <Iristyle@github>",
"Chris Hunt <[email protected]>",
"Robert Stein <[email protected]>",
"ngiebel <[email protected]>",
"Robin Liang <[email protected]>",
"rdodev <[email protected]>",
"Matt Lewis <[email protected]>",
"Ruben Bridgewater <[email protected]>",
"Ezra Brooks <[email protected]>",
"David Herges <[email protected]>",
"Réda Housni Alaoui <[email protected]>",
"Filipe Guerra <[email protected]>",
"Aseem Bansal <[email protected]>",
"Ruben Bridgewater <[email protected]>",
"Bryan Smith <[email protected]>",
"Sammy Jelin <sjelin@gmail.com>",
"Réda Housni Alaoui <reda.housnialaoui@gmail.com>",
"David Pärsson <[email protected]>",
"Sergei Startsev <[email protected]>",
"Sammy Jelin <[email protected]>",
"Jonas Pommerening <[email protected]>",
"Sergei Startsev <[email protected]>",
"Sergey Simonchik <[email protected]>",
"Sergey Simonchik <[email protected]>",
"Shane Russell <[email protected]>",
"Jonathan Freeman <[email protected]>",
"Josh <[email protected]>",
"Bulat Shakirzyanov <[email protected]>",
"Shane Russell <[email protected]>",
"Josh <[email protected]>",
"Andrew Morris <[email protected]>",
"Greenkeeper <[email protected]>",
"Stefan Dragnev <[email protected]>",
"Steve Mao <[email protected]>",
"Steve Mao <[email protected]>",
"Steve Van Opstal <[email protected]>",
"Sylvain Hamel <[email protected]>",
"KJ Tsanaktsidis <[email protected]>",
"Nico Jansen <[email protected]>",
"Terry <[email protected]>",
"Andrew Morris <[email protected]>",
"Cyrus Chan <[email protected]>",
"Thomas Parisot <[email protected]>",
"Hugues Malphettes <[email protected]>",
"Tom Erik Støwer <[email protected]>",
"Thomas Parisot <[email protected]>",
"Igor Minar <[email protected]>",
"Keen Yee Liau <[email protected]>",
"Igor Minar <[email protected]>",
"Tom Erik Støwer <[email protected]>",
"Kelly Jensen <[email protected]>",
"Ilya Goncharov <[email protected]>",
"Kevin Huang <[email protected]>",
"Kevin WENNER <[email protected]>",
"Parashuram <[email protected]>",
"Vivek Ganesan <[email protected]>",
"Vladimir Starkov <[email protected]>",
"Pat Tullmann <[email protected]>",
"Kevin WENNER <kevin.wenner@massmotionmedia.com>",
"ChangZhuo Chen (陳昌倬) <czchen@gmail.com>",
"PatrickJS <[email protected]>",
"Levi Thomason <[email protected]>",
"ChangZhuo Chen (陳昌倬) <[email protected]>",
"comdiv <[email protected]>",
"Aseem Bansal <[email protected]>",
"Luke Page <[email protected]>",
"comdiv <[email protected]>",
"James Ford <[email protected]>",
"James Talmage <[email protected]>",
"DarthCharles <[email protected]>",
"Richard Harrington <[email protected]>",
"karmarunnerbot <[email protected]>",
"DarthCharles <[email protected]>",
"Roarke Gaskill <[email protected]>",
"Ethan J. Brown <[email protected]>",
"Ezra Brooks <[email protected]>",
"Roarke Gaskill <[email protected]>",
"Matt Lewis <[email protected]>",
"David Herges <[email protected]>",
"Karol Fabjańczuk <[email protected]>",
"Karolis Narkevicius <[email protected]>",
"Keats <[email protected]>",
Expand All @@ -144,6 +147,7 @@
"M1xA <[email protected]>",
"Magnus Markling <[email protected]>",
"Manfred Stock <[email protected]>",
"Manoel <[email protected]>",
"Marko Anastasov <[email protected]>",
"Martin Geisler <[email protected]>",
"Martin Jul <[email protected]>",
Expand All @@ -156,6 +160,7 @@
"Matthias Oßwald <[email protected]>",
"Matti Paksula <[email protected]>",
"Mattijs Kneppers <[email protected]>",
"Max Waterman <[email protected]>",
"Merott Movahedi <[email protected]>",
"Merrick Christensen <[email protected]>",
"Michael Krotscheck <[email protected]>",
Expand All @@ -170,9 +175,9 @@
"Nick McCurdy <[email protected]>",
"Nick Payne <[email protected]>",
"Nick Williams <[email protected]>",
"Nico Jansen <[email protected]>",
"Nicolas Artman <[email protected]>",
"Nicolas Ferrero <[email protected]>",
"Nikita Balakirev <[email protected]>",
"Nir Moav <[email protected]>",
"Nish <[email protected]>",
"Nuno Job <[email protected]>",
Expand All @@ -198,6 +203,7 @@
"Peter Yates <[email protected]>",
"Philip Harrison <[email protected]>",
"Pierre Vanduynslager <[email protected]>",
"Piotr Błażejewicz (Peter Blazejewicz) <[email protected]>",
"Piper Chester <[email protected]>",
"Rafal Lindemann <[email protected]>",
"Remy Sharp <[email protected]>",
Expand Down Expand Up @@ -234,6 +240,8 @@
"Thai Pangsakulyanont @ Taskworld <[email protected]>",
"Thijs Triemstra <[email protected]>",
"Thomas Parisot <[email protected]>",
"Tim Gates <[email protected]>",
"Tim Hartman <[email protected]>",
"Tim Olshansky <[email protected]>",
"Timo Tijhof <[email protected]>",
"Tom MacWright <[email protected]>",
Expand Down Expand Up @@ -289,6 +297,7 @@
"Alexander Pepper <[email protected]>",
"Alexander Shtuchkin <[email protected]>",
"Alexei <[email protected]>",
"Ameer Jhan <[email protected]>",
"Anders Ekdahl <[email protected]>",
"Anders Janmyr <[email protected]>",
"Andreas Krummsdorf <[email protected]>",
Expand All @@ -305,6 +314,7 @@
"Basemm <[email protected]>",
"Benoit Charbonnier <[email protected]>",
"Bhavesh Kakadiya <[email protected]>",
"Borewit <[email protected]>",
"Brady Wied <[email protected]>",
"Bram Borggreve <[email protected]>",
"Breno Calazans <[email protected]>",
Expand All @@ -321,6 +331,7 @@
"Chris Dawson <[email protected]>",
"Christian Weiss <[email protected]>",
"Christopher Hiller <[email protected]>",
"Chuf <[email protected]>",
"Ciro S. Costa <[email protected]>",
"Daan Stolp <[email protected]>",
"Damien Choizit <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'@semantic-release/github'
],
prepare: [
'./tools/update-contributors',
'@semantic-release/changelog',
'@semantic-release/npm',
'@semantic-release/git'
Expand Down
23 changes: 23 additions & 0 deletions tools/update-contributors.js
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
// 412 Friedel Ziegelmayer <[email protected]>
// 206 dignifiedquire <[email protected]>
// 139 johnjbarton <[email protected]>
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 }

0 comments on commit 4fdef70

Please sign in to comment.