Skip to content

Commit b67a122

Browse files
authored
Generate client-version from git tag (#48)
Generate client-version from git tag
2 parents 9d59e8f + 9cf3531 commit b67a122

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

build.gradle

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
id 'java-library'
1111
id 'net.ltgt.errorprone' version '1.1.1'
1212
id 'net.minecrell.licenser' version '0.4.1'
13+
id 'com.palantir.git-version' version '0.12.3'
1314
}
1415

1516
repositories {
@@ -39,8 +40,38 @@ googleJavaFormat {
3940
exclude '**/.idea/**'
4041
}
4142

42-
group = 'io.temporal'
43-
version = '0.10.0-SNAPSHOT'
43+
// v0.20.0-2-g000a42a -> 0.20.0-2-g000a42a
44+
ext.getTag = { ->
45+
def stdout = new ByteArrayOutputStream()
46+
exec {
47+
commandLine 'git', 'describe', '--tags'
48+
standardOutput = stdout
49+
}
50+
return stdout.toString().trim().substring(1)
51+
}
52+
53+
// 0.20.0-2-g000a42a -> 0.20.0-SNAPSHOT
54+
// 0.20.0 -> 0.20.0
55+
// Used to name jar files
56+
ext.getVersionName = { ->
57+
def split = getTag().split('-')
58+
if (split.size() > 1) {
59+
return split[0] + '-SNAPSHOT'
60+
}
61+
return split[0]
62+
}
63+
64+
// 0.20.0-SNAPSHOT -> 0.20.0
65+
// 0.20.0 -> 0.20.0
66+
// Stored int version.properties which is loaded
67+
// and used as a value of temporal-client-version gRPC header.
68+
ext.getClientVersionName = { ->
69+
def split = getVersionName().split('-')
70+
return split[0]
71+
}
72+
73+
group='io.temporal'
74+
version = getVersionName()
4475
archivesBaseName="temporal-sdk"
4576

4677
description = '''Temporal Workflow Java SDK'''
@@ -138,13 +169,13 @@ compileTestJava {
138169
// Generation version.properties for value to be included into the request header
139170
task createProperties(dependsOn: processResources) {
140171
doLast {
141-
def subdir = new File('$buildDir/resources/main/io/temporal/')
172+
def subdir = new File("$buildDir/resources/main/io/temporal/")
142173
if (!subdir.exists()) {
143174
subdir.mkdirs()
144175
}
145-
new File('$buildDir/resources/main/io/temporal/version.properties').withWriter { w ->
176+
new File("$buildDir/resources/main/io/temporal/version.properties").withWriter { w ->
146177
Properties p = new Properties()
147-
p['temporal-client-version'] = project.version.toString()
178+
p['temporal-client-version'] = getClientVersionName()
148179
p.store w, null
149180
}
150181
}

src/main/java/io/temporal/internal/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Version {
3434

3535
/**
3636
* Library Version is a semver that represents the version of this Temporal client library. This
37-
* represent API changes visibile to Temporal client side library consumers. I.e. developers that
37+
* represent API changes visible to Temporal client side library consumers. I.e. developers that
3838
* are writing workflows. So every time we change API that can affect them we have to change this
3939
* number. Format: MAJOR.MINOR.PATCH
4040
*/
@@ -50,7 +50,7 @@ public class Version {
5050
static {
5151
// Load version from version.properties generated by Gradle into build/resources/main directory.
5252
Properties prop = new Properties();
53-
InputStream in = Version.class.getResourceAsStream("/io.temporal/version.properties");
53+
InputStream in = Version.class.getResourceAsStream("/io/temporal/version.properties");
5454
if (in == null) {
5555
LIBRARY_VERSION = "UNKNOWN";
5656
} else {

src/main/java/io/temporal/internal/WorkflowServiceStubsImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public final class WorkflowServiceStubsImpl implements WorkflowServiceStubs {
5151

5252
/** refers to the name of the gRPC header that contains the client library version */
5353
private static final Metadata.Key<String> LIBRARY_VERSION_HEADER_KEY =
54-
Metadata.Key.of("temporal-sdk-version", Metadata.ASCII_STRING_MARSHALLER);
54+
Metadata.Key.of("temporal-client-version", Metadata.ASCII_STRING_MARSHALLER);
5555

5656
/** refers to the name of the gRPC header that contains the client feature version */
5757
private static final Metadata.Key<String> FEATURE_VERSION_HEADER_KEY =
58-
Metadata.Key.of("temporal-sdk-feature-version", Metadata.ASCII_STRING_MARSHALLER);
58+
Metadata.Key.of("temporal-client-feature-version", Metadata.ASCII_STRING_MARSHALLER);
5959

6060
/** refers to the name of the gRPC header that contains the client SDK name */
6161
private static final Metadata.Key<String> CLIENT_IMPL_HEADER_KEY =
62-
Metadata.Key.of("temporal-sdk-name", Metadata.ASCII_STRING_MARSHALLER);
62+
Metadata.Key.of("temporal-client-name", Metadata.ASCII_STRING_MARSHALLER);
6363

6464
private static final String CLIENT_IMPL_HEADER_VALUE = "temporal-java";
6565

0 commit comments

Comments
 (0)