Skip to content

Commit

Permalink
Add version to jar manifest and read at runtime for SDK version header (
Browse files Browse the repository at this point in the history
#22)

Add version to the jar manifest and read from that to send the SDK version header

https://docs.gradle.org/current/samples/sample_building_kotlin_libraries.html#customize_the_library_jar

https://stackoverflow.com/a/43065467

To avoid unnecessarily reading from the manifest file, we store the value in a companion object which
should have the effect of making it a singleton.

An alternative using java properties was considered based on https://stackoverflow.com/a/70088083, but
the jar manifest seemed more appropriate
  • Loading branch information
albertchae authored Feb 24, 2024
1 parent aa95363 commit 79a0220
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions inngest-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
description = "Inngest SDK"
version = "0.0.1-SNAPSHOT"

plugins { id("org.jetbrains.kotlin.jvm") version "1.9.10" }

Expand All @@ -17,6 +18,17 @@ dependencies {
testImplementation(kotlin("test"))
}

tasks.jar {
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
),
)
}
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
Expand Down
6 changes: 3 additions & 3 deletions inngest-core/src/main/kotlin/com/inngest/Comm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CommHandler(val functions: HashMap<String, InngestFunction>) {
return mapOf(
"Content-Type" to "application/json",
// TODO - Get this from the build
"x-inngest-sdk" to "inngest-kt:v0.0.1",
"x-inngest-sdk" to "inngest-kt:${Version.getVersion()}",
// TODO - Pull this from options
"x-inngest-framework" to "ktor",
)
Expand Down Expand Up @@ -123,7 +123,7 @@ class CommHandler(val functions: HashMap<String, InngestFunction>) {
framework = "ktor",
sdk = "kotlin",
url = "http://localhost:8080/api/inngest",
v = "0.0.1",
v = Version.getVersion(),
functions = getFunctionConfigs(),
)
val jsonRequestBody = Klaxon().toJsonString(requestPayload)
Expand Down Expand Up @@ -163,7 +163,7 @@ class CommHandler(val functions: HashMap<String, InngestFunction>) {
framework = "ktor",
sdk = "kotlin",
url = "http://localhost:8080/api/inngest",
v = "0.0.1",
v = Version.getVersion(),
functions = getFunctionConfigs(),
)
return Klaxon().toJsonString(requestPayload)
Expand Down
9 changes: 9 additions & 0 deletions inngest-core/src/main/kotlin/com/inngest/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.inngest

class Version() {
companion object {
private val version: String = Version::class.java.getPackage().implementationVersion

fun getVersion(): String = version
}
}

0 comments on commit 79a0220

Please sign in to comment.