Skip to content

Commit

Permalink
bake in version info
Browse files Browse the repository at this point in the history
  • Loading branch information
Aivean committed Aug 21, 2023
1 parent f4a290e commit 5ba5cbc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ jobs:
java-version: '8'
cache: 'sbt'

- name: Extract version from tag
run: echo "PROJECT_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

- name: Build JAR
run: |
sbt assembly
sbt 'set version := "'"$PROJECT_VERSION"'"' assembly
mv target/scala-2.11/*-assembly-*.jar royalroad-downloader.jar
- name: Release
Expand Down
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ libraryDependencies += "org.rogach" %% "scallop" % "1.0.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
libraryDependencies += "org.scala-lang.modules" % "scala-java8-compat_2.11" % "0.9.1"

// inject version info
resourceGenerators in Compile += Def.task {
val file = (resourceManaged in Compile).value / "version.properties"
val props = new java.util.Properties()
props.put("version", version.value)
IO.write(props, "Version information", file)
Seq(file)
}.taskValue

mainClass in (Compile, run) := Some("com.aivean.royalroad.Main")
mainClass in assembly := Some("com.aivean.royalroad.Main")
2 changes: 2 additions & 0 deletions src/main/scala/com/aivean/royalroad/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import scala.concurrent.{Await, Future, duration}

object Main extends App {

print ("Royalroad downloader v" + VersionInfo.version + "\n")

def handleFromArg[T](chaps: Seq[T], fromChap: Int): Seq[T] =
if (fromChap > 0) chaps.drop(fromChap - 1) else if (fromChap < 0) chaps.takeRight(-fromChap) else chaps

Expand Down
11 changes: 11 additions & 0 deletions src/main/scala/com/aivean/royalroad/VersionInfo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.aivean.royalroad

object VersionInfo {
lazy val version: String = try {
val props = new java.util.Properties()
props.load(getClass.getResourceAsStream("/version.properties"))
props.getProperty("version")
} catch {
case _: Throwable => "unknown"
}
}

0 comments on commit 5ba5cbc

Please sign in to comment.