Skip to content

Commit 6786c36

Browse files
committed
Add short commit hash
1 parent 5976bb6 commit 6786c36

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

build.gradle

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,32 @@ subprojects {
9797
test.kotlin.srcDirs = ["test"]
9898

9999
main {
100-
output.dir(generatedVersionDir, builtBy: 'generateVersionProperties')
100+
output.dir(generatedVersionDir, builtBy: 'generateVersionAndHashProperties')
101101
}
102102
}
103-
task generateVersionProperties {
103+
104+
// generates a build properties file with the current PartiQL version and most recent commit hash
105+
task generateVersionAndHashProperties {
104106
doLast {
105-
def propertiesFile = file "$generatedVersionDir/version.properties"
107+
def propertiesFile = file "$generatedVersionDir/partiql.properties"
106108
propertiesFile.parentFile.mkdirs()
107109
def properties = new Properties()
110+
111+
// get current PartiQL version
108112
properties.setProperty("version", version.toString())
113+
114+
// get most recent short commit hash
115+
def commitHash = new ByteArrayOutputStream()
116+
exec {
117+
commandLine 'git', 'rev-parse', '--short', 'HEAD'
118+
standardOutput = commitHash
119+
}
120+
properties.setProperty("commit", commitHash.toString().trim())
121+
109122
propertiesFile.withWriter { properties.store(it, null) }
110123
}
111124
}
112-
processResources.dependsOn generateVersionProperties
125+
processResources.dependsOn generateVersionAndHashProperties
113126
})
114127

115128
}

cli/src/org/partiql/cli/Repl.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ internal class Repl(private val valueFactory: ExprValueFactory,
191191
outputWriter.write("\n")
192192
}
193193

194-
fun retrievePartiQLVersion(): String {
195-
val versionProperties = Properties()
196-
versionProperties.load(this.javaClass.getResourceAsStream("/version.properties"))
197-
return versionProperties.getProperty("version")
194+
fun retrievePartiQLVersionAndHash(): String {
195+
val properties = Properties()
196+
properties.load(this.javaClass.getResourceAsStream("/partiql.properties"))
197+
return "${properties.getProperty("version")}-${properties.getProperty("commit")}"
198198
}
199199

200200
private fun printVersionNumber() {
201-
outputWriter.write("Using version: ${retrievePartiQLVersion()}")
201+
outputWriter.write("Using version: ${retrievePartiQLVersionAndHash()}")
202202
outputWriter.write("\n")
203203
}
204204

cli/test/org/partiql/cli/ReplTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private class ReplTester(bindings: Bindings<ExprValue> = Bindings.empty()) {
7979

8080
private val repl = Repl(valueFactory, input, output, parser, compiler, bindings, zeroTimer)
8181

82-
val partiqlVersion = repl.retrievePartiQLVersion()
82+
val partiqlVersionAndHash = repl.retrievePartiQLVersionAndHash()
8383

8484
private val actualReplPrompt = StringBuilder()
8585

@@ -150,13 +150,13 @@ private class ReplTester(bindings: Bindings<ExprValue> = Bindings.empty()) {
150150

151151
@Ignore("https://github.com/partiql/partiql-lang-kotlin/issues/266")
152152
class ReplTest {
153-
private val partiqlVersion = ReplTester().partiqlVersion
153+
private val partiqlVersionAndHash = ReplTester().partiqlVersionAndHash
154154

155155
@Test
156156
fun singleQuery() {
157157
ReplTester().assertReplPrompt("""
158158
#Welcome to the PartiQL REPL!
159-
#Using version: $partiqlVersion
159+
#Using version: $partiqlVersionAndHash
160160
#PartiQL> 1+1
161161
# |
162162
#==='
@@ -171,7 +171,7 @@ class ReplTest {
171171
fun querySemiColon() {
172172
ReplTester().assertReplPrompt("""
173173
#Welcome to the PartiQL REPL!
174-
#Using version: $partiqlVersion
174+
#Using version: $partiqlVersionAndHash
175175
#PartiQL> 1+1;
176176
#==='
177177
#2
@@ -185,7 +185,7 @@ class ReplTest {
185185
fun multipleQuery() {
186186
ReplTester().assertReplPrompt("""
187187
#Welcome to the PartiQL REPL!
188-
#Using version: $partiqlVersion
188+
#Using version: $partiqlVersionAndHash
189189
#PartiQL> 1 + 1
190190
# |
191191
#==='
@@ -207,7 +207,7 @@ class ReplTest {
207207
fun astWithoutMetas() {
208208
ReplTester().assertReplPrompt("""
209209
#Welcome to the PartiQL REPL!
210-
#Using version: $partiqlVersion
210+
#Using version: $partiqlVersionAndHash
211211
#PartiQL> 1 + 1
212212
# | !!
213213
#==='
@@ -236,7 +236,7 @@ class ReplTest {
236236
fun addToGlobalEnvAndQuery() {
237237
ReplTester().assertReplPrompt("""
238238
#Welcome to the PartiQL REPL!
239-
#Using version: $partiqlVersion
239+
#Using version: $partiqlVersionAndHash
240240
#PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>}
241241
# |
242242
#==='
@@ -279,7 +279,7 @@ class ReplTest {
279279

280280
ReplTester(initialBindings).assertReplPrompt("""
281281
#Welcome to the PartiQL REPL!
282-
#Using version: $partiqlVersion
282+
#Using version: $partiqlVersionAndHash
283283
#PartiQL> !global_env
284284
# |
285285
#==='
@@ -300,7 +300,7 @@ class ReplTest {
300300
fun dumpEmptyInitialEnv() {
301301
ReplTester().assertReplPrompt("""
302302
#Welcome to the PartiQL REPL!
303-
#Using version: $partiqlVersion
303+
#Using version: $partiqlVersionAndHash
304304
#PartiQL> !global_env
305305
# |
306306
#==='
@@ -315,7 +315,7 @@ class ReplTest {
315315
fun dumpEnvAfterAltering() {
316316
ReplTester().assertReplPrompt("""
317317
#Welcome to the PartiQL REPL!
318-
#Using version: $partiqlVersion
318+
#Using version: $partiqlVersionAndHash
319319
#PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>}
320320
# |
321321
#==='
@@ -354,7 +354,7 @@ class ReplTest {
354354
fun listCommands() {
355355
ReplTester().assertReplPrompt("""
356356
#Welcome to the PartiQL REPL!
357-
#Using version: $partiqlVersion
357+
#Using version: $partiqlVersionAndHash
358358
#PartiQL> !list_commands
359359
# |
360360
#

0 commit comments

Comments
 (0)