diff --git a/.travis.yml b/.travis.yml index 0522e92e9d..675a5d4a3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,12 @@ notifications: email: true before_script: + - git fetch --tags + - git fetch --unshallow + - export DESCRIBE=$(git describe) + - export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST + - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi) + - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH, DESCRIBE=$DESCRIBE" - chmod +x gradlew # ARM architecture is used instead of x86 (which is 10x faster) of the lack of support from CI due # to complications of creating a virtual machine within a virtual machine. This may be solved diff --git a/VideoLocker/build.gradle b/VideoLocker/build.gradle index 3996d91479..20d61e5f69 100644 --- a/VideoLocker/build.gradle +++ b/VideoLocker/build.gradle @@ -29,7 +29,6 @@ apply plugin: 'com.android.application' apply plugin: 'newrelic' apply plugin: 'com.facebook.testing.screenshot' apply from: 'jacoco.gradle' -apply from: 'version.gradle' repositories { mavenCentral() @@ -50,6 +49,74 @@ class AndroidHelper { } } } +/** + * Computes a semantic version string, e.g. "1.0" or "2.5.7" by parsing git branches or tags. + * Branch name takes priority, otherwise the last annotated tag name will be used. + * @return The semantic version string, or "0.0.1" if we failed to determine one. + */ +def getVersionName = { -> + def description = "0.0.1"; + try { + def branch = System.getenv("BRANCH") + if (null == branch || branch.isEmpty()) { + def branchout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD' + standardOutput = branchout + } + branch = branchout.toString().trim() + } + + def hasSemanticVersion = { s -> + // This branch/tag contains a semantic version (e.g. "rc/2.6.0" or "release/2.5") + return s.indexOf("rc/") >= 0 || s.indexOf("release/") >= 0 + } + if (hasSemanticVersion(branch)) { + description = branch; + } else { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe' + standardOutput = stdout + } + def describe = stdout.toString().trim() + if (hasSemanticVersion(describe)) { + description = describe; + } + } + } + catch (e) { + logger.error("Could not determine version name", e) + } + return description.substring(description.indexOf("/") + 1).split("-")[0].trim() +} + +/** + * @return An integer representation of the string returned by getVersionName() + */ +def getVersionCode = { -> + try { + def versionName = getVersionName() + def semVer = versionName.split('\\.') + def vCode; + vCode = semVer[0].toInteger() * 1000000 // Major version + if (semVer.length > 1) { + vCode += semVer[1].toInteger() * 1000 // Minor version + if (semVer.length > 2) { + vCode += semVer[2].toInteger() * 1 // Patch version + } + } + return vCode + } catch (e) { + logger.error("Could not determine version code", e) + return 1; + } +} + +task(version) << { + println String.format('%s (%s)', getVersionName(), getVersionCode()) +} + dependencies { compile project (':android-iconify') diff --git a/VideoLocker/version.gradle b/VideoLocker/version.gradle deleted file mode 100644 index 8172632aa3..0000000000 --- a/VideoLocker/version.gradle +++ /dev/null @@ -1,66 +0,0 @@ -// Methods for determining version code / version name from Git branches and tags - -/** - * Computes a semantic version string, e.g. "1.0" or "2.5.7" by parsing git branches or tags. - * Branch name takes priority, otherwise the last annotated tag name will be used. - * @return The semantic version string, or "0.0.1" if we failed to determine one. - */ -def getVersionName = { -> - def description = "0.0.1"; - try { - def branchout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD' - standardOutput = branchout - } - def branch = branchout.toString().trim() - - def hasSemanticVersion = { s -> - // This branch/tag contains a semantic version (e.g. "rc/2.6.0" or "release/2.5") - return s.indexOf("rc/") >= 0 || s.indexOf("release/") >= 0 - } - if (hasSemanticVersion(branch)) { - description = branch; - } else { - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'describe' - standardOutput = stdout - } - def describe = stdout.toString().trim() - if (hasSemanticVersion(describe)) { - description = describe; - } - } - } - catch (e) { - logger.error("Could not determine version name", e) - } - return description.substring(description.indexOf("/") + 1).split("-")[0].trim() -} - -/** - * @return An integer representation of the string returned by getVersionName() - */ -def getVersionCode = { -> - try { - def versionName = getVersionName() - def semVer = versionName.split('\\.') - def vCode; - vCode = semVer[0].toInteger() * 1000000 // Major version - if (semVer.length > 1) { - vCode += semVer[1].toInteger() * 1000 // Minor version - if (semVer.length > 2) { - vCode += semVer[2].toInteger() * 1 // Patch version - } - } - return vCode - } catch (e) { - logger.error("Could not determine version code", e) - return 1; - } -} - -task(version) << { - println String.format('%s (%s)', getVersionName(), getVersionCode()) -}