Skip to content

Commit 6ced761

Browse files
author
Michael Mrowetz
committed
#137 automatic changelog creation added
1 parent 1fcb8f3 commit 6ced761

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

Diff for: Gruntfile.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
const path = require("path");
22
const process = require("process");
33
const gruntBump = require("grunt-bump")
4-
4+
/**
5+
* @param {IGrunt} grunt - Grunt instance
6+
*/
57
module.exports = function (grunt) {
68
"use strict";
79

8-
910
/** Version banner for static files (keep version format for "grunt-bump") */
1011
const banner = "/*! github.com/micmro/PerfCascade Version:<%= package.version %> <%= grunt.template.today(\"(dd/mm/yyyy)\") %> */\n";
1112
let releaseIncrement = ["major", "minor"]
1213
.indexOf(grunt.option('release-increment')) != -1 ? grunt.option('release-increment') : "patch";
1314

15+
// manually load custom task
16+
require("./build-utils/grunt-tasks/changelog-custom")(grunt)
17+
1418
// automatically loads configurations from `./grunt-config/*`
1519
require('load-grunt-config')(grunt, {
1620
configPath: path.join(process.cwd(), 'build-utils/grunt-config'),
@@ -60,6 +64,7 @@ module.exports = function (grunt) {
6064
"preBuild",
6165
`bump-only:${releaseIncrement}`,
6266
"releaseBuild",
67+
"changelog-custom",
6368
"commitAndPush"
6469
]);
6570

Diff for: build-utils/grunt-config/changelog-custom.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
options: {
3+
version: 'v<%= package.version %>',
4+
file: 'CHANGELOG.md'
5+
}
6+
}

Diff for: build-utils/grunt-config/run.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = {
2727
options: {
2828
cwd: process.cwd()
2929
},
30-
exec: `(export VERSION=<%= package.version %> && bash build-utils/release.sh)`
31-
30+
exec: `(export VERSION=<%= package.version %> && export CHANGELOG="<%= changelog %>" && bash build-utils/release.sh)`
3231
}
3332
};

Diff for: build-utils/grunt-tasks/changelog-custom.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
let fs = require('fs')
2+
let conventionalChangelog = require('conventional-changelog');
3+
4+
/**
5+
* @param {IGrunt} grunt - Grunt instance
6+
*/
7+
module.exports = function(grunt){
8+
let PassThroughStream = require('stream').PassThrough;
9+
10+
grunt.registerTask('changelog-custom', 'Custom version of changelog', function() {
11+
const done = this.async();
12+
const options = this.options()
13+
let readDataStream = new PassThroughStream();
14+
let tmpBuffer = "";
15+
16+
// extract data
17+
readDataStream
18+
.on('data', (chunk) => tmpBuffer += chunk)
19+
.on('end', () => {
20+
grunt.config.data.changelog = tmpBuffer
21+
readDataStream.end()
22+
})
23+
24+
// changlog file writer
25+
let appenFileStream = fs.createWriteStream(options.file, {'flags': 'a'})
26+
.on('error', grunt.log.error)
27+
.on('close', () => {
28+
grunt.log.ok(`${options.file} updated with latest changelog for ${options.version}`)
29+
done();
30+
})
31+
32+
// get changelog
33+
conventionalChangelog({
34+
config: {
35+
warn : grunt.warn,
36+
pkg: grunt.package
37+
}
38+
}, {
39+
version: options.version
40+
}).pipe(readDataStream).pipe(appenFileStream) // or any writable stream
41+
});
42+
43+
}

Diff for: build-utils/release.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
: "${VERSION?Need to set VERSION environment variable}"
1010
: "${GITHUB_TOKEN?Need to set GITHUB_TOKEN environment variable}"
1111

12-
1312
echo "Start Github release for ${VERSION}..."
1413

14+
CHANGELOG=${CHANGELOG}
15+
1516
###
1617
# Github Release
1718
###
@@ -44,7 +45,7 @@ echo "make Github release"
4445
# make releases
4546
# TODO: make final not draft once confirmed working
4647
# TODO: add Changelog
47-
API_JSON=$(printf '{"tag_name": "v%s", "target_commitish": "release", "name": "v%s", "body": "Release of version %s", "draft": false, "prerelease": false}' $VERSION $VERSION $VERSION)
48+
API_JSON=$(printf '{"tag_name": "v%s", "target_commitish": "release", "name": "v%s", "body": "%s", "draft": false, "prerelease": false}' $VERSION $VERSION $CHANGELOG)
4849
curl \
4950
--data "$API_JSON" \
5051
-H "Authorization: token ${GITHUB_TOKEN}" \

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"types": "./index.d.ts",
3333
"license": "MIT",
3434
"devDependencies": {
35+
"@types/grunt": "^0.4.21",
36+
"conventional-changelog": "^1.1.0",
3537
"grunt": "^1.0.1",
3638
"grunt-banner": "^0.6.0",
3739
"grunt-browserify": "^5.0.0",

0 commit comments

Comments
 (0)