Skip to content

Commit

Permalink
#137 automatic changelog creation added
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mrowetz committed Jan 30, 2017
1 parent 1fcb8f3 commit 6ced761
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const path = require("path");
const process = require("process");
const gruntBump = require("grunt-bump")

/**
* @param {IGrunt} grunt - Grunt instance
*/
module.exports = function (grunt) {
"use strict";


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

// manually load custom task
require("./build-utils/grunt-tasks/changelog-custom")(grunt)

// automatically loads configurations from `./grunt-config/*`
require('load-grunt-config')(grunt, {
configPath: path.join(process.cwd(), 'build-utils/grunt-config'),
Expand Down Expand Up @@ -60,6 +64,7 @@ module.exports = function (grunt) {
"preBuild",
`bump-only:${releaseIncrement}`,
"releaseBuild",
"changelog-custom",
"commitAndPush"
]);

Expand Down
6 changes: 6 additions & 0 deletions build-utils/grunt-config/changelog-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
options: {
version: 'v<%= package.version %>',
file: 'CHANGELOG.md'
}
}
3 changes: 1 addition & 2 deletions build-utils/grunt-config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
options: {
cwd: process.cwd()
},
exec: `(export VERSION=<%= package.version %> && bash build-utils/release.sh)`

exec: `(export VERSION=<%= package.version %> && export CHANGELOG="<%= changelog %>" && bash build-utils/release.sh)`
}
};
43 changes: 43 additions & 0 deletions build-utils/grunt-tasks/changelog-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let fs = require('fs')
let conventionalChangelog = require('conventional-changelog');

/**
* @param {IGrunt} grunt - Grunt instance
*/
module.exports = function(grunt){
let PassThroughStream = require('stream').PassThrough;

grunt.registerTask('changelog-custom', 'Custom version of changelog', function() {
const done = this.async();
const options = this.options()
let readDataStream = new PassThroughStream();
let tmpBuffer = "";

// extract data
readDataStream
.on('data', (chunk) => tmpBuffer += chunk)
.on('end', () => {
grunt.config.data.changelog = tmpBuffer
readDataStream.end()
})

// changlog file writer
let appenFileStream = fs.createWriteStream(options.file, {'flags': 'a'})
.on('error', grunt.log.error)
.on('close', () => {
grunt.log.ok(`${options.file} updated with latest changelog for ${options.version}`)
done();
})

// get changelog
conventionalChangelog({
config: {
warn : grunt.warn,
pkg: grunt.package
}
}, {
version: options.version
}).pipe(readDataStream).pipe(appenFileStream) // or any writable stream
});

}
5 changes: 3 additions & 2 deletions build-utils/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
: "${VERSION?Need to set VERSION environment variable}"
: "${GITHUB_TOKEN?Need to set GITHUB_TOKEN environment variable}"


echo "Start Github release for ${VERSION}..."

CHANGELOG=${CHANGELOG}

###
# Github Release
###
Expand Down Expand Up @@ -44,7 +45,7 @@ echo "make Github release"
# make releases
# TODO: make final not draft once confirmed working
# TODO: add Changelog
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)
API_JSON=$(printf '{"tag_name": "v%s", "target_commitish": "release", "name": "v%s", "body": "%s", "draft": false, "prerelease": false}' $VERSION $VERSION $CHANGELOG)
curl \
--data "$API_JSON" \
-H "Authorization: token ${GITHUB_TOKEN}" \
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"types": "./index.d.ts",
"license": "MIT",
"devDependencies": {
"@types/grunt": "^0.4.21",
"conventional-changelog": "^1.1.0",
"grunt": "^1.0.1",
"grunt-banner": "^0.6.0",
"grunt-browserify": "^5.0.0",
Expand Down

0 comments on commit 6ced761

Please sign in to comment.