From fe0e434a87be433bce69b46031b3ef2c379ce353 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 12 Mar 2014 15:19:48 -0700 Subject: chore(version-info): use remote tags and increment patch version --- lib/grunt/utils.js | 1 - lib/versions/version-info.js | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 59b78381..b25a4555 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -4,7 +4,6 @@ var shell = require('shelljs'); var grunt = require('grunt'); var spawn = require('child_process').spawn; var semver = require('semver'); -var versionInfo = require('../versions/version-info'); var _ = require('lodash'); diff --git a/lib/versions/version-info.js b/lib/versions/version-info.js index 90175fc9..5bf06585 100644 --- a/lib/versions/version-info.js +++ b/lib/versions/version-info.js @@ -100,7 +100,10 @@ var isStable = function(version) { * @return {Array.} The collection of previous versions */ var getPreviousVersions = function() { - var tagResults = shell.exec('git tag', {silent: true}); + // always use the remote tags as the local clone might + // not contain all commits when cloned with git clone --depth=... + // Needed e.g. for Travis + var tagResults = shell.exec('git ls-remote --tags | grep -o -e "v[0-9].*[0-9]$"', {silent: true}); if ( tagResults.code === 0 ) { return _(tagResults.output.trim().split('\n')) .map(function(tag) { @@ -129,7 +132,6 @@ var getPreviousVersions = function() { * @return {SemVer} The snapshot version */ var getSnapshotVersion = function() { - version = _(previousVersions) .filter(function(tag) { return semver.satisfies(tag, currentPackage.branchVersion); @@ -137,15 +139,27 @@ var getSnapshotVersion = function() { .last(); if ( !version ) { - throw new Error("No valid versions can be found that match the current branch (" + - currentPackage.branchVersion + ").\n" + - "Try running `git fetch -t` to download the tags from the repository."); + // a snapshot version before the first tag on the branch + version = semver(currentPackage.branchVersion.replace('*','0-beta.1')); } // We need to clone to ensure that we are not modifying another version version = semver(version.raw); var jenkinsBuild = process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER; + if (!version.prerelease || !version.prerelease.length) { + // last release was a non beta release. Increment the patch level to + // indicate the next release that we will be doing. + // E.g. last release was 1.3.0, then the snapshot will be + // 1.3.1-build.1, which is lesser than 1.3.1 accorind the semver! + + // If the last release was a beta release we don't update the + // beta number by purpose, as otherwise the semver comparison + // does not work any more when the next beta is released. + // E.g. don't generate 1.3.0-beta.2.build.1 + // as this is bigger than 1.3.0-beta.2 according to semver + version.patch++; + } version.prerelease = jenkinsBuild ? ['build', jenkinsBuild] : ['local']; version.build = getBuild(); version.codeName = 'snapshot'; -- cgit v1.2.3