niqdev/ipcam-view

Use travis to release new versions of the library

amadeu01 opened this issue · 3 comments

We can add the script below to gradle. So, the Travis will give the right version for the library when it deploys to GitHub and/or other repositories.

def getVersionCode = { ->
  try {
    def code = new ByteArrayOutputStream()
    exec {
      commandLine 'git', 'rev-list', 'HEAD', '--count'
      standardOutput = code
    }
    return Integer.parseInt(code.toString().trim())
  } catch (exception) {
    return "1";
  }
}

// Version name is Last Tag Name + No. of commits form last Tag +  short git sha
def getVersionName = { ->
  try {
    def stdout = new ByteArrayOutputStream()
    exec {
      commandLine 'git', 'describe', '--tags', '--dirty'
      standardOutput = stdout
    }
    return stdout.toString().trim()
  } catch (exception) {
    return "0.0.0.1";
  }
}

// Use
android{
  defaultConfig {
    ...
    versionCode getVersionCode()
    versionName getVersionName()
    ...
  }
}

I was reviewing this, not sure if I get it correctly, could you tell me how should I use it properly?

The tags are related to the app in the store, not the lib

App version, see here

versionCode 9
versionName "1.6.0"

Lib version, see here

# ignored
versionCode 1
# e.g. version = '1.3.2' in main build.gradle
versionName project.version

Probably the main build.gradle version is a bit confusing and could be removed

@niqdev Sorry for my really late response. I completely forgot to answer you.

What those functions will do are take the number of commit to the HEAD and use it as the versionCode, in other words, it will increase the number of the versionCode by the number of commits. Then, it will take the versionName from the tag name.

We could use the same versionName and versionCode for the app sample and the library, once they run together, even when we change the library and do not change the app, we had changed something that impacts on the app, so the version of that app has something different from the previous version, even though its code hasn't changed.

Got it, you want to uniform the version of the lib and the app!