Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #774 from edx/bguertin/git_versioning
Browse files Browse the repository at this point in the history
Use Git branches/tags for versioning
  • Loading branch information
Brian @ edX committed Jul 20, 2016
2 parents 00a1787 + 132f486 commit b6a5dcb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ notifications:
email: true

before_script:
- git fetch --tags
- git fetch --unshallow || true
- 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
Expand Down
72 changes: 70 additions & 2 deletions VideoLocker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,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')
Expand Down Expand Up @@ -168,8 +236,8 @@ android {
minSdkVersion 14
targetSdkVersion 21

versionCode 90
versionName "2.6.0"
versionCode getVersionCode()
versionName getVersionName()

renderscriptTargetApi 22
renderscriptSupportModeEnabled true
Expand Down

0 comments on commit b6a5dcb

Please sign in to comment.