Skip to content

Commit

Permalink
[patch] adding version call
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Oct 11, 2024
1 parent e63cca7 commit 6d4d768
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions command-line-tools/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

repositories {
Expand Down
20 changes: 20 additions & 0 deletions command-line-tools/tagger-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.org.jetbrains.kotlin.multiplatform)
Expand All @@ -11,6 +13,8 @@ repositories {
mavenCentral()
}

val generatedDirectory = project.layout.buildDirectory.dir("generated-sources/templates/kotlin/main")

kotlin {
jvm { withJava() }
js(IR) {
Expand All @@ -19,6 +23,7 @@ kotlin {
binaries.executable()
testTask {
useMocha { timeout = "10s" }
environment("EXPECTED_VERSION", "${project.version}")
environment("GIT_CONFIG_GLOBAL", "/dev/null")
environment("GIT_CONFIG_SYSTEM", "/dev/null")
}
Expand Down Expand Up @@ -54,6 +59,7 @@ dependencies {
tasks {
withType(Test::class) {
useJUnitPlatform()
environment("EXPECTED_VERSION", project.version)
environment("GIT_CONFIG_GLOBAL", "/dev/null")
environment("GIT_CONFIG_SYSTEM", "/dev/null")
}
Expand Down Expand Up @@ -97,6 +103,20 @@ tasks {
dependsOn(jsPublish)
mustRunAfter(check)
}
val copyTemplates by registering(Copy::class) {
inputs.property("version", rootProject.version)
filteringCharset = "UTF-8"
from(project.projectDir.resolve("src/commonMain/templates")) {
filter<ReplaceTokens>("tokens" to mapOf("TAGGER_VERSION" to rootProject.version))
}
into(generatedDirectory)
}
withType<KotlinCompile> {
dependsOn(copyTemplates)
}
kotlin.sourceSets {
commonMain { kotlin.srcDir(copyTemplates) }
}
}

fun Project.isSnapshot() = version.toString().contains("SNAPSHOT")
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package com.zegreatrob.tools.tagger.cli
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.versionOption

class Tagger : CliktCommand() {

init {
versionOption(Versions.taggerVersion)
}

private val quiet by option("--quiet", "-q")
.flag(default = false)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.zegreatrob.tools.tagger.cli

object Versions {
val taggerVersion: String = "@TAGGER_VERSION@"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.zegreatrob.tools.tagger.cli

import com.github.ajalt.clikt.testing.test
import com.zegreatrob.tools.test.git.getEnvironmentVariable
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class TaggerTest {
@Test
Expand All @@ -24,4 +26,17 @@ class TaggerTest {
assertEquals("", it)
}
}

@Test
fun versionWillReturnAppropriateVersion() {
val expectedVersion = getEnvironmentVariable("EXPECTED_VERSION")
assertNotNull(expectedVersion, "Test not setup correctly - include build version")
cli()
.test("-q --version")
.output
.trim()
.let {
assertEquals("tagger version $expectedVersion", it)
}
}
}

0 comments on commit 6d4d768

Please sign in to comment.