Automate HISTORY and release number changes

pull/6635/head
Rodrigo Nascimento 8 years ago
parent 3e312c9fcf
commit 2f2ef8bd13
  1. 116
      .github/changelog.js
  2. 40
      .github/templates/commit.hbs
  3. 11
      .github/templates/footer.hbs
  4. 26
      .github/templates/header.hbs
  5. 22
      .github/templates/template.hbs
  6. 47
      .scripts/version.js
  7. 7
      package.json

@ -0,0 +1,116 @@
/* eslint no-var: 0, object-shorthand: 0, prefer-template: 0 */
'use strict';
var readFile = require('fs').readFileSync;
var resolve = require('path').resolve;
var gitUrl = 'https://github.com/RocketChat/Rocket.Chat';
var parserOpts = {
headerPattern: /^(\[([A-z]+)\] )?(.*)$/m,
headerCorrespondence: [
'stype',
'type',
'subject'
],
mergePattern: /^Merge pull request #(.*) from .*$/,
mergeCorrespondence: ['pr']
// noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
// revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
// revertCorrespondence: ['header', 'hash'],
// mergePattern: /^Merge pull request #(\d+) from (.*)$/,
// mergeCorrespondence: ['id', 'source']
};
var LABELS = {
BREAK: {
title: 'BREAKING CHANGES',
collapse: false
},
NEW: {
title: 'New Features',
collapse: false
},
FIX: {
title: 'Bug Fixes',
collapse: false
},
DOC: {
title: 'Documentation',
collapse: true
},
OTHER: {
title: 'Others',
collapse: true
}
};
var sort = Object.keys(LABELS);
var writerOpts = {
transform: function(commit) {
if (!commit.pr) {
return;
}
// console.log(commit);
commit.type = (commit.type || 'OTHER').toUpperCase();
if (LABELS[commit.type] == null) {
return;
}
commit.pr_url = gitUrl + '/pull/' + commit.pr;
var issues = [];
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}
if (typeof commit.subject === 'string') {
// GitHub issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, function(_, issue) {
issues.push(issue);
return '[#' + issue + '](' + gitUrl + '/issue/' + issue + ')';
});
// GitHub user URLs.
commit.subject = commit.subject.replace(/@([a-zA-Z0-9_]+)/g, '[@$1](https://github.com/$1)');
}
// remove references that already appear in the subject
commit.references = commit.references.filter(function(reference) {
if (issues.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
return commit;
},
groupBy: 'type',
commitGroupsSort: function(a, b) {
return sort.indexOf(a.title) > sort.indexOf(b.title);
},
finalizeContext: function(context) {
context.commitGroups.forEach(function(group) {
Object.assign(group, LABELS[group.title.toUpperCase()]);
});
// console.log(context);
return context;
},
commitsSort: ['subject']
};
writerOpts.mainTemplate = readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8');
writerOpts.headerPartial = readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8');
writerOpts.commitPartial = readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8');
writerOpts.footerPartial = readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8');
module.exports = {
gitRawCommitsOpts: {
merges: null
},
parserOpts: parserOpts,
writerOpts: writerOpts
};

@ -0,0 +1,40 @@
{{!-- pr reference --}}- {{#if pr}}[#{{pr}}]({{pr_url}}){{/if}}
{{~!-- subject --}} {{subject}}
{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if this.repository}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}
{{~else}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~/if}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.issue}}/{{this.issue}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

@ -0,0 +1,11 @@
{{#if noteGroups}}
{{#each noteGroups}}
### {{title}}
{{#each notes}}
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
{{/each}}
{{/each}}
{{/if}}

@ -0,0 +1,26 @@
<a name="{{version}}"></a>
{{#if isPatch~}}
##
{{~else~}}
#
{{~/if}} {{#if @root.linkCompare~}}
[{{version}}](
{{~#if @root.repository~}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~else}}
{{~@root.repoUrl}}
{{~/if~}}
/compare/{{previousTag}}...{{currentTag}})
{{~else}}
{{~version}}
{{~/if}}
{{~#if title}} "{{title}}"
{{~/if}}
{{~#if date}} ({{date}})
{{/if}}

@ -0,0 +1,22 @@
{{> header}}
{{#each commitGroups}}
{{#if collapse}}
<details>
<summary>{{title}}</summary>
{{else}}
### {{title}}
{{/if}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{#if collapse}}
</details>
{{/if}}
{{/each}}
{{> footer}}

@ -0,0 +1,47 @@
/* eslint object-shorthand: 0, prefer-template: 0 */
const path = require('path');
const fs = require('fs');
let pkgJson = {};
try {
pkgJson = require(path.resolve(
process.cwd(),
'./package.json'
));
} catch (err) {
console.error('no root package.json found');
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const files = [
'./package.json',
'./.sandstorm/sandstorm-pkgdef.capnp',
'./.travis/snap.sh',
'./packages/rocketchat-lib/rocketchat.info'
];
console.log('Current version:', pkgJson.version);
rl.question('New version: ', function(version) {
rl.close();
version = version.trim();
if (version === '') {
return;
}
console.log('Updating files to version ' + version);
files.forEach(function(file) {
const data = fs.readFileSync(file, 'utf8');
fs.writeFileSync(file, data.replace(pkgJson.version, version), 'utf8');
});
});

@ -42,7 +42,9 @@
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests/end-to-end",
"chimp-test": "chimp tests/chimp-config.js",
"postinstall": "cd packages/rocketchat-katex && npm i"
"postinstall": "cd packages/rocketchat-katex && npm i",
"version": "node .scripts/version.js",
"release": "conventional-changelog --config .github/changelog.js -i HISTORY.md -s"
},
"license": "MIT",
"repository": {
@ -57,7 +59,8 @@
"chimp": "^0.47.2",
"eslint": "^3.19.0",
"stylelint": "^7.10.1",
"supertest": "^3.0.0"
"supertest": "^3.0.0",
"conventional-changelog": "^1.1.3"
},
"dependencies": {
"babel-runtime": "^6.23.0",

Loading…
Cancel
Save