Skip to content

Commit 1cf9455

Browse files
Joscha RohmannKanaye
authored andcommitted
Added master commit detection.
1 parent 8ff3e91 commit 1cf9455

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

build/tasks/publish.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ module.exports = function (grunt) {
99
return repo.getMasterCommit();
1010
}
1111

12+
function headIsMaster (repo) {
13+
return Promise.all([
14+
repo.getMasterCommit(),
15+
repo.getHeadCommit()
16+
]).then(function (commits) {
17+
var head = commits[1];
18+
var master = commits[0];
19+
return (head.id().toString() == master.id().toString());
20+
});
21+
}
22+
1223
function getPatches(commit) {
1324
return commit.getDiff().then(function (diffs) {
1425
return Promise.all(diffs.map(function (diff) {
@@ -38,9 +49,7 @@ module.exports = function (grunt) {
3849

3950
function dontContainsTag (repo, tagName) {
4051
return Git.Tag.list(repo).then(function (tags) {
41-
return tags.map(function (tag) {
42-
return tag.name();
43-
}).indexOf(tagName) == -1;
52+
return tags.indexOf(tagName) == -1;
4453
});
4554
}
4655

@@ -81,22 +90,31 @@ module.exports = function (grunt) {
8190
repository = repo;
8291
return repo;
8392
})
84-
.then(getMasterCommit)
85-
.then(getPatches)
86-
.then(findPackageJsonPatch)
87-
.then(function (patch) {
88-
return hasVersionChange(patch, repository);
89-
})
90-
.then(function (versionChanged) {
91-
if (versionChanged) {
92-
grunt.log.writeln('Package version has changed. Build will be published.');
93-
grunt.task.run(['build-only', 'publish-post-build']);
94-
done();
95-
} else {
96-
grunt.log.writeln('Version has not changed.');
93+
.then(headIsMaster)
94+
.then(function (headIsMaster) {
95+
if (!headIsMaster) {
96+
grunt.log.writeln('Not on master branch. Nothing to do.');
9797
done();
98+
return;
9899
}
99-
}).catch(function (e) {
100+
return getMasterCommit(repository)
101+
.then(getPatches)
102+
.then(findPackageJsonPatch)
103+
.then(function (patch) {
104+
return hasVersionChange(patch, repository);
105+
})
106+
.then(function (versionChanged) {
107+
if (versionChanged) {
108+
grunt.log.writeln('Package version has changed. Build will be published.');
109+
grunt.task.run(['build-only', 'publish-post-build']);
110+
done();
111+
} else {
112+
grunt.log.writeln('Version has not changed.');
113+
done();
114+
}
115+
});
116+
})
117+
.catch(function (e) {
100118
if (e.message == 'No change in package.json') {
101119
grunt.log.writeln(e.message);
102120
done();
@@ -128,9 +146,7 @@ module.exports = function (grunt) {
128146
return index.writeTree();
129147
}).then(function (oidRes) {
130148
oid = oidRes;
131-
return Git.Reference.nameToId(repository, 'HEAD');
132-
}).then(function (head) {
133-
return repository.getCommit(head);
149+
return getMasterCommit(repository);
134150
}).then(function (parent) {
135151
return repository.createCommit('HEAD', author, author, 'Build Version ' + version, oid, [parent]);
136152
}).then(function (id) {

0 commit comments

Comments
 (0)