Skip to content

Commit

Permalink
Cleanup company docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Dec 13, 2024
1 parent 76185cf commit 928c2b5
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 77 deletions.
1 change: 0 additions & 1 deletion 03-api/src/main/scala/camundala/api/ApiCreator.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package camundala.api

import camundala.api.docs.ApiProjectConf
import camundala.bpmn.InputParams
import camundala.domain.MockedServiceResponse
import sttp.apispec.openapi.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package camundala.api
package docs

import com.typesafe.config.ConfigFactory

import scala.jdk.CollectionConverters.CollectionHasAsScala
import scala.util.Try

case class ApiProjectConf(
org: String,
Expand All @@ -14,8 +14,8 @@ case class ApiProjectConf(
changelog: Seq[String] = Seq.empty,
isWorker: Boolean = false
):
lazy val versionConf = ConfVersion(version)
lazy val versionPreviousConf = ConfVersion(versionPrevious)
lazy val versionConf = versionFor(version)
lazy val versionPreviousConf = versionFor(versionPrevious)

lazy val versionAsInt = versionConf.versionAsInt

Expand All @@ -24,10 +24,17 @@ case class ApiProjectConf(
lazy val isPatched = !isNew && versionConf.isPatch(versionPreviousConf)
lazy val minorVersion: String = versionConf.minorVersion
lazy val fullName = s"$org:$name:$version"

private def versionFor(version: String) =
Try(ConfVersion(version))
.getOrElse:
println(s"Version $version is not valid. for $org:$name")
ConfVersion(ApiProjectConf.defaultVersion)

end ApiProjectConf

object ApiProjectConf:
lazy val defaultVersion = "0.1.0-SNAPSHOT"
lazy val defaultVersion = "0.1.0"

def apply(
packageFile: os.Path
Expand Down
2 changes: 0 additions & 2 deletions 03-api/src/main/scala/camundala/api/ModelerTemplUpdater.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package camundala.api

import camundala.api.*
import camundala.api.docs.ApiProjectConf
import io.circe.parser
import io.circe.syntax.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package camundala.api
package docs
package camundala.helper.dev.company.docs

import camundala.api.{ApiConfig, ApiProjectConf}

trait DependencyCreator:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package camundala.api
package docs
package camundala.helper.dev.company.docs

import camundala.api.{ApiConfig, ApiProjectConf, ProjectGroup}
import os.{pwd, write}

case class DependencyGraphCreator()(using
Expand All @@ -26,7 +26,7 @@ case class DependencyGraphCreator()(using
val graphsForProjects = treeForEachProjects(configs)
graphsForProjects.foreach(g =>
write.over(
pwd / "src" / "docs" / "dependencies" / s"${g.name}.md",
apiConfig.basePath / "src" / "docs" / "dependencies" / s"${g.name}.md",
g.graph
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package camundala.api
package docs
package camundala.helper.dev.company.docs

import camundala.api.{ApiConfig, ApiProjectConf, ProjectGroup}

case class DependencyLinkCreator()(using
val apiConfig: ApiConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package camundala.api
package docs
package camundala.helper.dev.company.docs

import camundala.api.{ApiConfig, ApiProjectConf}

case class DependencyValidator()(using
val apiConfig: ApiConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package camundala.api.docs
package camundala.helper.dev.company.docs

case class DevStatisticsCreator(gitBasePath: os.Path, basePath: os.Path):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package camundala.api
package docs
package camundala.helper.dev.company.docs

import camundala.api.{ApiProjectConf, ProjectConfig, catalogFileName}
import camundala.helper.util.Helpers
import os.Path

import java.time.LocalDate
Expand All @@ -10,7 +11,7 @@ import java.time.format.DateTimeFormatter
*
* For a Start you can create a Catalog.
*/
trait CompanyDocCreator extends DependencyCreator:
trait DocCreator extends DependencyCreator, Helpers:

protected def gitBasePath: os.Path = apiConfig.projectsConfig.gitDir
protected given configs: Seq[ApiProjectConf] = setupConfigs()
Expand Down Expand Up @@ -293,7 +294,8 @@ trait CompanyDocCreator extends DependencyCreator:
case ((entries, activeGroup), line) =>
line match
case l if l.startsWith("### ") => // group
val group = ChangeLogGroup.withName(l.drop(4).trim)
val group = groups.map(_.toString).toSeq.findLast(_ == l.drop(4).trim)
.map(ChangeLogGroup.valueOf).getOrElse(ChangeLogGroup.Other)
(entries, group)
case l =>
val regex = """(.*)(MAP-\d+)(:? )(.*)""".r
Expand All @@ -313,7 +315,7 @@ trait CompanyDocCreator extends DependencyCreator:
val preparedGroups = groups
// take only the groups that have entries
.filter(g => changeLogEntries.exists(_.group == g))
.foldLeft(Map.empty[ChangeLogGroup.Value, Map[String, Seq[String]]]) {
.foldLeft(Map.empty[ChangeLogGroup, Map[String, Seq[String]]]) {
case (result, group) =>
// get the new entries for a group - group it by ticket
val newEntries =
Expand Down Expand Up @@ -371,13 +373,13 @@ trait CompanyDocCreator extends DependencyCreator:
else
s"[$jiraTicket](https://issue.swisscom.ch/browse/$jiraTicket)"

private object ChangeLogGroup extends Enumeration:
val Added, Changed, Fixed, Deprecated, Removed, Security = Value
private enum ChangeLogGroup:
case Added, Changed, Fixed, Deprecated, Removed, Security, Other

private case class ChangeLogEntry(
group: ChangeLogGroup.Value = ChangeLogGroup.Changed,
group: ChangeLogGroup = ChangeLogGroup.Changed,
text: String,
ticket: Option[String] = None
)

end CompanyDocCreator
end DocCreator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package camundala.api.docs
package camundala.helper.dev.company.docs

import com.typesafe.config.ConfigFactory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package camundala.api.docs
package camundala.helper.dev.company.docs

import java.time.LocalDate

Expand Down
54 changes: 18 additions & 36 deletions 04-helper/src/main/scala/camundala/helper/dev/publish/WebDAV.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.jdk.CollectionConverters.CollectionHasAsScala

abstract class WebDAV:
def publishConfig: PublishConfig
val baseUrl = publishConfig.documentationUrl
val publishBaseUrl = publishConfig.documentationUrl
val contentTypeHtml = "text/html"
val contentTypeYaml = "text/yaml"

Expand All @@ -22,8 +22,9 @@ abstract class WebDAV:
username <- sys.env.get(publishConfig.documentationEnvUsername)
password <- sys.env.get(publishConfig.documentationEnvPassword)
yield
println(s"Set Credentials for $username (${publishConfig.documentationEnvUsername})")
sardine.setCredentials(username, password))
println(s"Set Credentials for $username (${publishConfig.documentationEnvUsername})")
sardine.setCredentials(username, password)
)
.getOrElse(
throw new IllegalArgumentException(
s"System Environment Variables ${publishConfig.documentationEnvUsername} and/ or ${publishConfig.documentationEnvPassword} are not set."
Expand All @@ -35,7 +36,7 @@ end WebDAV

case class ProjectWebDAV(projectName: String, publishConfig: PublishConfig) extends WebDAV:

val projectUrl = s"$baseUrl/$projectName/"
val projectUrl = s"$publishBaseUrl/$projectName/"

def upload(): Unit =
println(s"Start $projectName: upload Documentation to ${publishConfig.documentationUrl}")
Expand All @@ -51,10 +52,9 @@ case class ProjectWebDAV(projectName: String, publishConfig: PublishConfig) exte
sardine.delete(projectUrl)
catch
case ex: SardineException
if ex.getMessage.contains("Unexpected response (404 Not Found)") =>
if ex.getMessage.contains("Unexpected response (404 Not Found)") =>
println(s"New Project will be created.")
end try

// create new
sardine.createDirectory(projectUrl)
sardine.put(s"$projectUrl/OpenApi.html", openApiHtml, contentTypeHtml)
Expand Down Expand Up @@ -98,6 +98,7 @@ case class ProjectWebDAV(projectName: String, publishConfig: PublishConfig) exte
println(s"Finished $projectName: upload Documentation")
finally sardine.shutdown()
end try
end upload

private lazy val openApiHtml =
os.read.inputStream(publishConfig.openApiHtmlPath)
Expand All @@ -113,11 +114,12 @@ case class ProjectWebDAV(projectName: String, publishConfig: PublishConfig) exte

end ProjectWebDAV

case class DocsWebDAV(apiConfig: ApiConfig, publishConfig: PublishConfig) extends WebDAV with Helpers:
case class DocsWebDAV(apiConfig: ApiConfig, publishConfig: PublishConfig) extends WebDAV
with Helpers:
def upload(releaseTag: String): Unit =
val sardine = startSession
val directories = Seq("helium", "releases")
val docDir = os.pwd / "target" / "docs" / "site"
val docDir = apiConfig.basePath / "target" / "docs" / "site"
if docDir.toIO.exists() then
// symbolic links for dependencies
os.proc(
Expand All @@ -126,34 +128,14 @@ case class DocsWebDAV(apiConfig: ApiConfig, publishConfig: PublishConfig) extend
s"./$releaseTag/dependencies",
docDir / "dependencies"
).callOnConsole()
os.proc("ln", "-s", s"./$releaseTag/helium", docDir / "helium")
.callOnConsole()
os.proc("ln", "-s", s"./$releaseTag/index.html", docDir / "index.html")
.callOnConsole()
os.proc(
"ln",
"-s",
s"./$releaseTag/overviewDependencies.html",
docDir / "overviewDependencies.html"
).callOnConsole()
// create also top level links for versioned root pages
Seq("helium", "index.html", "release.html", "overviewDependencies.html")
.foreach: f =>
println(s"Create symbolic link $f")
os.proc("ln", "-s", s"./$releaseTag/$f", docDir / f)
.callOnConsole()

try
// remove existing files if exists
val existingFiles = sardine.list(baseUrl)
val filteredFiles = existingFiles.asScala
.filter(r =>
r.getName.endsWith(".html") || directories.contains(r.getName)
)
println(s"Existing Files $existingFiles")
println(s"Filtered Files $filteredFiles")
filteredFiles
.filterNot(_.getName == "releases")
.foreach(f =>
val url =
if f.isDirectory then s"$baseUrl/${f.getName}/"
else s"$baseUrl/${f.getName}"
println(s"Delete: $url")
sardine.delete(url)
)

def uploadFiles(url: String, docFiles: Seq[os.Path]): Unit =
docFiles.foreach {
Expand All @@ -169,7 +151,7 @@ case class DocsWebDAV(apiConfig: ApiConfig, publishConfig: PublishConfig) extend
println(s"Not supported file: $f")
}

uploadFiles(baseUrl, os.list(docDir))
uploadFiles(publishBaseUrl, os.list(docDir))
println(s"Finished upload Documentation")

catch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package camundala.helper.dev.update

import camundala.api.docs.DependencyConf
import camundala.helper.util.DevConfig

case class ApiGeneratorGenerator()(using config: DevConfig):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package camundala.helper.dev.update

import camundala.api.docs.DependencyConf

case class DmnGenerator()(using config: DevConfig):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package camundala.helper.dev.update

import camundala.api.docs.DependencyConf
import camundala.api.DependencyConf

case class WorkerGenerator()(using config: DevConfig):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package camundala.helper.util

import camundala.BuildInfo
import camundala.api.docs.ApiProjectConf

import camundala.api.ApiProjectConf
import camundala.helper.util.ReposConfig
import os.RelPath

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package camundala.helper.util

import camundala.api.ApiConfig
import camundala.api.docs.ApiProjectConf

trait Helpers:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package camundala.helper.util

import camundala.api.docs.*
import camundala.api.ApiProjectConf
import camundala.api.DependencyConf

import scala.jdk.CollectionConverters.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package camundala.myCompany

import camundala.api.*
import camundala.api.docs.CompanyDocCreator
import camundala.helper.dev.company.docs.DocCreator

/*
Starting point to use Camundala for Company wide documentation
For now only the catalog is created.
exampleMyCompany/run
*/
object MyCompanyDocCreator extends CompanyDocCreator, App:
object MyCompanyDocCreator extends DocCreator, App:
given apiConfig: ApiConfig = myCompanyConfig
protected def upload(releaseTag: String): Unit =
println("Uploaded to Web Server")
Expand Down
6 changes: 2 additions & 4 deletions project/Settings.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import Dependencies.mUnitVersion
import laika.ast.Path.Root
import laika.config.*
import laika.config.LaikaKeys.versions
import laika.format.Markdown.GitHubFlavor
import laika.helium.Helium
import laika.helium.config.{Favicon, HeliumIcon, IconLink}
import laika.helium.config.{HeliumIcon, IconLink}
import laika.sbt.LaikaPlugin.autoImport.*
import mdoc.MdocPlugin.autoImport.*
import sbt.Keys.*
import sbt.*
import sbt.Keys.*
import xerial.sbt.Sonatype.autoImport.sonatypeRepository

import scala.util.Using
Expand Down Expand Up @@ -127,7 +126,6 @@ object Settings {
IconLink.external(githubUrl, HeliumIcon.github),
)
)

.build,
)
lazy val mdocSettings = Seq(
Expand Down

0 comments on commit 928c2b5

Please sign in to comment.