Skip to content

Commit

Permalink
add bump script
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Sep 25, 2023
1 parent 0b83e0b commit 59e4216
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 10 deletions.
5 changes: 5 additions & 0 deletions posthog-v3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ plugins {
id("com.diffplug.spotless") version PosthogBuildConfig.Plugins.SPOTLESS apply true
id("io.gitlab.arturbosch.detekt") version PosthogBuildConfig.Plugins.DETEKT apply true
id("org.jetbrains.kotlinx.binary-compatibility-validator") version PosthogBuildConfig.Plugins.API_VALIDATOR apply true
id("com.github.gmazzo.buildconfig") version PosthogBuildConfig.Plugins.BUILD_CONFIG apply false

// TODO: add jacoco/codecov, gradle-versions-plugin
}

allprojects {
version = properties[PostHogPublishConfig.versionNameProperty].toString()
}

subprojects {
apply(plugin = "org.jetbrains.dokka")
}
Expand Down
8 changes: 6 additions & 2 deletions posthog-v3/buildSrc/src/main/java/PostHogPublishConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import org.gradle.kotlin.dsl.findByType
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.dokka.gradle.DokkaTask

object PostHogPublishConfig {
val versionNameProperty = "versionName"
}

fun Project.publishingAndroidConfig() {
val projectName = name

Expand Down Expand Up @@ -66,7 +70,7 @@ fun MavenPom.postHogConfig(projectName: String, repo: String = "posthog-android"
licenses {
license {
name.set("MIT")
url.set("https://github.com/PostHog/$repo/blob/master/LICENSE.md")
url.set("http://opensource.org/licenses/MIT")
}
}
organization {
Expand All @@ -92,7 +96,7 @@ fun MavenPom.postHogConfig(projectName: String, repo: String = "posthog-android"
fun MavenPublication.postHogConfig(projectName: String, properties: Map<String, Any?>) {
groupId = "com.posthog"
artifactId = projectName
version = properties["versionName"].toString()
version = properties[PostHogPublishConfig.versionNameProperty].toString()
}

fun SigningExtension.postHogConfig(variantName: String, publishingExtension: PublishingExtension?) {
Expand Down
1 change: 1 addition & 0 deletions posthog-v3/buildSrc/src/main/java/PosthogBuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ object PosthogBuildConfig {
val SPOTLESS = "6.21.0"
val DETEKT = "1.23.1"
val API_VALIDATOR = "0.13.2"
val BUILD_CONFIG = "4.1.2"
}
}
2 changes: 1 addition & 1 deletion posthog-v3/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ android.defaults.buildfeatures.aidl=false
android.defaults.buildfeatures.resvalues=false

# Release
versionName=3.0.0
versionName=3.0.0-alpha.1
1 change: 1 addition & 0 deletions posthog-v3/posthog-android/api/posthog-android.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public final class com/posthog/android/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
public fun <init> ()V
}

Expand Down
2 changes: 2 additions & 0 deletions posthog-v3/posthog-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ android {
buildFeatures {
buildConfig = true
}

buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class PostHogAndroid private constructor() {
val preferences = config.cachePreferences ?: PostHogSharedPreferences(context, config)
config.cachePreferences = preferences
config.networkStatus = config.networkStatus ?: PostHogAndroidNetworkStatus(context)
config.sdkVersion = BuildConfig.VERSION_NAME

if (context is Application) {
config.integrations.add(PostHogActivityLifecycleCallback(context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ internal class PostHogAndroidContext(private val context: Context, private val c
staticContext["\$app_version"] = name
}
staticContext["\$app_namespace"] = it.packageName
// TODO: is it string instead?
staticContext["\$app_build"] = it.versionCodeCompat()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class PostHogAppInstallIntegration(private val context: Context, privat
preferences.setValue("version", versionName)
preferences.setValue("build", versionCode)

// TODO: do we need ot send an event every time as an update? we need to compare the Ids maybe?
// TODO: do we need to send an event every time as an update? we need to compare the Ids maybe?
// maybe it didnt change
PostHog.capture(event, properties = props)
}
Expand Down
1 change: 0 additions & 1 deletion posthog-v3/posthog/api/posthog.api
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public final class com/posthog/PostHogConfig {
public final fun setNetworkStatus (Lcom/posthog/internal/PostHogNetworkStatus;)V
public final fun setOptOut (Z)V
public final fun setPreloadFeatureFlags (Z)V
public final fun setSdkName (Ljava/lang/String;)V
public final fun setSdkVersion (Ljava/lang/String;)V
public final fun setSendFeatureFlagEvent (Z)V
public final fun setStoragePrefix (Ljava/lang/String;)V
Expand Down
7 changes: 7 additions & 0 deletions posthog-v3/posthog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ plugins {
`maven-publish`
signing
id("org.jetbrains.dokka")

// plugins
id("com.github.gmazzo.buildconfig")
}

configure<JavaPluginExtension> {
sourceCompatibility = PosthogBuildConfig.Build.JAVA_VERSION
targetCompatibility = PosthogBuildConfig.Build.JAVA_VERSION
}

buildConfig {
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
Expand Down
9 changes: 5 additions & 4 deletions posthog-v3/posthog/src/main/java/com/posthog/PostHogConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.posthog

import PostHog.posthog.BuildConfig
import com.posthog.internal.PostHogNetworkStatus

public class PostHogConfig(
Expand Down Expand Up @@ -27,16 +28,16 @@ public class PostHogConfig(
@PostHogInternal
public var context: PostHogContext? = null

// TODO: read the repo name and version
@PostHogInternal
public var sdkName: String = "posthog-android"
public val sdkName: String = "posthog-android"

@PostHogInternal
public var sdkVersion: String = "3.0.0"
public var sdkVersion: String = BuildConfig.VERSION_NAME

internal val userAgent: String = "$sdkName/$sdkVersion"

// should this be configurable by the user?
// TODO: should this be configurable by the user?
// should we allow in memory cache only?
@PostHogInternal
public var legacyStoragePrefix: String? = null

Expand Down
17 changes: 17 additions & 0 deletions posthog-v3/scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# ./scripts/bump-version.sh <new version>
# eg ./scripts/bump-version.sh "3.0.0-alpha.1"

set -eux

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR/..

NEW_VERSION="$1"

GRADLE_FILEPATH="gradle.properties"

# Replace `versionName` with the given version
VERSION_NAME_PATTERN="versionName"
perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $GRADLE_FILEPATH

0 comments on commit 59e4216

Please sign in to comment.