Skip to content

Commit

Permalink
run scalafmtSbtCheck task in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Oct 14, 2024
1 parent 3eb783f commit b088d48
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
uses: sbt/setup-sbt@v1
- name: Build and test
run: |
sbt -v "mimaReportBinaryIssues; scalafmtCheckAll; shadedPackageBin; test;"
sbt -v "mimaReportBinaryIssues; scalafmtSbtCheck; scalafmtCheckAll; shadedPackageBin; test;"
ci-test/test.sh
shell: bash
65 changes: 37 additions & 28 deletions project/Transform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@ object Transform {
conscriptConfigs := {
val res = (managedResources in launch in Compile).value
val src = (sourceDirectory in Compile).value
val source = res.filter(_.getName == "sbt.boot.properties").headOption getOrElse sys.error("No managed boot.properties file.")
val source = res.filter(_.getName == "sbt.boot.properties").headOption getOrElse sys.error(
"No managed boot.properties file."
)
copyConscriptProperties(source, src / "conscript")
()
}
)
def copyConscriptProperties(source: File, conscriptBase: File): Seq[File] =
{
IO.delete(conscriptBase)
val pairs = Seq(
"sbt.xMain" -> "sbt",
"sbt.ScriptMain" -> "scalas",
"sbt.ConsoleMain" -> "screpl"
)
for ((main, dir) <- pairs) yield {
val file = conscriptBase / dir / "launchconfig"
copyPropertiesFile(source, main, file)
file
}
def copyConscriptProperties(source: File, conscriptBase: File): Seq[File] = {
IO.delete(conscriptBase)
val pairs = Seq(
"sbt.xMain" -> "sbt",
"sbt.ScriptMain" -> "scalas",
"sbt.ConsoleMain" -> "screpl"
)
for ((main, dir) <- pairs) yield {
val file = conscriptBase / dir / "launchconfig"
copyPropertiesFile(source, main, file)
file
}
}
def copyPropertiesFile(source: File, newMain: String, target: File): Unit = {
def subMain(line: String): String = if (line.trim.startsWith("class:")) " class: " + newMain else line
def subMain(line: String): String =
if (line.trim.startsWith("class:")) " class: " + newMain else line
IO.writeLines(target, IO.readLines(source) map subMain)
}

Expand All @@ -54,11 +56,13 @@ object Transform {
inputSources := (inputSourceDirectories.value ** (-DirectoryFilter)).get,
fileMappings in transformSources := transformSourceMappings.value,
transformSources := {
(fileMappings in transformSources).value.map { case (in, out) => transform(in, out, sourceProperties.value) }
(fileMappings in transformSources).value.map {
case (in, out) => transform(in, out, sourceProperties.value)
}
},
sourceGenerators += transformSources.taskValue
)
def transformSourceMappings = Def.task{
def transformSourceMappings = Def.task {
val ss = inputSources.value
val sdirs = inputSourceDirectories.value
val sm = sourceManaged.value
Expand All @@ -81,26 +85,31 @@ object Transform {
inputResources := (inputResourceDirectories.value ** (-DirectoryFilter)).get,
fileMappings in transformResources := transformResourceMappings.value,
transformResources := {
(fileMappings in transformResources).value.map { case (in, out) => transform(in, out, resourceProperties.value) }
(fileMappings in transformResources).value.map {
case (in, out) => transform(in, out, resourceProperties.value)
}
},
resourceGenerators += transformResources.taskValue
)
def transformResourceMappings = Def.task{
def transformResourceMappings = Def.task {
val rs = inputResources.value
val rdirs = inputResourceDirectories.value
val rm = resourceManaged.value
(rs --- rdirs) pair (rebase(rdirs, rm) | flat(rm)) toSeq
}

def transform(in: File, out: File, map: Map[String, String]): File =
{
def get(key: String): String = map.getOrElse(key, sys.error("No value defined for key '" + key + "'"))
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
if (Some(newString) != read(out))
IO.write(out, newString)
out
}
def read(file: File): Option[String] = try { Some(IO.read(file)) } catch { case _: java.io.IOException => None }
def transform(in: File, out: File, map: Map[String, String]): File = {
def get(key: String): String =
map.getOrElse(key, sys.error("No value defined for key '" + key + "'"))
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
if (Some(newString) != read(out))
IO.write(out, newString)
out
}
def read(file: File): Option[String] =
try {
Some(IO.read(file))
} catch { case _: java.io.IOException => None }
lazy val Property = """\$\{\{([\w.-]+)\}\}""".r

def repositories(isSnapshot: Boolean) = Releases :: (if (isSnapshot) Snapshots :: Nil else Nil)
Expand Down

0 comments on commit b088d48

Please sign in to comment.