-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sbt
More file actions
197 lines (178 loc) · 7.19 KB
/
Copy pathbuild.sbt
File metadata and controls
197 lines (178 loc) · 7.19 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
ThisBuild / tlBaseVersion := "0.3"
ThisBuild / organization := "org.polyvariant"
ThisBuild / organizationName := "Polyvariant"
ThisBuild / startYear := Some(2025)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(tlGitHubDev("kubukoz", "Jakub Kozłowski"))
ThisBuild / githubWorkflowPublishTargetBranches := Seq(
RefPredicate.Equals(Ref.Branch("main")),
RefPredicate.StartsWith(Ref.Tag("v")),
)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"))
val scala212 = "2.12.21"
val scala3 = "3.8.4"
ThisBuild / scalaVersion := scala212
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
ThisBuild / tlJdkRelease := None
ThisBuild / tlFatalWarnings := false
ThisBuild / mergifyStewardConfig ~= (_.map(_.withMergeMinors(true)))
// Discover+run matrix for the sbt plugin's scripted tests. The placeholder/patch
// trick works around an upstream bug where matrixAdds values are always quoted
// but we need the `${{ fromJSON(...) }}` expression rendered unquoted.
// Tracked at https://github.com/typelevel/sbt-typelevel/issues/887
ThisBuild / githubWorkflowAddedJobs ++= ScriptedMatrix.jobs(
moduleId = "sbtPlugin",
jobIdPrefix = "scripted",
scalas = List(scala212, scala3),
javas = List(JavaSpec.temurin("17")),
oses = (ThisBuild / githubWorkflowOSes).value.toList,
jobSetup = githubWorkflowJobSetup.value.toList,
)
ThisBuild / githubWorkflowAddedJobs ++= ScriptedMatrix.jobs(
moduleId = "sbtPluginSmithy4s",
jobIdPrefix = "scripted-smithy4s",
scalas = List(scala212, scala3),
javas = List(JavaSpec.temurin("17")),
oses = (ThisBuild / githubWorkflowOSes).value.toList,
jobSetup = githubWorkflowJobSetup.value.toList,
)
// Upstream `githubWorkflowGenerate` renders all matrix values through `wrap`,
// which quotes the `${{ fromJSON(...) }}` expression we need for the scripted
// matrix axis. We work around this with a placeholder + post-process pass.
// Two tasks below cooperate symmetrically: one regenerates and applies the
// patch; the other regenerates, applies the patch in memory, and compares.
// The CI workflow's "up to date" check calls the patched check task so it
// sees the same form as what's on disk.
// Tracked upstream: https://github.com/typelevel/sbt-typelevel/issues/887
val patchScriptedMatrix: String => String = ScriptedMatrix
.patchFor("scripted")
.andThen(ScriptedMatrix.patchFor("scripted-smithy4s"))
// route the in-workflow staleness check through our patched task so it
// compares apples to apples
.andThen(_.replace("sbt githubWorkflowCheck", "sbt githubWorkflowCheckWithMatrixPatch"))
val githubWorkflowGenerateWithMatrixPatch = taskKey[Unit](
"Generate ci.yml via sbt-typelevel, then patch the scripted matrix axis"
)
val githubWorkflowCheckWithMatrixPatch = taskKey[Unit](
"Check ci.yml is up to date, accounting for the scripted matrix patch"
)
ThisBuild / githubWorkflowGenerateWithMatrixPatch := {
(LocalRootProject / githubWorkflowGenerate).value
val ciYml = (LocalRootProject / baseDirectory).value / ".github" / "workflows" / "ci.yml"
IO.write(ciYml, patchScriptedMatrix(IO.read(ciYml)))
}
// Snapshot the on-disk content to a sibling file BEFORE upstream generation
// runs. Sequencing is done via `Def.sequential` so the snapshot task executes
// before generate (which overwrites the file).
val snapshotCiYml = taskKey[File](
"Copy ci.yml to a sibling file so it can be diffed after regeneration"
)
ThisBuild / snapshotCiYml := {
val ciYml = (LocalRootProject / baseDirectory).value / ".github" / "workflows" / "ci.yml"
val snap = ciYml.getParentFile / s"${ciYml.getName}.snapshot"
IO.copyFile(ciYml, snap)
snap
}
ThisBuild / githubWorkflowCheckWithMatrixPatch := Def
.sequential(
ThisBuild / snapshotCiYml,
LocalRootProject / githubWorkflowGenerate,
Def.task {
val ciYml = (LocalRootProject / baseDirectory).value / ".github" / "workflows" / "ci.yml"
val snap = ciYml.getParentFile / s"${ciYml.getName}.snapshot"
val onDisk = IO.read(snap)
val regeneratedAndPatched = patchScriptedMatrix(IO.read(ciYml))
IO.write(ciYml, onDisk)
IO.delete(snap)
if (regeneratedAndPatched != onDisk) {
val tmp = IO.createTemporaryDirectory
val expected = tmp / "expected.yml"
val actual = tmp / "actual.yml"
IO.write(expected, regeneratedAndPatched)
IO.write(actual, onDisk)
val out = new java.io.ByteArrayOutputStream
scala
.sys
.process
.Process(Seq("diff", "-u", actual.getAbsolutePath, expected.getAbsolutePath))
.#>(out)
.!
println(s"diff (actual vs expected):\n${out.toString}")
sys.error(
"ci.yml is out of date — run githubWorkflowGenerateWithMatrixPatch"
)
}
},
)
.value
// Reroute the `prePR` and `tlPrePrBotHook` aliases (defined by sbt-typelevel)
// to use our patched generate task, so contributors running `sbt prePR` get
// the same ci.yml form that `githubWorkflowCheckWithMatrixPatch` validates.
GlobalScope / tlCommandAliases := (GlobalScope / tlCommandAliases).value.map {
case (alias, commands) =>
alias -> commands.map {
case "githubWorkflowGenerate" => "githubWorkflowGenerateWithMatrixPatch"
case other => other
}
}
lazy val core = project
.settings(
name := "smithy-scala-tools-core",
libraryDependencies ++= Seq(
"software.amazon.smithy" % "smithy-trait-codegen" % "1.72.1",
"software.amazon.smithy" % "smithy-model" % "1.72.1",
"software.amazon.smithy" % "smithy-syntax" % "1.72.1",
"software.amazon.smithy" % "smithy-docgen" % "1.72.1",
"software.amazon.smithy" % "smithy-build" % "1.72.1",
"com.lihaoyi" %% "os-lib" % "0.11.8",
"org.scalameta" %% "munit" % "1.3.4" % Test,
),
mimaPreviousArtifacts := Set.empty,
)
lazy val sbtPlugin = project
.dependsOn(core)
.settings(
name := "smithy-scala-tools-sbt",
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "1.3.4" % Test
),
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => "1.9.8"
case _ => "2.0.0"
}
},
scriptedLaunchOpts :=
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value),
scriptedBufferLog := false,
mimaPreviousArtifacts := Set.empty,
)
.enablePlugins(SbtPlugin)
lazy val sbtPluginSmithy4s = project
.in(file("sbtPluginSmithy4s"))
.dependsOn(sbtPlugin)
.settings(
name := "smithy-scala-tools-sbt-smithy4s",
libraryDependencies += Defaults.sbtPluginExtra(
"com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.19.11",
(pluginCrossBuild / sbtBinaryVersion).value,
(update / scalaBinaryVersion).value,
),
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => "1.9.8"
case _ => "2.0.0"
}
},
scriptedLaunchOpts :=
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value),
scriptedBufferLog := false,
mimaPreviousArtifacts := Set.empty,
)
.enablePlugins(SbtPlugin)
lazy val root = project
.in(file("."))
.aggregate(core, sbtPlugin, sbtPluginSmithy4s)
.enablePlugins(NoPublishPlugin)