Skip to content

Commit c4ca27e

Browse files
authored
Re-enable SNAPSHOT publishing (#4976)
Remove custom Mill publishing logic, use upstream flow for release publishing. This involves generating the list of plugin versions we publish in bash + jq. The publishing flow does not seem to work for SNAPSHOTs, so instead call .publish on the relevant modules for SNAPSHOT publishing.
1 parent e62d810 commit c4ca27e

File tree

5 files changed

+36
-76
lines changed

5 files changed

+36
-76
lines changed

.github/scripts/publish.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
# Ideally Snapshots could use mill.javalib.SonatypeCentralPublishModule/ too
6+
# but it does not work for them on 1.0.1. It seems to publish to the wrong place.
7+
IS_SNAPSHOT=$(./mill show unipublish.isSnapshot)
8+
PLUGIN_VERSIONS=$(./mill show plugin.publishableVersions)
9+
PLUGIN_MODULES=$(jq -r 'map("plugin.cross[" + . + "]")' <<< "${PLUGIN_VERSIONS}")
10+
MODULES=$(jq -r '. + ["unipublish"]' <<< "${PLUGIN_MODULES}")
11+
if [[ "${IS_SNAPSHOT}" = "true" ]]; then
12+
for mod in $(jq -r '.[]' <<< "$MODULES"); do
13+
./mill ${mod}.publish
14+
done
15+
else
16+
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
17+
BUNDLE_NAME=$(./mill show unipublish.artifactMetadata | jq -r '.group + "." + .id + "-" + .version')
18+
MODULES_LIST=$(jq -r 'join(",")' <<< "${MODULES}")
19+
./mill mill.javalib.SonatypeCentralPublishModule/ \
20+
--shouldRelease "false" \
21+
--bundleName "$BUNDLE_NAME" \
22+
--publishArtifacts "{${MODULES_LIST}}.publishArtifacts"
23+
fi

.github/workflows/ci.yml

Lines changed: 6 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,12 @@ jobs:
8785
with:
8886
jvm: temurin:11
8987
- name: Publish
90-
run: ./mill publish.publishAll
88+
run: .github/scripts/publish.sh
9189
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 }}
90+
MILL_PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
91+
MILL_PGP_SECRET_BASE64: ${{ secrets.PGP_SECRET }}
92+
MILL_SONATYPE_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
93+
MILL_SONATYPE_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
9694
- run: |
9795
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
9896
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
@@ -363,63 +356,3 @@ trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScalaPlugin
363356
}
364357

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

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: 3 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,9 @@ trait Unipublish extends ScalaModule with ChiselPublishModule {
3837

3938
def scalaVersion = v.scalaVersion
4039

40+
/** Is this a SNAPSHOT release? */
41+
def isSnapshot = Task { publishVersion().endsWith("-SNAPSHOT") }
42+
4143
// This is published as chisel
4244
override def artifactName = "chisel"
4345

0 commit comments

Comments
 (0)