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

Commit

Permalink
Use direct request to GitHub's API to get versionCode, since Travis d…
Browse files Browse the repository at this point in the history
…oes a shallow clone of the repo.
  • Loading branch information
pazaan committed Jul 24, 2017
1 parent 32dff64 commit bb2f067
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.ajoberstar.grgit.Grgit
import groovy.json.JsonSlurper

buildscript {
repositories {
Expand All @@ -10,6 +11,7 @@ buildscript {
classpath 'io.fabric.tools:gradle:1.22.2'
classpath 'io.realm:realm-gradle-plugin:3.4.0'
classpath 'org.ajoberstar:grgit:1.5.0'
classpath 'org.codehaus.groovy:groovy-json:2.4.12'
}
}
plugins {
Expand All @@ -27,13 +29,12 @@ apply plugin: 'io.fabric'
apply plugin: 'realm-android'

def generateVersionCode() {
// current dir is <your proj>/app, so it's likely that all your git repo files are in the dir
// above.
ext.repo = Grgit.open()
// We need to get the number of releases directly from GitHub, since Travis
// does a "git clone --depth=50", meaning we don't get all the tags locally.
String url = "https://api.github.com/repos/pazaan/600SeriesAndroidUploader/releases"
def json = new JsonSlurper().parseText(url.toURL().text)

// should result in the same value as running
// git tag -l | wc -l or git tag -l | grep -c ".*" -
def numOfTags = ext.repo.tag.list().size()
def numOfTags = json.size() + 1
logger.warn("Generated Version Code: " + numOfTags)
return numOfTags
}
Expand Down

0 comments on commit bb2f067

Please sign in to comment.