Skip to content

Commit

Permalink
Added publish for DevCompanyCamundalaRunner.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Dec 13, 2024
1 parent 928c2b5 commit e3260d6
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 65 deletions.
4 changes: 2 additions & 2 deletions 00-documentation/src/docs/development/initCompany.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ open helperCompany.scala
//> using toolkit 0.5.0
//> using dep io.github.pme123::camundala-helper:@VERSION@

import camundala.helper.dev.DevCompanyHelper
import camundala.helper.dev.DevCompanyRunner

@main
def run(command: String, arguments: String*): Unit =
DevCompanyHelper.run(command, arguments*)
DevCompanyRunner.run(command, arguments*)
```

1. Make the file executable:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package camundala.helper.dev

import camundala.helper.dev.publish.PublishHelper
import camundala.helper.dev.publish.PublishHelper.*
import camundala.helper.util.{DevConfig, Helpers}

import scala.util.{Failure, Success, Try}

// dev-company/company-camundala/helper.scala
case class DevCompanyCamundalaRunner(
devConfig: DevConfig
) extends Helpers:

def run(command: String, arguments: String*): Unit =
val args = arguments.toSeq
println(s"Running command: $command with args: $args")
Try(Command.valueOf(command)) match
case Success(cmd) =>
runCommand(cmd, args)
case Failure(_) =>
println(s"Command not found: $command")
println("Available commands: " + Command.values.mkString(", "))
end match
end run

private def runCommand(command: Command, args: Seq[String]): Unit =
command match
case Command.publish if args.size == 1 =>
publish(args.head)
case Command.publish =>
println("Usage: publish <version>")
case Command.prepareDocs =>
// CompanyDocCreator.prepareDocs()
case Command.releaseDocs =>
// CompanyDocCreator.releaseDocs()
case other =>
println(s"Command not found: $other")
println("Available commands: publish, prepareDocs, releaseDocs")

enum Command:
case publish, prepareDocs, releaseDocs

private def publish(newVersion: String): Unit =
println(s"Publishing ${devConfig.projectName}: $newVersion")
verifyVersion(newVersion)
verifySnapshots()
verifyChangelog(newVersion)
replaceVersion(newVersion, projectFile)
println("Versions replaced")
val isSnapshot = newVersion.contains("-")

os.proc("sbt", "-J-Xmx3G", "publish").callOnConsole()

if !isSnapshot then
git(newVersion, newVers => replaceVersion(newVers, projectFile))
end if
end publish

end DevCompanyCamundalaRunner
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import camundala.helper.util.{DevConfig, RepoConfig}

import scala.util.{Failure, Success, Try}

object DevCompanyHelper:
// dev-company/helperCompany.scala
object DevCompanyRunner:

def run(command: String, arguments: String*): Unit =
val args = arguments.toSeq
Expand All @@ -30,7 +31,7 @@ object DevCompanyHelper:
case other =>
println(s"Invalid arguments for command $command: $other")
println("Usage: project <projectName>")

// dev-company/company-camundala/helper.scala

enum Command:
case init, project
Expand All @@ -48,4 +49,4 @@ object DevCompanyHelper:

private lazy val companyName = os.pwd.last.replace("dev-", "").toLowerCase

end DevCompanyHelper
end DevCompanyRunner
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ case class CompanyScriptCreator()(using config: DevConfig):
|//> using toolkit 0.5.0
|//> using dep io.github.pme123::camundala-helper:${VersionHelper.camundalaVersion}
|
|import camundala.helper.dev.DevCompanyHelper
|import camundala.helper.dev.DevCompanyRunner
|
| @main
| def run(command: String, arguments: String*): Unit =
| DevCompanyHelper.run(command, arguments*)
| DevCompanyRunner.run(command, arguments*)
|""".stripMargin


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ case class PublishHelper()(using
publishConfig: Option[PublishConfig]
) extends Helpers:

import PublishHelper.*

def publish(version: String): Unit =
println(s"Publishing BPF Package: $version")
// TODO uncomment: verifySnapshots()
verifyVersion(version)
verifySnapshots()
verifyChangelog(version)
pushDevelop()
setApiVersion(version)

val releaseVersion = """^(\d+)\.(\d+)\.(\d+)(-.*)?$"""
if !version.matches(releaseVersion) then
throw new IllegalArgumentException(
"Your Version has not the expected format (2.1.2(-SNAPSHOT))"
)

replaceVersion(version)

lazy val sbtProcs = Seq(
Expand All @@ -49,27 +45,8 @@ case class PublishHelper()(using
val isSnapshot = version.contains("-")
if !isSnapshot then
publishToWebserver()
git(version, replaceVersion)

os.proc("git", "fetch", "--all").callOnConsole()
os.proc("git", "commit", "-a", "-m", s"Released Version $version")
.callOnConsole()
os.proc("git", "tag", "-a", "--no-sign", s"v$version", "-m", s"Version $version")
.callOnConsole()
os.proc("git", "checkout", "master").callOnConsole()
os.proc("git", "merge", branch).callOnConsole()
os.proc("git", "push", "--tags").callOnConsole()
os.proc("git", "checkout", branch).callOnConsole()
val Pattern = """^(\d+)\.(\d+)\.(\d+)$""".r

val newVersion = version match
case Pattern(major, minor, _) =>
s"$major.${minor.toInt + 1}.0-SNAPSHOT"
replaceVersion(newVersion)

os.proc("git", "commit", "-a", "-m", s"Init new Version $newVersion")
.callOnConsole()
os.proc("git", "push", "--all").callOnConsole()
println(s"Published Version: $version")
end if
end publish

Expand All @@ -86,29 +63,38 @@ case class PublishHelper()(using

os.write.over(apiFile, updatedFile)

private val projectFile: os.Path = workDir / "project" / "ProjectDef.scala"

private def replaceVersion(newVersion: String): Unit =
replaceVersion(newVersion, projectFile)
replaceVersion(newVersion, apiConfig.projectConfPath)
end replaceVersion

private def replaceVersion(newVersion: String, versionFile: os.Path): Unit =
val versionFileStr = os.read(versionFile)

val regexPattern = """version = "(\d+\.\d+\.\d+(-.+)?)""""
val updatedFile = versionFileStr
.replaceAll(regexPattern, s"""version = "$newVersion"""") + "\n"

os.write.over(versionFile, updatedFile)
PublishHelper.replaceVersion(newVersion, projectFile)
PublishHelper.replaceVersion(newVersion, apiConfig.projectConfPath)
end replaceVersion

private def publishToWebserver(): Unit =
// push it to Documentation Webserver
publishConfig.foreach:
ProjectWebDAV(devConfig.projectName, _).upload()

private def verifySnapshots(): Unit =
end PublishHelper

object PublishHelper extends Helpers:
val projectFile: os.Path = workDir / "project" / "ProjectDef.scala"

def verifyVersion(newVersion: String): Unit =
val releaseVersion = """^(\d+)\.(\d+)\.(\d+)(-.*)?$"""
if !newVersion.matches(releaseVersion) then
throw new IllegalArgumentException(
"Your Version has not the expected format (2.1.2(-SNAPSHOT))"
)
end verifyVersion

def verifyChangelog(newVersion: String): Unit =
ChangeLogUpdater.verifyChangelog(
newVersion,
commitsAddress = _.replace(".git", "/commit/") // git
.replace("ssh://git@", "https://") // ssh protocol
.replace(":2222", "") // ssh port
)

def verifySnapshots(): Unit =
hasSnapshots("Settings")
hasSnapshots("ProjectDef")

Expand All @@ -120,16 +106,42 @@ case class PublishHelper()(using
s"There are SNAPSHOT dependencies in `project/$fileName.scala`"
)

private def verifyChangelog(newVersion: String): Unit =
ChangeLogUpdater.verifyChangelog(
newVersion,
commitsAddress = _.replace(".git", "/commit/") // git
.replace("ssh://git@", "https://") // ssh protocol
.replace(":2222", "") // ssh port
)
// as projectUpdate for reference creation gets the newest changes from remote
private def pushDevelop(): Unit =
// as projectUpdate for reference creation gets the newest changes from remote
def pushDevelop(): Unit =
os.proc("git", "push").callOnConsole()

private lazy val branch = "develop"
def replaceVersion(newVersion: String, versionFile: os.Path): Unit =
val versionFileStr = os.read(versionFile)

val regexPattern = """version = "(\d+\.\d+\.\d+(-.+)?)""""
val updatedFile = versionFileStr
.replaceAll(regexPattern, s"""version = "$newVersion"""") + "\n"

os.write.over(versionFile, updatedFile)
end replaceVersion

def git(version: String, replaceVersion: String => Unit): Unit =
val branch = "develop"
os.proc("git", "fetch", "--all").callOnConsole()
os.proc("git", "commit", "-a", "-m", s"Released Version $version")
.callOnConsole()
os.proc("git", "tag", "-a", "--no-sign", s"v$version", "-m", s"Version $version")
.callOnConsole()
os.proc("git", "checkout", "master").callOnConsole()
os.proc("git", "merge", branch).callOnConsole()
os.proc("git", "push", "--tags").callOnConsole()
os.proc("git", "checkout", branch).callOnConsole()
val Pattern = """^(\d+)\.(\d+)\.(\d+)$""".r

val newVersion = version match
case Pattern(major, minor, _) =>
s"$major.${minor.toInt + 1}.0-SNAPSHOT"
replaceVersion(newVersion)

os.proc("git", "commit", "-a", "-m", s"Init new Version $newVersion")
.callOnConsole()
os.proc("git", "push", "--all").callOnConsole()
println(s"Published Version: $version")
end git

end PublishHelper
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ case class SbtGenerator()(using
| val org = "${projectConf.org}"
| val name = "${projectConf.name}"
| val version = "${projectConf.version}"
| lazy val nameAsPackage = name.split("-").mkString(".")
|
|${versionHelper.dependencyVersionVars}
|
Expand Down
7 changes: 5 additions & 2 deletions 04-helper/src/main/scala/camundala/helper/util/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ trait Helpers:
end check

extension (proc: os.proc)
def callOnConsole(path: os.Path = os.pwd): os.CommandResult =
proc.call(cwd = path, stdout = os.Inherit)

def callOnConsole(path: os.Path = os.pwd): Unit =
println(proc.command.mkString(" "))
val result = proc.call(cwd = path, stdout = os.Inherit)
println(result.out.text())
end extension
end Helpers
4 changes: 2 additions & 2 deletions docs/helper/initCompany.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ <h1 id="init-company" class="title">Init Company</h1>
</span><span class="comment">//&gt; using toolkit 0.5.0
//&gt; using dep io.github.pme123::camundala-helper:0.31.0-SNAPSHOT
</span><span>
</span><span class="keyword">import</span><span> </span><span class="identifier">camundala</span><span>.</span><span class="identifier">helper</span><span>.</span><span class="identifier">dev</span><span>.</span><span class="type-name">DevCompanyHelper</span><span>
</span><span class="keyword">import</span><span> </span><span class="identifier">camundala</span><span>.</span><span class="identifier">helper</span><span>.</span><span class="identifier">dev</span><span>.</span><span class="type-name">DevCompanyRunner</span><span>

</span><span class="annotation">@main</span><span>
</span><span class="keyword">def</span><span> </span><span class="declaration-name">run</span><span>(</span><span class="identifier">command</span><span>: </span><span class="type-name">String</span><span>, </span><span class="identifier">arguments</span><span>: </span><span class="type-name">String</span><span>*): </span><span class="type-name">Unit</span><span> =
</span><span class="type-name">DevCompanyHelper</span><span>.</span><span class="identifier">run</span><span>(</span><span class="identifier">command</span><span>, </span><span class="identifier">arguments</span><span>*)</span></code></pre>
</span><span class="type-name">DevCompanyRunner</span><span>.</span><span class="identifier">run</span><span>(</span><span class="identifier">command</span><span>, </span><span class="identifier">arguments</span><span>*)</span></code></pre>
</li>
<li>
<p>Make the file executable:</p>
Expand Down

0 comments on commit e3260d6

Please sign in to comment.