-
Notifications
You must be signed in to change notification settings - Fork 1
/
GitHubActionsGenerator.scala
126 lines (118 loc) · 3.08 KB
/
GitHubActionsGenerator.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import io.circe.Json
import io.circe.syntax._
object GitHubActionsGenerator {
object Step {
def setupJava(version: String): Json = Json.obj(
"name" := "Setup Java JDK",
"uses" := "actions/setup-java@v4",
"with" := Json.obj(
"distribution" := "temurin",
"java-version" := version,
"cache" := "sbt"
)
)
val Checkout: Json = Json.obj(
"name" := "Checkout",
"uses" := "actions/checkout@v4",
"with" := Json.obj(
"fetch-depth" := 0
)
)
}
object Job {
def lint(javaVersion: String): Json = Json.obj(
"name" := "Fatal warnings and code formatting",
"runs-on" := "ubuntu-latest",
"steps" := List(
Step.Checkout,
Step.setupJava(javaVersion),
Json.obj(
"name" := "Workflows",
"run" := "sbt blowoutCheck"
),
Json.obj(
"name" := "Code formatting",
"run" := "sbt scalafmtCheckAll"
),
Json.obj(
"name" := "Fatal warnings",
"run" := "sbt compile"
)
)
)
def test(javaVersion: String): Json = Json.obj(
"name" := "Unit tests",
"runs-on" := "ubuntu-latest",
"steps" := List(
Step.Checkout,
Step.setupJava(javaVersion),
Json.obj(
"name" := "Tests",
"run" := "sbt scripted"
)
)
)
def deploy(javaVersion: String): Json = Json.obj(
"name" := "Deploy",
"runs-on" := "ubuntu-latest",
"needs" := List("test", "lint"),
"steps" := List(
Step.Checkout,
Step.setupJava(javaVersion),
Json.obj(
"name" := "Release",
"run" := "sbt ci-release",
"env" := Json.obj(
"PGP_PASSPHRASE" := "${{secrets.PGP_PASSPHRASE}}",
"PGP_SECRET" := "${{secrets.PGP_SECRET}}",
"SONATYPE_PASSWORD" := "${{secrets.SONATYPE_PASSWORD}}",
"SONATYPE_USERNAME" := "${{secrets.SONATYPE_USERNAME}}"
)
)
)
)
}
def main(javaVersion: String): Json = Json.obj(
"name" := "CI",
"on" := Json.obj(
"push" := Json.obj("branches" := List("main"))
),
"env" := Json.obj(
"SBT_TPOLECAT_CI" := "true"
),
"jobs" := Json.obj(
"lint" := Job.lint(javaVersion),
"test" := Job.test(javaVersion),
"deploy" := Job.deploy(javaVersion)
)
)
def tag(javaVersion: String): Json = Json.obj(
"name" := "CD",
"on" := Json.obj(
"push" := Json.obj("tags" := List("*.*.*"))
),
"env" := Json.obj(
"SBT_TPOLECAT_RELEASE" := "true"
),
"jobs" := Json.obj(
"lint" := Job.lint(javaVersion),
"test" := Job.test(javaVersion),
"deploy" := Job.deploy(javaVersion)
)
)
def pullRequest(javaVersion: String): Json = Json.obj(
"name" := "CI",
"on" := Json.obj(
"pull_request" := Json.obj(
"branches" := List("main")
)
),
"env" := Json.obj(
"SBT_TPOLECAT_CI" := "true"
),
"jobs" := Json.obj(
"lint" := Job.lint(javaVersion),
"test" := Job.test(javaVersion)
)
)
}