Skip to content

Commit

Permalink
Allow applicationId from CI config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiaan de Die le Clercq committed Aug 28, 2020
1 parent 4aa96c0 commit 95ae12e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}
}
dependencies {
classpath 'nl.uncinc.androidci:UncIncAndroidCI:0.2'
classpath 'nl.uncinc.androidci:UncIncAndroidCI:0.3'
}
}
```
Expand All @@ -27,13 +27,14 @@ apply plugin: 'nl.uncinc.androidci'
```
android {
defaultConfig {
versionCode project.ext.androidciconfig.getVersionCode()
versionName project.ext.androidciconfig.getVersionName()
applicationId project.ext.androidci.getApplicationId("nl.uncinc.demo")
versionCode project.ext.androidci.getVersionCode()
versionName project.ext.androidci.getVersionName()
}
buildTypes {
release {
signingConfig project.ext.androidciconfig.getSigningConfig(project)
signingConfig project.ext.androidci.getSigningConfig()
}
}
}
Expand All @@ -51,11 +52,12 @@ storeFile=/Full/Path/To/keystore.jks
```

# Possible properties
| Property | Purpose | Default Value |
|-----------------------------|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| androidci.signingProperties | Full path to the file with the signing configuration. Should be available to CI. | android-app-signing.properties (and if it does not exist. The Debug build key) |
| androidci.versionCode | Android versionCode, use an Integer value | 1 |
| androidci.versionName | Android versionName, should be a String | Git hash of the repo |
| Property | Purpose | Default Value |
|-----------------------------|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| androidci.signingProperties | Full path to the file with the signing configuration. Should be available to CI. | android-app-signing.properties (and if it does not exist. The Debug build key) |
| androidci.versionCode | Android versionCode, use an Integer value | 1 |
| androidci.versionName | Android versionName, should be a String | Git hash of the repo |
| androidci.applicationId | Override for application identifier, for multiple app flavours (e.g. Beta release) | Parameter given in the android defaultConfig |

# License
MIT License
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'nl.uncinc.androidci'
version '0.2'
version '0.3'
sourceCompatibility = 1.8

repositories {
Expand Down
32 changes: 24 additions & 8 deletions src/main/groovy/nl/uncinc/androidci/UncIncAndroidCIPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import org.gradle.api.Project

class UncIncAndroidCIPlugin implements Plugin<Project> {
def androidci = new Properties()
Project project

void apply(Project project) {
this.project = project

androidci.signingProperies = project.hasProperty('androidci.signingProperties')
? project.getProperty('androidci.signingProperties') : 'android-app-signing.properties'
androidci.versionCode = project.hasProperty('androidci.versionCode')
? project.getProperty('androidci.versionCode') as Integer : 1
androidci.versionName = project.hasProperty('androidci.versionName')
? project.getProperty('androidci.versionName') : getGitHash()

androidci.signingProperies = project.hasProperty('androidci.signingProperties') ? project.getProperty('androidci.signingProperties') : 'android-app-signing.properties'
androidci.versionCode = project.hasProperty('androidci.versionCode') ? project.getProperty('androidci.versionCode') as Integer : 1
androidci.versionName = project.hasProperty('androidci.versionName') ? project.getProperty('androidci.versionName') : getGitHash(project)
def keystoreProperties = new Properties()

if (project.file(androidci.signingProperies).exists()) {
Expand All @@ -23,7 +29,8 @@ class UncIncAndroidCIPlugin implements Plugin<Project> {
keystoreProperties.setProperty("storeFileType", 'jks')
}
} else {
project.logger.error("No release build via CI currently or signing properties file not found. Defaulting to debug keystore for CI configuration.")
project.logger.error("No release build via CI currently or signing properties file not found." +
" Defaulting to debug keystore for CI configuration.")
keystoreProperties.setProperty("keyAlias", 'androiddebugkey')
keystoreProperties.setProperty("keyPassword", 'android')
keystoreProperties.setProperty("storePassword", 'android')
Expand All @@ -32,26 +39,35 @@ class UncIncAndroidCIPlugin implements Plugin<Project> {

}
androidci.keystoreProperties = keystoreProperties
project.ext.androidciconfig = this

// Expose this class to the project
project.ext.androidci = this

project.task('printAndroidCIVars') {
doLast {
println 'Signing: ' + androidci.signingProperies
println 'versionCode: ' + androidci.versionCode
println 'versionName: ' + androidci.versionName
println 'androidApplicationId': + androidci.applicationId
}
}
}

Integer getVersionCode() {
return androidci.versionCode
return androidci.versionCode as Integer
}

String getVersionName() {
return androidci.versionName
}

SigningConfig getSigningConfig(Project project) {
String getApplicationId(String appId) {
androidci.applicationId = project.hasProperty('androidci.applicationId')
? project.getProperty('androidci.applicationId') : appId
return androidci.applicationId
}

SigningConfig getSigningConfig() {
def signingConfig = new SigningConfig("CIStore")
signingConfig.storeFile = project.file(androidci.keystoreProperties['storeFile'])
signingConfig.storePassword = androidci.keystoreProperties['storePassword']
Expand All @@ -60,7 +76,7 @@ class UncIncAndroidCIPlugin implements Plugin<Project> {
return signingConfig
}

String getGitHash(Project project) {
String getGitHash() {
def stdout = new ByteArrayOutputStream()
project.exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
Expand Down

0 comments on commit 95ae12e

Please sign in to comment.