-
Notifications
You must be signed in to change notification settings - Fork 2
/
CompareApp.scala
66 lines (61 loc) · 2.03 KB
/
CompareApp.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// receive 2 file paths as input and compare the files, exit with status code 0 if there was no breaking change, 1 otherwise
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
import BreakingChangeDetector.CompareSummary._
object CompareApp extends App {
private def writeToOutput(
values: Map[String, String] = Map.empty[String, String],
githubOutput: String
): Unit = {
Files.write(
Paths.get(githubOutput),
values
.map { case (key, value) => s"$key=$value" }
.mkString("\n")
.getBytes(
StandardCharsets.UTF_8
)
)
}
val filesList =
sys.env("INPUT_FILES").split(",").filterNot(_.isBlank())
// read environment variable GITHUB_OUTPUT
val githubOutput = sys.env("GITHUB_OUTPUT")
val result = filesList.map(file => (file, file + ".prev")).map {
case (newFile, oldFile) => {
val oldFileParsed = FileParser.fromPathToClassDef(oldFile)
val newFileParsed = FileParser.fromPathToClassDef(newFile)
val compared =
BreakingChangeDetector.detectBreakingChange(
oldFileParsed,
newFileParsed
)
if (compared.find(_.isBreakingChange).isEmpty) {
val output = List.empty[BreakingChangeDetector.CompareSummary]
// write false to environment variable GITHUB_OUTPUT
(false, output, newFile)
} else {
val output = compared.filter(_.isBreakingChange)
println(output)
(true, output, newFile)
}
}
}
val finalResult = result.map(_._1).foldLeft(false)(_ || _)
// listOfFilesThatBreakChange
val finalOutput = result.filter(_._1).map(_._3).mkString(",")
val finalRaw = result.filter(_._1).map(res => (res._3, res._2)).toMap
val finalJson = upickle.default.write(finalRaw)
writeToOutput(
Map(
"result" -> finalResult.toString,
"log" -> finalOutput,
"json" -> finalJson
),
githubOutput
)
println("json=" + finalJson)
println("result=" + finalResult.toString)
println("log=" + finalOutput)
System.exit(0)
}