Skip to content

Commit

Permalink
Merge pull request #297 from alexarchambault/publish
Browse files Browse the repository at this point in the history
Publish individual indices on Maven Central
  • Loading branch information
alexarchambault authored Oct 23, 2024
2 parents 7e4368b + bfea4d2 commit a6b65af
Show file tree
Hide file tree
Showing 8 changed files with 630 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish
on:
push:
branches:
- master
pull_request:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: coursier/[email protected]
- uses: coursier/[email protected]
with:
jvm: 11
- name: Publish local
run: cd publish && ./mill -i __.publishLocal
if: github.ref != 'refs/heads/master'
env:
PUBLISH_SECRET_KEY: ${{ secrets.PUBLISH_SECRET_KEY }}
PUBLISH_SECRET_KEY_PASSWORD: ${{ secrets.PUBLISH_SECRET_KEY_PASSWORD }}
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}
- run: echo "$PGP_SECRET" | base64 --decode | gpg --batch --import
if: github.ref == 'refs/heads/master'
env:
PGP_SECRET: ${{ secrets.PUBLISH_SECRET_KEY }}
- name: Publish
run: cd publish && ./mill -i ci.publishSonatype --tasks __.publishArtifacts
if: github.ref == 'refs/heads/master'
env:
PUBLISH_SECRET_KEY: ${{ secrets.PUBLISH_SECRET_KEY }}
PUBLISH_SECRET_KEY_PASSWORD: ${{ secrets.PUBLISH_SECRET_KEY_PASSWORD }}
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: coursier/[email protected]
with:
jvm: 11
- run: ./scala-cli.sh compile .
- run: ./scala-cli.sh compile src

fmt:
runs-on: ubuntu-latest
Expand All @@ -24,4 +24,5 @@ jobs:
- uses: coursier/[email protected]
with:
jvm: 11
- run: ./scala-cli.sh fmt . --check
apps: scalafmt
- run: scalafmt --test
2 changes: 1 addition & 1 deletion .github/workflows/update-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: coursier/[email protected]
with:
jvm: 11
- run: ./scala-cli.sh .
- run: ./scala-cli.sh src
env:
GH_TOKEN: ${{ secrets.INDEX_GITHUB_TOKEN }}
- name: Create Pull Request
Expand Down
1 change: 1 addition & 0 deletions publish/.config/mill-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.0-RC3-68-d5c638
3 changes: 3 additions & 0 deletions publish/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bloop/
.bsp/
out/
123 changes: 123 additions & 0 deletions publish/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`

import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.api.WorkspaceRoot
import mill.scalalib._
import mill.scalalib.publish._

import scala.concurrent.duration._

trait IndexModule extends Cross.Module[String] with PublishModule {
def moduleName = s"index-$crossValue"
def pomSettings = PomSettings(
description = s"JVM index for $crossValue",
organization = "io.get-coursier.jvm.indices",
url = "https://github.com/coursier/jvm-index",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("io.get-coursier", "jvm-index"),
developers = Seq(
Developer("alexarchambault", "Alex Archambault", "https://github.com/alexarchambault")
)
)
def publishVersion = VcsVersion.vcsState().format()
def sonatypeUri = "https://s01.oss.sonatype.org/service/local"
def sonatypeSnapshotUri = "https://s01.oss.sonatype.org/content/repositories/snapshots"

def indexFile = T.source {
PathRef(T.workspace / os.up / "indices" / s"$crossValue.json")
}

def indexResourceDir = T {
val dest = T.dest
os.copy.over(
indexFile().path,
dest / "coursier/jvm/indices/v1" / s"$crossValue.json",
createFolders = true
)
PathRef(dest)
}

def resources = T.sources(
Seq(indexResourceDir())
)
}

lazy val osCpus =
os.list(WorkspaceRoot.workspaceRoot / os.up / "indices")
.filter(_.last.endsWith(".json"))
.filter(os.isFile)
.map(_.last.stripSuffix(".json"))

object index extends Cross[IndexModule](osCpus)

object ci extends Module {

// same publishing stuff I copy-paste in all my projects 😬

private def publishSonatype0(
credentials: String,
pgpPassword: String,
data: Seq[PublishModule.PublishData],
timeout: Duration,
log: mill.api.Logger
): Unit = {

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 SonatypePublisher(
uri = "https://s01.oss.sonatype.org/service/local",
snapshotUri = "https://s01.oss.sonatype.org/content/repositories/snapshots",
credentials = credentials,
signed = isRelease,
gpgArgs = Seq(
"--passphrase",
pgpPassword,
"--no-tty",
"--pinentry-mode",
"loopback",
"--batch",
"--yes",
"-a",
"-b"
),
readTimeout = timeout.toMillis.toInt,
connectTimeout = timeout.toMillis.toInt,
log = log,
workspace = os.pwd,
env = sys.env,
awaitTimeout = timeout.toMillis.toInt,
stagingRelease = isRelease
)

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

def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) =
T.command {
val timeout = 10.minutes
val credentials = sys.env("PUBLISH_USER") + ":" + sys.env("PUBLISH_PASSWORD")
val pgpPassword = sys.env("PUBLISH_SECRET_KEY_PASSWORD")
val data = T.sequence(tasks.value)()

publishSonatype0(
credentials = credentials,
pgpPassword = pgpPassword,
data = data,
timeout = timeout,
log = T.ctx().log
)
}
}
Loading

0 comments on commit a6b65af

Please sign in to comment.