Skip to content

Commit

Permalink
Use mill-vcs-version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed May 15, 2023
1 parent b41cd4f commit a07fe94
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ jobs:
- run: .github/scripts/gpg-setup.sh
env:
PGP_SECRET: ${{ secrets.PUBLISH_SECRET_KEY }}
- run: ./mill -i io.kipp.mill.ci.release.ReleaseModule/publishAll
- run: ./mill -i publishSonatype __.publishArtifacts
shell: bash
env:
PGP_PASSPHRASE: ${{ secrets.PUBLISH_SECRET_KEY_PASSWORD }}
PGP_SECRET: ${{ secrets.PUBLISH_SECRET_KEY }}
SONATYPE_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.PUBLISH_USER }}
65 changes: 62 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import $file.project.deps, deps.{Deps, Versions}

import $ivy.`io.chris-kipp::mill-ci-release::0.1.6`
import $ivy.`com.github.lolgab::mill-mima::0.0.19`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.3.1`

import com.github.lolgab.mill.mima.Mima
import io.kipp.mill.ci.release.CiReleaseModule
import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.scalalib._

import java.util.Arrays

import scala.concurrent.duration.DurationInt

// Tell mill modules are under modules/
implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / "modules")

trait AmmSparkPublishModule extends CiReleaseModule {
trait AmmSparkPublishModule extends PublishModule {
import mill.scalalib.publish._
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
organization = "sh.almond",
Expand Down Expand Up @@ -271,3 +274,59 @@ class AlmondSpark(val crossScalaVersion: String) extends CrossSbtModule with Amm
)
}
}

def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) = T.command {
publishSonatype0(
data = define.Target.sequence(tasks.value)(),
log = T.ctx().log
)
}

def publishSonatype0(
data: Seq[PublishModule.PublishData],
log: mill.api.Logger
): Unit = {

val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
val pgpPassword = sys.env("PGP_PASSPHRASE")
val timeout = 10.minutes

val artifacts = data.map {
case PublishModule.PublishData(a, s) =>
(s.map { case (p, f) => (p.path, f) }, a)
}

val isRelease = {
val versions = artifacts.map(_._2.version).toSet
val set = versions.map(!_.endsWith("-SNAPSHOT"))
assert(
set.size == 1,
s"Found both snapshot and non-snapshot versions: ${versions.toVector.sorted.mkString(", ")}"
)
set.head
}
val publisher = new scalalib.publish.SonatypePublisher(
uri = "https://oss.sonatype.org/service/local",
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
credentials = credentials,
signed = true,
// format: off
gpgArgs = Seq(
"--detach-sign",
"--batch=true",
"--yes",
"--pinentry-mode", "loopback",
"--passphrase", pgpPassword,
"--armor",
"--use-agent"
),
// format: on
readTimeout = timeout.toMillis.toInt,
connectTimeout = timeout.toMillis.toInt,
log = log,
awaitTimeout = timeout.toMillis.toInt,
stagingRelease = isRelease
)

publisher.publishAll(isRelease, artifacts: _*)
}

0 comments on commit a07fe94

Please sign in to comment.