Skip to content

Commit

Permalink
Store version in "$smithyRsVersion\n$gitCommitHash" format
Browse files Browse the repository at this point in the history
  • Loading branch information
unexge committed Aug 10, 2022
1 parent 609eb21 commit 5cd9d69
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ val generateSmithyRuntimeCrateVersion by tasks.registering {
val crateVersion = project.properties["smithy.rs.runtime.crate.version"].toString()
inputs.property("crateVersion", crateVersion)
// version format must be in sync with `software.amazon.smithy.rust.codegen.smithy.Version`
val version = "$crateVersion-${gitCommitHash()}"
val version = "$crateVersion\n${gitCommitHash()}"
sourceSets.main.get().output.dir(resourcesDir)
doLast {
versionFile.writeText(version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ package software.amazon.smithy.rust.codegen.smithy

import software.amazon.smithy.codegen.core.CodegenException

// generated as part of the build in the "{smithy_rs_version}\n{git_commit_hash}" format,
// see codegen/build.gradle.kts
private const val VERSION_FILENAME = "runtime-crate-version.txt"

class Version(private val content: String) {
fun fullVersion(): String = content

fun crateVersion(): String {
val parts = content.split("-")
if (parts.size < 2) {
return ""
}
return parts.first()
}
// Returns full version in the "{smithy_rs_version}-{git_commit_hash}" format
fun fullVersion(): String = content.lines().joinToString("-")

companion object {
// generated as part of the build in the "{smithy_rs_version}-{git_commit_hash}" format,
// see codegen/build.gradle.kts
private const val VERSION_FILENAME = "runtime-crate-version.txt"
fun crateVersion(): String = content.lines().first()

companion object {
fun fullVersion(): String =
fromDefaultResource().fullVersion()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,61 @@

package software.amazon.smithy.rust.codegen.smithy

import org.junit.jupiter.api.Assertions
import io.kotest.matchers.shouldBe
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource

class VersionTest {
@ParameterizedTest()
@CsvSource(
"'0.47.0-0198d26096eb1af510ce24766c921ffc5e4c191e','0.47.0-0198d26096eb1af510ce24766c921ffc5e4c191e','0.47.0'",
"'0.0.0','0.0.0',''",
"'','',''",
)
@MethodSource("versionProvider")
fun `parses version`(
content: String,
fullVersion: String,
crateVersion: String,
) {
Assertions.assertEquals(fullVersion, Version(content).fullVersion())
Assertions.assertEquals(crateVersion, Version(content).crateVersion())
Version(content).fullVersion() shouldBe fullVersion
Version(content).crateVersion() shouldBe crateVersion
}

companion object {
@JvmStatic
fun versionProvider() = listOf(
Arguments.of(
"0.47.0\n0198d26096eb1af510ce24766c921ffc5e4c191e",
"0.47.0-0198d26096eb1af510ce24766c921ffc5e4c191e",
"0.47.0",
),
Arguments.of(
"release-2022-08-04\ndb48039065bec890ef387385773b37154b555b14",
"release-2022-08-04-db48039065bec890ef387385773b37154b555b14",
"release-2022-08-04",
),
Arguments.of(
"0.30.0-alpha\na1dbbe2947de3c8bbbef9446eb442e298f83f200",
"0.30.0-alpha-a1dbbe2947de3c8bbbef9446eb442e298f83f200",
"0.30.0-alpha",
),
Arguments.of(
"0.6-rc1.cargo\nc281800a185b34600b05f8b501a0322074184123",
"0.6-rc1.cargo-c281800a185b34600b05f8b501a0322074184123",
"0.6-rc1.cargo",
),
Arguments.of(
"0.27.0-alpha.1\n643f2ee",
"0.27.0-alpha.1-643f2ee",
"0.27.0-alpha.1",
),
Arguments.of(
"0.0.0",
"0.0.0",
"0.0.0",
),
Arguments.of(
"",
"",
"",
),
)
}
}

0 comments on commit 5cd9d69

Please sign in to comment.