Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fe0e434

Browse files
committed
chore(version-info): use remote tags and increment patch version
1 parent edad4e6 commit fe0e434

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/grunt/utils.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var shell = require('shelljs');
44
var grunt = require('grunt');
55
var spawn = require('child_process').spawn;
66
var semver = require('semver');
7-
var versionInfo = require('../versions/version-info');
87

98
var _ = require('lodash');
109

lib/versions/version-info.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ var isStable = function(version) {
100100
* @return {Array.<SemVer>} The collection of previous versions
101101
*/
102102
var getPreviousVersions = function() {
103-
var tagResults = shell.exec('git tag', {silent: true});
103+
// always use the remote tags as the local clone might
104+
// not contain all commits when cloned with git clone --depth=...
105+
// Needed e.g. for Travis
106+
var tagResults = shell.exec('git ls-remote --tags | grep -o -e "v[0-9].*[0-9]$"', {silent: true});
104107
if ( tagResults.code === 0 ) {
105108
return _(tagResults.output.trim().split('\n'))
106109
.map(function(tag) {
@@ -129,23 +132,34 @@ var getPreviousVersions = function() {
129132
* @return {SemVer} The snapshot version
130133
*/
131134
var getSnapshotVersion = function() {
132-
133135
version = _(previousVersions)
134136
.filter(function(tag) {
135137
return semver.satisfies(tag, currentPackage.branchVersion);
136138
})
137139
.last();
138140

139141
if ( !version ) {
140-
throw new Error("No valid versions can be found that match the current branch (" +
141-
currentPackage.branchVersion + ").\n" +
142-
"Try running `git fetch -t` to download the tags from the repository.");
142+
// a snapshot version before the first tag on the branch
143+
version = semver(currentPackage.branchVersion.replace('*','0-beta.1'));
143144
}
144145

145146
// We need to clone to ensure that we are not modifying another version
146147
version = semver(version.raw);
147148

148149
var jenkinsBuild = process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER;
150+
if (!version.prerelease || !version.prerelease.length) {
151+
// last release was a non beta release. Increment the patch level to
152+
// indicate the next release that we will be doing.
153+
// E.g. last release was 1.3.0, then the snapshot will be
154+
// 1.3.1-build.1, which is lesser than 1.3.1 accorind the semver!
155+
156+
// If the last release was a beta release we don't update the
157+
// beta number by purpose, as otherwise the semver comparison
158+
// does not work any more when the next beta is released.
159+
// E.g. don't generate 1.3.0-beta.2.build.1
160+
// as this is bigger than 1.3.0-beta.2 according to semver
161+
version.patch++;
162+
}
149163
version.prerelease = jenkinsBuild ? ['build', jenkinsBuild] : ['local'];
150164
version.build = getBuild();
151165
version.codeName = 'snapshot';

0 commit comments

Comments
 (0)