Skip to content

Instantly share code, notes, and snippets.

@paramsen
Last active January 17, 2024 08:17
Show Gist options
  • Save paramsen/4a92c9230d799caeb3b90897da27a80c to your computer and use it in GitHub Desktop.
Save paramsen/4a92c9230d799caeb3b90897da27a80c to your computer and use it in GitHub Desktop.

Revisions

  1. paramsen revised this gist Feb 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion build.groovy
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Generate a minor version code from git commit count (ideally for prod builds in small scale projects)
    // Generate a minor version code from git commit count (for prod builds)

    static def generateVersionCode() {
    def result = "git rev-list HEAD --count".execute().text.trim() //unix
  2. paramsen revised this gist Feb 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion build.groovy
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,6 @@ def majorVersion = 1
    android {
    defaultConfig {
    versionCode generateVersionCode()
    versionName "${majorVersion}.${getVersionCode()}"
    versionName "${majorVersion}.${generateVersionCode()}"
    }
    }
  3. paramsen revised this gist Feb 21, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions build.groovy
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // Generate a minor version code from git commit count
    // Generate a minor version code from git commit count (ideally for prod builds in small scale projects)

    static def getVersionCode() {
    static def generateVersionCode() {
    def result = "git rev-list HEAD --count".execute().text.trim() //unix
    if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() //windows
    if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
    @@ -11,7 +11,7 @@ def majorVersion = 1

    android {
    defaultConfig {
    versionCode getVersionCode()
    versionCode generateVersionCode()
    versionName "${majorVersion}.${getVersionCode()}"
    }
    }
  4. paramsen revised this gist Feb 21, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions build.groovy
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    // Generate a minor version code from git commit count

    static def getVersionCode() {
    def result = "git rev-list HEAD | wc -l".execute().text.trim() //unix
    if(result.empty) result = "PowerShell -Command git rev-list HEAD | wc -l".execute().text.trim() //windows
    def result = "git rev-list HEAD --count".execute().text.trim() //unix
    if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() //windows
    if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
    return result.toInteger()
    }
  5. paramsen created this gist Feb 21, 2018.
    17 changes: 17 additions & 0 deletions build.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Generate a minor version code from git commit count

    static def getVersionCode() {
    def result = "git rev-list HEAD | wc -l".execute().text.trim() //unix
    if(result.empty) result = "PowerShell -Command git rev-list HEAD | wc -l".execute().text.trim() //windows
    if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
    return result.toInteger()
    }

    def majorVersion = 1

    android {
    defaultConfig {
    versionCode getVersionCode()
    versionName "${majorVersion}.${getVersionCode()}"
    }
    }