Skip to content

Commit

Permalink
Update besom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelprazak committed Feb 15, 2024
1 parent c862b4f commit cdd19c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions codegen/src/model/SemanticVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ case class SemanticVersion(
else preCompared // pre-release version has lower precedence than a normal version
end compare

def isSnapshot: Boolean = preRelease.contains("SNAPSHOT")

lazy val preReleaseString: String = preRelease.map("-" + _).getOrElse("")
lazy val buildMetadataString: String = buildMetadata.map("+" + _).getOrElse("")

Expand Down
29 changes: 22 additions & 7 deletions scripts/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,39 @@ object Version:
println(s"$a $b")
}
case "bump" :: newBesomVersionStr :: Nil =>
val newBesomVersion = SemanticVersion.parse(newBesomVersionStr).fold(
e => throw Exception(s"Invalid version: $newBesomVersionStr", e), _.toString
)
val (newBesomVersion, isSnapshot) = SemanticVersion
.parse(newBesomVersionStr)
.fold(
e => throw Exception(s"Invalid version: $newBesomVersionStr", e),
v => (v.toString, v.isSnapshot)
)
println(s"Bumping Besom core version from '$besomVersion' to '$newBesomVersion'")
os.write.over(cwd / "version.txt", newBesomVersion)
println(s"Updated version.txt")
projectFiles()
val filesWithBesomDeps = projectFiles()
.collect { case (path, content) if content.linesIterator.exists(besomDependencyPattern.matches) => path -> content }
filesWithBesomDeps
.foreachEntry { case (path, content) =>
val newContent = content.linesIterator
val hasSnapshotRepo = content.linesIterator
.forall(line => line.contains("repository sonatype:snapshots"))
val newContent: Vector[String] = content.linesIterator.toVector
.map {
case line if line.contains("besom-fake-") => line // ignore
case besomDependencyPattern(prefix, version, suffix) =>
prefix + changeVersion(version, newBesomVersion) + suffix
case line => line // pass through
}
.mkString("\n") + "\n"
os.write.over(path, newContent)
.filter {
case line if !isSnapshot && line.contains("repository sonatype:snapshots") =>
false // remove snapshot repo from non-snapshot version
case _ => true
} ++ {
if isSnapshot && !hasSnapshotRepo then // add snapshot repo to snapshot version
Vector("//> using repository sonatype:snapshots")
else Vector.empty
}

os.write.over(path, newContent.mkString("\n") + "\n")
println(s"Updated $path")
}
case "update" :: Nil =>
Expand Down

0 comments on commit cdd19c0

Please sign in to comment.