diff --git a/.gitignore b/.gitignore index dff80d42..a649b16b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ firebase_service_account.json workflow.secrets mobile-team-android.jks.asc sample/mobile-team-android.jks -/mobile-team-android.jks +mobile-team-android.jks +secring.asc.gpg \ No newline at end of file diff --git a/Makefile b/Makefile index 8fc39f43..1c4298cb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: base64-secret-to-file build-test check-env help create-sample-release-bundle create-testing-apks lint prepare-ci run-github-workflow-locally test-android-firebase test-android-firebase-emulator +.PHONY: base64-secret-to-file build-test check-env help create-sample-release-bundle create-testing-apks lint prepare-ci run-github-workflow-locally test-android-firebase test-android-firebase-emulator release-to-sonatype .DEFAULT_GOAL := help SHELL := /bin/bash @@ -45,6 +45,11 @@ prepare-ci: check-env ## setup prerequisites for pipeline @echo $ANDROID_HOME > local.properties @./gradlew base64EnvToFile -PpropertyName=GOOGLE_SERVICES_JSON_BASE64 -Pfile=./sample/google-services.json +prepare-release: check-env ## setup prerequisites for release + @./gradlew base64EnvToFile -PpropertyName=SONATYPE_SIGNING_SECRET_KEY_RING_FILE_BASE64 -Pfile=./secring.asc.gpg + +prepare-sample-release-key: check-env + test-android-firebase-emulator: check-env ## run Android Instrumented tests on emulators on Firebase Test Lab @gcloud firebase test android run \ --type instrumentation \ @@ -68,3 +73,8 @@ test-android-firebase: check-env ## run Android Instrumented tests on real devic run-github-workflow-locally: check-env ## needs act to be installed: `brew install act` and docker running. Pass in workflow path to run @act --secret-file ./workflow.secrets -W $(WORKFLOW_PATH) --container-architecture linux/amd64 + +release: check-env prepare-release prepare-sample-release-key ## release to sonatype + @./gradlew assembleRelease && ./gradlew publishToSonatype +release-locally: check-env prepare-release prepare-sample-release-key ## release to mavenLocal + @./gradlew assembleRelease && ./gradlew publishToMavenLocal \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index d494d4bf..c87dec58 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,10 +15,19 @@ plugins { alias(libs.plugins.dotenv) alias(libs.plugins.ben.manes.versions) alias(libs.plugins.android.junit5) apply false + alias(libs.plugins.nexus.publish) + id("maven-publish") + id("signing") } versionData() +allprojects { + val sdkVersion: GitVersion by rootProject.extra + group = "com.emarsys" + version = sdkVersion.versionName +} + fun versionData() { val git = Grgit.open( mapOf("currentDir" to project.rootDir) @@ -44,10 +53,17 @@ fun versionData() { versionCodeTime = 0 ) } - val version by extra(v) + val sdkVersion by extra(v) + + ext["signing.keyId"] = + env.fetch("SONATYPE_SIGNING_KEY_ID") ?: System.getenv("SONATYPE_SIGNING_KEY_ID") + ext["signing.password"] = + env.fetch("SONATYPE_SIGNING_PASSWORD") ?: System.getenv("SONATYPE_SIGNING_PASSWORD") + ext["signing.secretKeyRingFile"] = "./secring.asc.gpg" - println("versionName: ${version.versionName}") - println("versionCode: ${version.versionCode}") + + println("versionName: ${sdkVersion.versionName}") + println("versionCode: ${sdkVersion.versionCode}") } tasks { @@ -67,4 +83,17 @@ tasks { } } } -} \ No newline at end of file +} + + +nexusPublishing { + packageGroup = "com.emarsys" + repositories { + sonatype { + stagingProfileId = env.fetch("SONATYPE_STAGING_PROFILE_ID") + ?: System.getenv("SONATYPE_STAGING_PROFILE_ID") + username = env.fetch("OSSRH_USERNAME") ?: System.getenv("OSSRH_USERNAME") + password = env.fetch("OSSRH_PASSWORD") ?: System.getenv("OSSRH_PASSWORD") + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ddb09cf0..3c4319bd 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,9 @@ plugins { id("org.jetbrains.kotlin.jvm") version "1.9.0" + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" + id("co.uzzu.dotenv.gradle") version "4.0.0" + id("maven-publish") + signing } repositories { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index ea6f251b..fc111d5e 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -4,6 +4,8 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") + dependencies { implementation(project(":core-api")) diff --git a/core-api/build.gradle.kts b/core-api/build.gradle.kts index 2c145d3b..ac452475 100644 --- a/core-api/build.gradle.kts +++ b/core-api/build.gradle.kts @@ -4,6 +4,8 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") + dependencies { api(libs.androidx.annotation) api(libs.androidx.appcompat) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index a8d73efd..e7d78556 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -4,6 +4,9 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") + +val sdkVersion: GitVersion by rootProject.extra dependencies { implementation(project(":core-api")) @@ -26,9 +29,9 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - val version: GitVersion by rootProject.extra - buildConfigField("int", "VERSION_CODE", "${version.versionCode}") - buildConfigField("String", "VERSION_NAME", "\"${version.versionName}\"") + val sdkVersion: GitVersion by rootProject.extra + buildConfigField("int", "VERSION_CODE", "${sdkVersion.versionCode}") + buildConfigField("String", "VERSION_NAME", "\"${sdkVersion.versionName}\"") } buildFeatures { diff --git a/emarsys-firebase/build.gradle.kts b/emarsys-firebase/build.gradle.kts index 6fe6968b..3d617710 100644 --- a/emarsys-firebase/build.gradle.kts +++ b/emarsys-firebase/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":core-api")) diff --git a/emarsys-huawei/build.gradle.kts b/emarsys-huawei/build.gradle.kts index acbe2feb..29c72344 100644 --- a/emarsys-huawei/build.gradle.kts +++ b/emarsys-huawei/build.gradle.kts @@ -5,6 +5,7 @@ plugins { alias(libs.plugins.kapt) // alias(libs.plugins.huawei.agconnect) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":core-api")) diff --git a/emarsys-sdk/build.gradle.kts b/emarsys-sdk/build.gradle.kts index 607a8cbc..f79b3426 100644 --- a/emarsys-sdk/build.gradle.kts +++ b/emarsys-sdk/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { api(project(":core-api")) diff --git a/emarsys/build.gradle.kts b/emarsys/build.gradle.kts index 0ff6eec1..93bb3421 100644 --- a/emarsys/build.gradle.kts +++ b/emarsys/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { api(project(":core-api")) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 43e6c50a..3ea4190b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -55,6 +55,7 @@ dotEnv = "4.0.0" android-tools-desugar = "2.0.4" benManesVersions = "0.51.0" android-junit5 = "1.10.0.0" +nexus-publish = "1.3.0" [libraries] androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" } @@ -130,3 +131,4 @@ grgit = { id = "org.ajoberstar.grgit", version.ref = "grGit" } dotenv = { id = "co.uzzu.dotenv.gradle", version.ref = "dotEnv" } ben-manes-versions = { id = "com.github.ben-manes.versions", version.ref = "benManesVersions" } android-junit5 = { id = "de.mannodermaus.android-junit5", version.ref = "android-junit5" } +nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" } diff --git a/gradle/release.gradle b/gradle/release.gradle index e43dc263..a229b8ab 100644 --- a/gradle/release.gradle +++ b/gradle/release.gradle @@ -1,104 +1,72 @@ -ext.modules = [':core-api', ':core', ':common', ':mobile-engage-api', ':mobile-engage', ':predict-api', ':predict', ':emarsys', ':emarsys-firebase', ':emarsys-huawei', ':emarsys-sdk'] - -apply plugin: 'maven-publish' -apply plugin: 'signing' -apply plugin: "io.github.gradle-nexus.publish-plugin" - - -def ossrhUsername = null -def ossrhPassword = null -def sonatypeStagingProfileId = null - -def localConfigPropertiesFile = rootProject.file('localConfig.properties') -def localConfigProperties = new Properties() -if (localConfigPropertiesFile.exists()) { - localConfigProperties.load(new FileInputStream(localConfigPropertiesFile)) - ossrhUsername = localConfigProperties.getProperty("ossrhUsername") - ossrhPassword = localConfigProperties.getProperty("ossrhPassword") - sonatypeStagingProfileId = localConfigProperties.getProperty("sonatypeStagingProfileId") - - ext["signing.keyId"] = localConfigProperties.getProperty("signingKeyId") - ext["signing.password"] = localConfigProperties.getProperty("signingPassword") - ext["signing.secretKeyRingFile"] = localConfigProperties.getProperty("signingSecretKeyRingFile") -} else { - ossrhUsername = System.env.OSSRH_USERNAME - ossrhPassword = System.env.OSSRH_PASSWORD - sonatypeStagingProfileId = System.env.SONATYPE_STAGING_PROFILE_ID - - ext["signing.keyId"] = System.env.SIGNING_KEYID - ext["signing.password"] = System.env.SIGNING_PASSWORD - ext["signing.secretKeyRingFile"] = System.env.SIGNING_SECRET_KEY_RING_FILE +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + archiveClassifier = 'sources' } -modules.each { - project(it) { - task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - archiveClassifier = 'sources' - } - - task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - failOnError false - } +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + failOnError false +} - task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier = 'javadoc' - from javadoc.destinationDir - } +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier = 'javadoc' + if (javadoc.destinationDir != null) { + from javadoc.destinationDir + } else { + println("Javadoc not found") + } +} - afterEvaluate { - publishing { - publications { - "${project.name}"(MavenPublication) { - groupId = group - artifactId = project.name - artifact sourcesJar - artifact javadocJar - artifact("$buildDir/outputs/aar/${project.name}-release.aar") - pom { - name = project.name - description = "${project.name} module of the EmarsysSDK" - url = 'https://github.com/emartech/android-emarsys-sdk' - licenses { - license { - name = 'Mozilla Public License 2.0' - url = 'https://github.com/emartech/android-emarsys-sdk/blob/master/LICENSE' - } - } - organization { - name = 'Emarsys' - url = 'https://emarsys.com' - } - developers { - developer { - organization = 'Emarsys' - organizationUrl = 'https://emarsys.com' - } - } - scm { - connection = 'scm:git:https://github.com/emartech/android-emarsys-sdk.git' - developerConnection = 'scm:git:https://github.com/emartech/android-emarsys-sdk.git' - url = 'https://github.com/emartech/android-emarsys-sdk' +afterEvaluate { + publishing { + publications { + "${project.name}"(MavenPublication) { + groupId = group + artifactId = project.name + artifact sourcesJar + artifact javadocJar + artifact("$buildDir/outputs/aar/${project.name}-release.aar") + pom { + name = project.name + description = "${project.name} module of the EmarsysSDK" + url = 'https://github.com/emartech/android-emarsys-sdk' + licenses { + license { + name = 'Mozilla Public License 2.0' + url = 'https://github.com/emartech/android-emarsys-sdk/blob/master/LICENSE' + } + } + organization { + name = 'Emarsys' + url = 'https://emarsys.com' + } + developers { + developer { + organization = 'Emarsys' + organizationUrl = 'https://emarsys.com' + } + } + scm { + connection = 'scm:git:https://github.com/emartech/android-emarsys-sdk.git' + developerConnection = 'scm:git:https://github.com/emartech/android-emarsys-sdk.git' + url = 'https://github.com/emartech/android-emarsys-sdk' + } + withXml { + def dependenciesNode = asNode().appendNode("dependencies") + configurations.getByName("api") { + dependencies.forEach { + def dependencyNode = dependenciesNode.appendNode("dependency") + dependencyNode.appendNode("groupId", it.group) + dependencyNode.appendNode("artifactId", it.name) + dependencyNode.appendNode("version", it.version) } - withXml { - def dependenciesNode = asNode().appendNode("dependencies") - configurations.getByName("api") { - dependencies.forEach { - def dependencyNode = dependenciesNode.appendNode("dependency") - dependencyNode.appendNode("groupId", it.group) - dependencyNode.appendNode("artifactId", it.name) - dependencyNode.appendNode("version", it.version) - } - } - configurations.getByName("implementation") { - dependencies.forEach { - def dependencyNode = dependenciesNode.appendNode("dependency") - dependencyNode.appendNode("groupId", it.group) - dependencyNode.appendNode("artifactId", it.name) - dependencyNode.appendNode("version", it.version) - } - } + } + configurations.getByName("implementation") { + dependencies.forEach { + def dependencyNode = dependenciesNode.appendNode("dependency") + dependencyNode.appendNode("groupId", it.group) + dependencyNode.appendNode("artifactId", it.name) + dependencyNode.appendNode("version", it.version) } } } @@ -108,17 +76,6 @@ modules.each { } } -nexusPublishing { - packageGroup = "com.emarsys" - repositories { - sonatype { - stagingProfileId = sonatypeStagingProfileId - username = ossrhUsername - password = ossrhPassword - } - } -} - signing { sign publishing.publications } \ No newline at end of file diff --git a/mobile-engage-api/build.gradle.kts b/mobile-engage-api/build.gradle.kts index 5438e861..be011a97 100644 --- a/mobile-engage-api/build.gradle.kts +++ b/mobile-engage-api/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":core-api")) diff --git a/mobile-engage/build.gradle.kts b/mobile-engage/build.gradle.kts index 7602e257..9bbc5dc3 100644 --- a/mobile-engage/build.gradle.kts +++ b/mobile-engage/build.gradle.kts @@ -5,6 +5,7 @@ plugins { alias(libs.plugins.kotlin.parcelize) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":common")) diff --git a/predict-api/build.gradle.kts b/predict-api/build.gradle.kts index d8b5ebe3..1776b6ae 100644 --- a/predict-api/build.gradle.kts +++ b/predict-api/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":core")) diff --git a/predict/build.gradle.kts b/predict/build.gradle.kts index 457ed8fa..13c5e116 100644 --- a/predict/build.gradle.kts +++ b/predict/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.kotlin.allopen) alias(libs.plugins.kapt) } +apply(from = "../gradle/release.gradle") dependencies { implementation(project(":core")) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index ef05d925..2cde2c0d 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -7,9 +7,9 @@ plugins { alias(libs.plugins.google.services) // alias(libs.plugins.huawei.agconnect) } - +val sdkVersion: GitVersion by rootProject.extra group = "com.emarsys.sample" - +version = sdkVersion.versionName android { namespace = "com.emarsys.sample" defaultConfig { @@ -22,12 +22,11 @@ android { targetSdk = libs.versions.android.targetSdk.get().toInt() } multiDexEnabled = true - val version: GitVersion by rootProject.extra - versionCode = version.versionCode - versionName = version.versionName + versionCode = sdkVersion.versionCode + versionName = sdkVersion.versionName testInstrumentationRunner = "com.emarsys.sample.testutils.SampleAppTestRunner" - resValue("string", "sdk_version", version.versionName) + resValue("string", "sdk_version", sdkVersion.versionName) buildConfigField( "String", "GOOGLE_OAUTH_SERVER_CLIENT_ID",