Skip to content

Commit 74d717d

Browse files
authored
Refactor publishing logic (#4901)
mill-ci-release is archived and we were accidentally publishing the compiler plugin for Scala 3.
1 parent 76c9f13 commit 74d717d

File tree

7 files changed

+78
-14
lines changed

7 files changed

+78
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
with:
8686
jvm: temurin:11
8787
- name: Publish
88-
run: ./mill -i io.kipp.mill.ci.release.ReleaseModule/publishAll
88+
run: ./mill publish.publishAll
8989
env:
9090
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
9191
PGP_SECRET: ${{ secrets.PGP_SECRET }}

build.mill

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package build
22

33
import mill._
4+
import mill.api.Result
45
import mill.scalalib._
56
import mill.scalalib.scalafmt._
7+
import mill.scalalib.publish.{Artifact, SonatypePublisher}
68

79
import $packages._
810
import build._
@@ -59,6 +61,10 @@ object v extends Module {
5961
}
6062
}
6163

64+
// Projects that we publish to Maven
65+
def publishedProjects: Seq[PublishModule] =
66+
pluginScalaCrossVersions.filterNot(isScala3).map(plugin.cross(_)) ++ Seq(unipublish)
67+
6268
val scalaVersion = scalaCrossVersions.head
6369
val jmhVersion = "1.37"
6470
val osLib = ivy"com.lihaoyi::os-lib:0.10.0"
@@ -317,3 +323,66 @@ trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScalaPlugin
317323
}
318324

319325
object unipublish extends release.Unipublish
326+
327+
/** Tasks for publishing to Sonatype */
328+
object publish extends Module {
329+
330+
def getEnvVar(name: String) = Task.Command {
331+
Task.env.get(name) match {
332+
case Some(value) => Result.Success(value)
333+
case None => Result.Failure(s"Must define environment variable $name")
334+
}
335+
}
336+
337+
def sonatypeCredentials: Task[String] = Task.Anon {
338+
val username = getEnvVar("SONATYPE_USERNAME")()
339+
val password = getEnvVar("SONATYPE_PASSWORD")()
340+
s"$username:$password"
341+
}
342+
343+
def importPgp = Task.Anon {
344+
val secret = getEnvVar("PGP_SECRET")()
345+
os.call(
346+
("gpg", "--import", "--no-tty", "--batch", "--yes"),
347+
stdin = java.util.Base64.getDecoder.decode(secret)
348+
)
349+
}
350+
351+
// We can't directly use mill.scalalib.PublishModule.publishAll because
352+
// there's no easy way to programmatically pick which PublishModules to
353+
// publish, and we don't want to publish everything.
354+
// We aren't yet publishing Scala 3 cross-builds nor the CIRCT bindings.
355+
def publishAll(): Command[Unit] = Task.Command {
356+
val sonatypeUrl = "https://s01.oss.sonatype.org/service/local"
357+
val sonatypeSnapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots"
358+
359+
val artifacts: Seq[(Seq[(os.Path, String)], Artifact)] =
360+
Task.traverse(v.publishedProjects)(_.publishArtifacts)().map { case PublishModule.PublishData(a, s) =>
361+
(s.map { case (p, f) => (p.path, f) }, a)
362+
}
363+
364+
val sonatypeCreds = sonatypeCredentials()
365+
// Import GPG, this is mutating the environment
366+
importPgp()
367+
val pgpPass = getEnvVar("PGP_PASSPHRASE")()
368+
val gpgArgs = PublishModule.defaultGpgArgsForPassphrase(Some(pgpPass))
369+
370+
new SonatypePublisher(
371+
sonatypeUrl,
372+
sonatypeSnapshotUrl,
373+
sonatypeCreds,
374+
signed = true,
375+
gpgArgs,
376+
readTimeout = 10 * 60 * 1000,
377+
connectTimeout = 10 * 1000,
378+
Task.log,
379+
Task.workspace,
380+
Task.env,
381+
awaitTimeout = 10 * 60 * 1000,
382+
stagingRelease = true
383+
).publishAll(
384+
release = false, // We like to confirm in the Sonatype UI
385+
artifacts: _*
386+
)
387+
}
388+
}

circtpanamabinding/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object `package` extends RootModule with CIRCTPanamaBinding
1111

1212
// Java Codegen for all declared functions.
1313
// All of these functions are not private API which is subject to change.
14-
trait CIRCTPanamaBinding extends HasJextractGeneratedSources with release.BaseChiselPublishModule {
14+
trait CIRCTPanamaBinding extends HasJextractGeneratedSources with release.ChiselPublishModule {
1515
override def javadocOptions = Task(super.javadocOptions() ++ Seq("--enable-preview", "--release", "21"))
1616

1717
object utils extends Module {

panamaconverter/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait PanamaConverter
1919
with CrossModuleBase
2020
with HasScalaPlugin
2121
with ScalafmtModule
22-
with release.BaseChiselPublishModule {
22+
with release.ChiselPublishModule {
2323
def millSourcePath = super.millSourcePath / os.up
2424

2525
def panamaOMModule = panamaom.cross(crossScalaVersion)

panamalib/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait PanamaLib
1919
with HasCIRCTPanamaBindingModule
2020
with CrossModuleBase
2121
with ScalafmtModule
22-
with release.BaseChiselPublishModule {
22+
with release.ChiselPublishModule {
2323
def millSourcePath = super.millSourcePath / os.up
2424

2525
def circtPanamaBindingModule = circtpanamabinding

panamaom/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait PanamaOM
1818
with HasPanamaLibModule
1919
with CrossModuleBase
2020
with ScalafmtModule
21-
with release.BaseChiselPublishModule {
21+
with release.ChiselPublishModule {
2222
def millSourcePath = super.millSourcePath / os.up
2323

2424
def panamaLibModule = panamalib.cross(crossScalaVersion)

release.mill

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import mill.scalalib.publish._
77
import mill.api.Result
88
import mill.scalalib.api.ZincWorkerUtil.matchingVersions
99
import mill.util.Jvm.createJar
10-
import $ivy.`io.chris-kipp::mill-ci-release_mill0.12:0.2.1` // https://github.com/ckipp01/mill-ci-release/pull/143
11-
import io.kipp.mill.ci.release.{CiReleaseModule, SonatypeHost}
12-
import de.tobiasroeser.mill.vcs.version.VcsVersion // pulled in by mill-ci-release
10+
11+
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1`
12+
import de.tobiasroeser.mill.vcs.version.VcsVersion
1313

1414
import build._
1515

1616
/** Adds basic publishing information--useful for local publishing */
17-
trait BaseChiselPublishModule extends PublishModule {
17+
trait ChiselPublishModule extends PublishModule {
1818
// Publish information
1919
def pomSettings = PomSettings(
2020
description = artifactName(),
@@ -38,11 +38,6 @@ trait BaseChiselPublishModule extends PublishModule {
3838
)
3939
}
4040

41-
/** Integrates the Module into the Chisel CI publishing flow */
42-
trait ChiselPublishModule extends CiReleaseModule with BaseChiselPublishModule {
43-
override def sonatypeHost = Some(SonatypeHost.s01)
44-
}
45-
4641
/** Aggregate project for publishing Chisel as a single artifact
4742
*/
4843
trait Unipublish extends ScalaModule with ChiselPublishModule {

0 commit comments

Comments
 (0)