forked from karma-runner/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): update contributors when publishing a release (karma-…
…runner#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 <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
1 parent
81e51ae
commit 1378b44
Showing
3 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <vojta.jina@gmail.com> | ||
// 412 Friedel Ziegelmayer <friedel.ziegelmayer@gmail.com> | ||
// 206 dignifiedquire <friedel.ziegelmayer@gmail.com> | ||
// 139 johnjbarton <johnjbarton@johnjbarton.com> | ||
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 } |