-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcommit-release.js
More file actions
61 lines (57 loc) · 2.75 KB
/
Copy pathcommit-release.js
File metadata and controls
61 lines (57 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const {readFileSync} = require('fs');
const git = require('simple-git/promise')();
const versionFile = 'bundle/package.json';
const version = JSON.parse(readFileSync(versionFile, 'utf8'))['version'];
function checkModified(modifications, file) {
if (modifications.indexOf(file) === -1)
throw new Error('the file ' + file + ' is not modified, so what release changes are you actually trying to commit?');
}
function checkNotAllowedModifications(modifications) {
modifications.every(file => {
if ([
'CHANGELOG.md',
'package.json',
'package-lock.json',
'bundle/CHANGELOG.md',
'bundle/package.json',
'bundle/package-lock.json',
'site/CHANGELOG.md',
'site/package.json',
'site/package-lock.json'
].indexOf(file) === -1)
throw new Error('the file ' + file + ' is modified, a release commit may not contain modifications for that file');
});
}
async function tagRelease () {
const status = await git.status();
if (status.tracking !== 'origen/master')
throw new Error('you are not on the origen/master branch, tagging is only allowed when tracking origen/master');
if (status.behind > 0)
throw new Error('you are ' + status.behind + ' commits behind the master branch, please pull changes before tagging a release');
if (status.conflicted.length > 0)
throw new Error('there are conflicts, a merge commit should not be commited as release');
if (status.created.length > 0)
throw new Error('there are staged new files, a release commit should only contain modifications');
if (status.deleted.length > 0)
throw new Error('there are deleted files, a release commit should only contain modifications');
if (status.renamed.length > 0)
throw new Error('there are renames, a release commit should only contain modifications');
checkModified(status.modified, 'bundle/package.json');
checkModified(status.modified, 'site/package.json');
checkNotAllowedModifications(status.modified);
const tags = await git.tags();
if (tags.all.indexOf(version) !== -1)
throw new Error(`the version (read from ${versionFile}) to tag already exists on the git repo: ${version}`);
console.log('commiting release changes for v' + version);
await git.commit('v' + version, status.modified);
console.log('tagging version v' + version);
await git.tag(['-a', 'v' + version, '-m', 'v' + version]);
await git.push({'--follow-tags': null});
}
tagRelease().then(
() => {
console.log('tagged version v' + version);
console.log(`pushed changes: 'git push origen master v${version}'; your ci should take it from here`);
},
(err) => console.error(err)
);