Skip to content

Commit 8116c60

Browse files
abdulraqeeb33AR Abdul Azeez
andauthored
ci: Centralize SDK version (#2362)
* Version Bump Workflow * renamed the file * Update version-bump.yml test branch * Update version-bump.yml Update path * fix order * fix typo * Update version-bump.yml Delete branch if it exists * cat files * Update version-bump.yml branch name * Update gradle.properties test * Update version-bump.yml fix branch name * fixed branch names * test branch name * cleanup * changed it back to main * cleanup * ktlint check * Cleanup * New link e * Gather summaries * Warning message when no commits present * Cleaned up based on feedback * trigger on branch * test from local * Fail to build if version number not present * added documentation * Added more checks --------- Co-authored-by: AR Abdul Azeez <[email protected]>
1 parent 43df4f7 commit 8116c60

File tree

14 files changed

+178
-14
lines changed

14 files changed

+178
-14
lines changed

Examples/OneSignalDemo/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ dependencies {
8585
implementation 'com.github.bumptech.glide:glide:4.12.0'
8686

8787
/** START - Google Play Builds **/
88-
gmsImplementation('com.onesignal:OneSignal:5.1.37')
88+
gmsImplementation("com.onesignal:OneSignal:$SDK_VERSION")
8989
/** END - Google Play Builds **/
9090

9191
/** START - Huawei Builds **/
9292
// Omit Google / Firebase libraries for Huawei builds.
93-
huaweiImplementation('com.onesignal:OneSignal:5.1.37') {
93+
huaweiImplementation("com.onesignal:OneSignal:$SDK_VERSION") {
9494
exclude group: 'com.google.android.gms', module: 'play-services-gcm'
9595
exclude group: 'com.google.android.gms', module: 'play-services-analytics'
9696
exclude group: 'com.google.android.gms', module: 'play-services-location'

Examples/OneSignalDemo/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ allprojects {
3030
}
3131
}
3232

33+
subprojects {
34+
ext.SDK_VERSION = rootProject.findProperty("SDK_VERSION") ?: "x.x.x"
35+
}
36+
3337
task clean(type: Delete) {
3438
delete rootProject.buildDir
3539
}

Examples/OneSignalDemo/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
org.gradle.jvmargs=-Xmx1536m
1515
android.useAndroidX=true
1616
android.enableJetifier=false
17+
18+
# This is the name of the SDK to use when building your project.
19+
# This will be fed from the GitHub Actions workflow.
20+
SDK_VERSION=5.1.37

OneSignalSDK/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ android.enableD8 = true
3030

3131
# Android X settings
3232
android.useAndroidX = true
33+
34+
# This is the name of the SDK to use when building your project.
35+
# This will be fed from the GitHub Actions workflow.
36+
SDK_VERSION=5.1.37

OneSignalSDK/onesignal/core/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ android {
1111
minSdkVersion rootProject.buildVersions.minSdkVersion
1212
consumerProguardFiles "consumer-rules.pro"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
buildConfigField "String", "SDK_VERSION", "\"${rootProject.version}\""
15+
}
16+
17+
buildFeatures {
18+
buildConfig = true
1419
}
1520

1621
buildTypes {

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/OneSignalUtils.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
package com.onesignal.common
22

3+
import com.onesignal.core.BuildConfig
34
import java.util.regex.Pattern
45

56
object OneSignalUtils {
67
/**
7-
* The version of this SDK.
8+
* The version of this SDK. This is being formatted to ensure proper sorting when used in
9+
* User-Agent strings and other uses where lexicographical order matters.
10+
* Its being picked up from the Gradle build config field `SDK_VERSION`.
11+
* Also its calculated lazily once when first accessed and then cached after that.
812
*/
9-
const val SDK_VERSION: String = "050137"
13+
val sdkVersion: String by lazy {
14+
formatVersion(BuildConfig.SDK_VERSION)
15+
}
16+
17+
/**
18+
* Formats a version string to ensure proper lexicographical sorting.
19+
* For example, "1.2.3-beta" becomes "010203-beta", "1.20.3" becomes "010203".
20+
*/
21+
internal fun formatVersion(version: String): String {
22+
val parts = version.split("-", limit = 2)
23+
val base = parts[0].split(".")
24+
val major = base.getOrNull(0)?.padStart(2, '0') ?: "00"
25+
val minor = base.getOrNull(1)?.padStart(2, '0') ?: "00"
26+
val patch = base.getOrNull(2)?.padStart(2, '0') ?: "00"
27+
val formatted = "$major$minor$patch"
28+
return if (parts.size > 1) formatted + "-" + parts[1] else formatted
29+
}
1030

1131
fun isValidEmail(email: String): Boolean {
1232
if (email.isEmpty()) {

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/http/impl/HttpClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ internal class HttpClient(
135135
con.useCaches = false
136136
con.connectTimeout = timeout
137137
con.readTimeout = timeout
138-
con.setRequestProperty("SDK-Version", "onesignal/android/" + OneSignalUtils.SDK_VERSION)
138+
con.setRequestProperty("SDK-Version", "onesignal/android/" + OneSignalUtils.sdkVersion)
139139

140140
if (OneSignalWrapper.sdkType != null && OneSignalWrapper.sdkVersion != null) {
141141
con.setRequestProperty("SDK-Wrapper", "onesignal/${OneSignalWrapper.sdkType}/${OneSignalWrapper.sdkVersion}")

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import com.onesignal.user.internal.subscriptions.SubscriptionType
5353
import org.json.JSONObject
5454

5555
internal class OneSignalImp : IOneSignal, IServiceProvider {
56-
override val sdkVersion: String = OneSignalUtils.SDK_VERSION
56+
override val sdkVersion: String = OneSignalUtils.sdkVersion
5757
override var isInitialized: Boolean = false
5858

5959
override var consentRequired: Boolean
@@ -300,7 +300,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
300300
pushSubscriptionModel.status = SubscriptionStatus.SUBSCRIBED
301301
}
302302

303-
pushSubscriptionModel.sdk = OneSignalUtils.SDK_VERSION
303+
pushSubscriptionModel.sdk = OneSignalUtils.sdkVersion
304304
pushSubscriptionModel.deviceOS = Build.VERSION.RELEASE
305305
pushSubscriptionModel.carrier = DeviceUtils.getCarrierName(
306306
services.getService<IApplicationService>().appContext,
@@ -472,7 +472,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
472472
newPushSubscription.optedIn = currentPushSubscription?.optedIn ?: true
473473
newPushSubscription.address = currentPushSubscription?.address ?: ""
474474
newPushSubscription.status = currentPushSubscription?.status ?: SubscriptionStatus.NO_PERMISSION
475-
newPushSubscription.sdk = OneSignalUtils.SDK_VERSION
475+
newPushSubscription.sdk = OneSignalUtils.sdkVersion
476476
newPushSubscription.deviceOS = Build.VERSION.RELEASE
477477
newPushSubscription.carrier = DeviceUtils.getCarrierName(services.getService<IApplicationService>().appContext) ?: ""
478478
newPushSubscription.appVersion = AndroidUtils.getAppVersion(services.getService<IApplicationService>().appContext) ?: ""

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/LoginUserOperationExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ internal class LoginUserOperationExecutor(
296296
operation.address,
297297
operation.enabled,
298298
operation.status.value,
299-
OneSignalUtils.SDK_VERSION,
299+
OneSignalUtils.sdkVersion,
300300
Build.MODEL,
301301
Build.VERSION.RELEASE,
302302
RootToolsInternalMethods.isRooted,

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/SubscriptionOperationExecutor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal class SubscriptionOperationExecutor(
9898
address,
9999
enabled,
100100
status.value,
101-
OneSignalUtils.SDK_VERSION,
101+
OneSignalUtils.sdkVersion,
102102
Build.MODEL,
103103
Build.VERSION.RELEASE,
104104
RootToolsInternalMethods.isRooted,
@@ -181,7 +181,7 @@ internal class SubscriptionOperationExecutor(
181181
lastOperation.address,
182182
lastOperation.enabled,
183183
lastOperation.status.value,
184-
OneSignalUtils.SDK_VERSION,
184+
OneSignalUtils.sdkVersion,
185185
Build.MODEL,
186186
Build.VERSION.RELEASE,
187187
RootToolsInternalMethods.isRooted,

0 commit comments

Comments
 (0)