Skip to content

Commit

Permalink
chore(pipeline): rework release pipeline
Browse files Browse the repository at this point in the history
SUITEDEV-35237

Co-authored-by: davidSchuppa <[email protected]>
  • Loading branch information
megamegax and davidSchuppa committed Feb 29, 2024
1 parent 50ae24d commit 96779c1
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 122 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 \
Expand All @@ -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
37 changes: 33 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -67,4 +83,17 @@ tasks {
}
}
}
}
}


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")
}
}
}
4 changes: 4 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
implementation(project(":core-api"))

Expand Down
2 changes: 2 additions & 0 deletions core-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions emarsys-firebase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
implementation(project(":core-api"))
Expand Down
1 change: 1 addition & 0 deletions emarsys-huawei/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.kapt)
// alias(libs.plugins.huawei.agconnect)
}
apply(from = "../gradle/release.gradle")

dependencies {
implementation(project(":core-api"))
Expand Down
1 change: 1 addition & 0 deletions emarsys-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
api(project(":core-api"))
Expand Down
1 change: 1 addition & 0 deletions emarsys/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
api(project(":core-api"))
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
171 changes: 64 additions & 107 deletions gradle/release.gradle
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Expand All @@ -108,17 +76,6 @@ modules.each {
}
}

nexusPublishing {
packageGroup = "com.emarsys"
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
}
}
}

signing {
sign publishing.publications
}
1 change: 1 addition & 0 deletions mobile-engage-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
implementation(project(":core-api"))
Expand Down
1 change: 1 addition & 0 deletions mobile-engage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.kapt)
}
apply(from = "../gradle/release.gradle")

dependencies {
implementation(project(":common"))
Expand Down
Loading

0 comments on commit 96779c1

Please sign in to comment.