Skip to content

Commit

Permalink
Merge pull request #79 from craigatk/version
Browse files Browse the repository at this point in the history
(feature) Adding endpoint that shows application version
  • Loading branch information
craigatk authored Apr 26, 2020
2 parents 3313aec + 6a966a5 commit 4432792
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/release-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
CACHE_ACCESS_KEY: ${{ secrets.CACHE_ACCESS_KEY }}
CACHE_SECRET_KEY: ${{ secrets.CACHE_SECRET_KEY }}
run: |
./gradlew :server:server-app:assembleFull
./gradlew :server:server-app:assembleFull -PreleaseVersion=${{ env.RELEASE_VERSION }}
- name: cypress-common install
run: |
cd cypress-common
Expand Down
1 change: 1 addition & 0 deletions server/server-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/main/resources/static
src/main/resources/version.json

.kotlintest
15 changes: 15 additions & 0 deletions server/server-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ task copyUI(type: Copy, dependsOn: ['cleanStaticResources', ':ui:assemble']) {
processResources.mustRunAfter(copyUI)
shadowJar.mustRunAfter(copyUI)

task writeVersion() {
String projectVersion = findProperty("releaseVersion") ?: version

inputs.property("projectVersion", projectVersion)
outputs.file("src/main/resources/version.json")
outputs.cacheIf { true }

doLast {
new File("$projectDir/src/main/resources/version.json").text = """{
"version": "$projectVersion"
}"""
}
}
processResources.dependsOn(writeVersion)

runShadow.dependsOn(copyUI)

task assembleFull(dependsOn: ['copyUI', 'shadowJar'])
Expand Down
1 change: 1 addition & 0 deletions server/server-app/src/main/kotlin/projektor/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ fun Application.main() {
testRuns(testRunService)
testRunSystemAttributes(testRunSystemAttributesService)
ui()
version()
}
}

Expand Down
11 changes: 11 additions & 0 deletions server/server-app/src/main/kotlin/projektor/route/VersionRoutes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package projektor.route

import io.ktor.http.content.defaultResource
import io.ktor.http.content.static
import io.ktor.routing.Route

fun Route.version() {
static("/version") {
defaultResource("version.json", "/")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package projektor.version

import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.withTestApplication
import io.ktor.util.KtorExperimentalAPI
import org.junit.jupiter.api.Test
import projektor.ApplicationTestCase
import strikt.api.expectThat
import strikt.assertions.contains
import strikt.assertions.isEqualTo
import strikt.assertions.isNotNull

@KtorExperimentalAPI
class VersionApplicationTest : ApplicationTestCase() {
@Test
fun `should provide version endpoint`() {
withTestApplication(::createTestApplication) {
handleRequest(HttpMethod.Get, "/version").apply {
expectThat(response.status()).isEqualTo(HttpStatusCode.OK)

expectThat(response.content).isNotNull().and { contains("version") }
}
}
}
}

0 comments on commit 4432792

Please sign in to comment.