Skip to content

Commit 129f28b

Browse files
committed
fix(grunt): Make getVersion() work on travis
1 parent 84de806 commit 129f28b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/grunt/utils.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,28 @@ var util = module.exports = {
194194
getVersion: function() {
195195
// Get the current git tag
196196
// var version = shell.exec('git describe', {silent:true}).output.trim();
197-
var version = shell.exec('git rev-list --all --max-count=1 | xargs git describe', {silent:true}).output.trim();
198197

199-
// Clean up the tag
198+
// Try to get a tag for the current version
199+
var out = shell.exec('git rev-list --all --max-count=1 | xargs git describe', {silent:true});
200+
201+
var version;
202+
203+
// If there's a tag on this commit, use it
204+
if (out.code == 0) {
205+
version = out.output.trim();
206+
}
207+
// ...otherwise, get the most recent stable tag
208+
else {
209+
version = shell.exec('git rev-list --tags --max-count=1 | xargs git describe', {silent:true}).output.trim();
210+
211+
// Append the commit hash suffix
212+
var hash = shell.exec('git describe --always', {silent:true}).output.trim();
213+
version = version + '-' + hash;
214+
}
215+
216+
// Clean up the tag (git describe --long comes out as: v1.0.0-123-a78fda, need to remove the middle part though with the above commands we should not have the build number)
200217
var tag = version.replace(/-\d+-/, '-');
218+
201219
tag = semver.clean(tag);
202220

203221
return tag;

0 commit comments

Comments
 (0)