Skip to content

Publish snapshots #4976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ jobs:
publish:
needs: [all_tests_passed]
runs-on: ubuntu-24.04
# Only publish on release until Mill supports publishing snapshots to Maven Central
# https://github.com/com-lihaoyi/mill/issues/4421
if: startsWith(github.ref, 'refs/tags/')
if: github.event_name == 'push'

steps:
- name: Checkout
Expand All @@ -87,12 +85,21 @@ jobs:
with:
jvm: temurin:11
- name: Publish
run: ./mill publish.publishAll
run: |
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
BUNDLE_NAME=$(./mill show unipublish.artifactMetadata | jq -r '.group + "." + .id + "-" + .version')
SHOULD_RELEASE=$(./mill show unipublish.autoRelease)
PLUGIN_VERSIONS=$(./mill show plugin.publishableVersions)
PLUGIN_MODULES=$(echo "${PLUGIN_VERSIONS}" | jq -r 'map("plugin.cross[" + . + "]") | join(",")')
./mill mill.javalib.SonatypeCentralPublishModule/ \
--shouldRelease "$SHOULD_RELEASE" \
--bundleName "$BUNDLE_NAME" \
--publishArtifacts "{unipublish,${PLUGIN_MODULES}}.publishArtifacts"
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MILL_PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
MILL_PGP_SECRET_BASE64: ${{ secrets.PGP_SECRET }}
MILL_SONATYPE_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MILL_SONATYPE_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
- run: |
VERSION=$(./mill show unipublish.publishVersion | tr -d \")
echo "Published version: $VERSION" >> $GITHUB_STEP_SUMMARY
Expand Down
67 changes: 0 additions & 67 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ package build

import mill._
import mill.api.{BuildCtx, Result}
import mill.javalib.SonatypeCentralPublishModule
import mill.scalalib._
import mill.scalalib.scalafmt._
import mill.scalalib.publish.{Artifact, SonatypePublisher}
import com.lumidion.sonatype.central.client.core.{PublishingType, SonatypeCredentials}

object v extends Module {

Expand Down Expand Up @@ -69,10 +66,6 @@ object v extends Module {
}
}

// Projects that we publish to Maven
def publishedProjects: Seq[SonatypeCentralPublishModule] =
pluginScalaCrossVersions.filterNot(isScala3).map(plugin.cross(_)) ++ Seq(unipublish)

val scalaVersion = scalaCrossVersions.head
val jmhVersion = "1.37"
val osLib = mvn"com.lihaoyi::os-lib:0.10.7" // 0.11 requires Java 11
Expand Down Expand Up @@ -366,63 +359,3 @@ trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScalaPlugin
}

object unipublish extends Unipublish

/** Tasks for publishing to Sonatype */
object publish extends Module {

def getEnvVar(name: String) = Task.Command {
Task.env.get(name) match {
case Some(value) => Result.Success(value)
case None => Result.Failure(s"Must define environment variable $name")
}
}

def sonatypeCredentials: Task[SonatypeCredentials] = Task.Anon {
val username = getEnvVar("MAVEN_CENTRAL_USERNAME")()
val password = getEnvVar("MAVEN_CENTRAL_PASSWORD")()
SonatypeCredentials(username, password)
}

def importPgp = Task.Anon {
val secret = getEnvVar("PGP_SECRET")()
os.call(
("gpg", "--import", "--no-tty", "--batch", "--yes"),
stdin = java.util.Base64.getDecoder.decode(secret)
)
}

// We can't directly use mill.scalalib.SonatypeCentralPublishModule.publishAll because
// there's no easy way to programmatically pick which Modules to publish, and
// we don't want to publish everything.
// We aren't yet publishing Scala 3 cross-builds nor the CIRCT bindings.
def publishAll(): Command[Unit] = Task.Command {
val artifacts: Seq[(Seq[(os.Path, String)], Artifact)] =
Task.traverse(v.publishedProjects)(_.publishArtifacts)().map { case PublishModule.PublishData(a, s) =>
(s.map { case (p, f) => (p.path, f) }, a)
}
// unipublish is the main Chisel artifact, use it to make bundle name
val PublishModule.PublishData(Artifact(group, id, version), _) = unipublish.publishArtifacts()
val bundleName = Some(s"$group.$id-$version")

val sonatypeCreds = sonatypeCredentials()
// Import GPG, this is mutating the environment
importPgp()
val pgpPass = getEnvVar("PGP_PASSPHRASE")()
val gpgArgs = PublishModule.defaultGpgArgsForPassphrase(Some(pgpPass))

new SonatypeCentralPublisher(
sonatypeCreds,
gpgArgs,
readTimeout = 10 * 60 * 1000,
connectTimeout = 10 * 1000,
Task.log,
BuildCtx.workspaceRoot,
Task.env,
awaitTimeout = 10 * 60 * 1000
).publishAll(
publishingType = PublishingType.USER_MANAGED, // confirm in UI
singleBundleName = bundleName,
artifacts*
)
}
}
4 changes: 4 additions & 0 deletions plugin/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import build._
object `package` extends Module {
// https://github.com/com-lihaoyi/mill/issues/3693
object cross extends Cross[Plugin](v.pluginScalaCrossVersions)

def publishableVersions = Task {
v.pluginScalaCrossVersions.filter(!v.isScala3(_))
}
}

trait Plugin extends CrossSbtModule with ScalafmtModule with ChiselPublishModule {
Expand Down
7 changes: 6 additions & 1 deletion release.mill
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package build
import mill._
import mill.api.{BuildCtx, Result}
import mill.javalib.SonatypeCentralPublishModule
import mill.javalib.api.JvmWorkerUtil.matchingVersions
import mill.scalalib._
import mill.scalalib.scalafmt._
import mill.scalalib.publish._
Expand Down Expand Up @@ -38,6 +37,12 @@ trait Unipublish extends ScalaModule with ChiselPublishModule {

def scalaVersion = v.scalaVersion

/** Should we release without user intervention?
*
* True for snapshots, false otherwise.
*/
def autoRelease = Task { publishVersion().endsWith("-SNAPSHOT") }

// This is published as chisel
override def artifactName = "chisel"

Expand Down
Loading