Skip to content

Commit bcdacfe

Browse files
committed
Re-enable SNAPSHOT publishing
Remove custom publishing logic, use upstream flow instead. This involves generating the list of plugin versions we publish.
1 parent 1a2980c commit bcdacfe

File tree

4 files changed

+25
-76
lines changed

4 files changed

+25
-76
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ jobs:
7171
publish:
7272
needs: [all_tests_passed]
7373
runs-on: ubuntu-24.04
74-
# Only publish on release until Mill supports publishing snapshots to Maven Central
75-
# https://github.com/com-lihaoyi/mill/issues/4421
76-
if: startsWith(github.ref, 'refs/tags/')
74+
if: github.event_name == 'push'
7775

7876
steps:
7977
- name: Checkout
@@ -87,12 +85,21 @@ jobs:
8785
with:
8886
jvm: temurin:11
8987
- name: Publish
90-
run: ./mill publish.publishAll
88+
run: |
89+
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
90+
BUNDLE_NAME=$(./mill show unipublish.artifactMetadata | jq -r '.group + "." + .id + "-" + .version')
91+
SHOULD_RELEASE=$(./mill show unipublish.autoRelease)
92+
PLUGIN_VERSIONS=$(./mill show plugin.publishableVersions)
93+
PLUGIN_MODULES=$(echo "${PLUGIN_VERSIONS}" | jq -r 'map("plugin.cross[" + . + "]") | join(",")')
94+
./mill mill.javalib.SonatypeCentralPublishModule/ \
95+
--shouldRelease "$SHOULD_RELEASE" \
96+
--bundleName "$BUNDLE_NAME" \
97+
--publishArtifacts "{unipublish,${PLUGIN_MODULES}}.publishArtifacts"
9198
env:
92-
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
93-
PGP_SECRET: ${{ secrets.PGP_SECRET }}
94-
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
95-
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
99+
MILL_PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
100+
MILL_PGP_SECRET_BASE64: ${{ secrets.PGP_SECRET }}
101+
MILL_SONATYPE_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
102+
MILL_SONATYPE_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
96103
- run: |
97104
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
98105
echo "Published version: $VERSION" >> $GITHUB_STEP_SUMMARY

build.mill

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ package build
77

88
import mill._
99
import mill.api.{BuildCtx, Result}
10-
import mill.javalib.SonatypeCentralPublishModule
1110
import mill.scalalib._
1211
import mill.scalalib.scalafmt._
13-
import mill.scalalib.publish.{Artifact, SonatypePublisher}
14-
import com.lumidion.sonatype.central.client.core.{PublishingType, SonatypeCredentials}
1512

1613
object v extends Module {
1714

@@ -69,10 +66,6 @@ object v extends Module {
6966
}
7067
}
7168

72-
// Projects that we publish to Maven
73-
def publishedProjects: Seq[SonatypeCentralPublishModule] =
74-
pluginScalaCrossVersions.filterNot(isScala3).map(plugin.cross(_)) ++ Seq(unipublish)
75-
7669
val scalaVersion = scalaCrossVersions.head
7770
val jmhVersion = "1.37"
7871
val osLib = mvn"com.lihaoyi::os-lib:0.10.7" // 0.11 requires Java 11
@@ -366,63 +359,3 @@ trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScalaPlugin
366359
}
367360

368361
object unipublish extends Unipublish
369-
370-
/** Tasks for publishing to Sonatype */
371-
object publish extends Module {
372-
373-
def getEnvVar(name: String) = Task.Command {
374-
Task.env.get(name) match {
375-
case Some(value) => Result.Success(value)
376-
case None => Result.Failure(s"Must define environment variable $name")
377-
}
378-
}
379-
380-
def sonatypeCredentials: Task[SonatypeCredentials] = Task.Anon {
381-
val username = getEnvVar("MAVEN_CENTRAL_USERNAME")()
382-
val password = getEnvVar("MAVEN_CENTRAL_PASSWORD")()
383-
SonatypeCredentials(username, password)
384-
}
385-
386-
def importPgp = Task.Anon {
387-
val secret = getEnvVar("PGP_SECRET")()
388-
os.call(
389-
("gpg", "--import", "--no-tty", "--batch", "--yes"),
390-
stdin = java.util.Base64.getDecoder.decode(secret)
391-
)
392-
}
393-
394-
// We can't directly use mill.scalalib.SonatypeCentralPublishModule.publishAll because
395-
// there's no easy way to programmatically pick which Modules to publish, and
396-
// we don't want to publish everything.
397-
// We aren't yet publishing Scala 3 cross-builds nor the CIRCT bindings.
398-
def publishAll(): Command[Unit] = Task.Command {
399-
val artifacts: Seq[(Seq[(os.Path, String)], Artifact)] =
400-
Task.traverse(v.publishedProjects)(_.publishArtifacts)().map { case PublishModule.PublishData(a, s) =>
401-
(s.map { case (p, f) => (p.path, f) }, a)
402-
}
403-
// unipublish is the main Chisel artifact, use it to make bundle name
404-
val PublishModule.PublishData(Artifact(group, id, version), _) = unipublish.publishArtifacts()
405-
val bundleName = Some(s"$group.$id-$version")
406-
407-
val sonatypeCreds = sonatypeCredentials()
408-
// Import GPG, this is mutating the environment
409-
importPgp()
410-
val pgpPass = getEnvVar("PGP_PASSPHRASE")()
411-
val gpgArgs = PublishModule.defaultGpgArgsForPassphrase(Some(pgpPass))
412-
413-
new SonatypeCentralPublisher(
414-
sonatypeCreds,
415-
gpgArgs,
416-
readTimeout = 10 * 60 * 1000,
417-
connectTimeout = 10 * 1000,
418-
Task.log,
419-
BuildCtx.workspaceRoot,
420-
Task.env,
421-
awaitTimeout = 10 * 60 * 1000
422-
).publishAll(
423-
publishingType = PublishingType.USER_MANAGED, // confirm in UI
424-
singleBundleName = bundleName,
425-
artifacts*
426-
)
427-
}
428-
}

plugin/package.mill

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import build._
1010
object `package` extends Module {
1111
// https://github.com/com-lihaoyi/mill/issues/3693
1212
object cross extends Cross[Plugin](v.pluginScalaCrossVersions)
13+
14+
def publishableVersions = Task {
15+
v.pluginScalaCrossVersions.filter(!v.isScala3(_))
16+
}
1317
}
1418

1519
trait Plugin extends CrossSbtModule with ScalafmtModule with ChiselPublishModule {

release.mill

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package build
33
import mill._
44
import mill.api.{BuildCtx, Result}
55
import mill.javalib.SonatypeCentralPublishModule
6-
import mill.javalib.api.JvmWorkerUtil.matchingVersions
76
import mill.scalalib._
87
import mill.scalalib.scalafmt._
98
import mill.scalalib.publish._
@@ -38,6 +37,12 @@ trait Unipublish extends ScalaModule with ChiselPublishModule {
3837

3938
def scalaVersion = v.scalaVersion
4039

40+
/** Should we release without user intervention?
41+
*
42+
* True for snapshots, false otherwise.
43+
*/
44+
def autoRelease = Task { publishVersion().endsWith("-SNAPSHOT") }
45+
4146
// This is published as chisel
4247
override def artifactName = "chisel"
4348

0 commit comments

Comments
 (0)