Skip to content

Commit

Permalink
update ci release to publish to maven central (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolang authored Jul 7, 2024
1 parent 8fe40ca commit 14f480e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
continue-on-error: false
needs:
- ci
if: ${{ github.event_name != 'pull_request' }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Git Checkout
uses: actions/checkout@v4
Expand All @@ -191,10 +191,16 @@ jobs:
- name: Cache Dependencies
uses: coursier/cache-action@v6
- name: Release
run: sbt +publish
run: |-
echo "$PGP_SECRET" | base64 -d -i - > /tmp/signing-key.gpg
&& echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
&& (echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)
&& sbt '+publishSigned; sonatypeCentralRelease'
env:
ARTIFACT_REGISTRY_USERNAME: ${{ vars.ARTIFACT_REGISTRY_USERNAME }}
ARTIFACT_REGISTRY_PASSWORD: ${{ secrets.ARTIFACT_REGISTRY_PASSWORD }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
release-docs:
name: Release Docs
runs-on: ubuntu-latest
Expand Down
63 changes: 39 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zio.sbt.githubactions.{Job, Step}
import zio.sbt.githubactions.{Job, Step, Condition}
enablePlugins(ZioSbtEcosystemPlugin, ZioSbtCiPlugin)

lazy val _scala2 = "2.13.14"
Expand All @@ -7,10 +7,25 @@ lazy val _scala3 = "3.3.3"

inThisBuild(
List(
name := "ZIO Google Cloud Pub/Sub",
organization := "com.anymindgroup",
licenses := Seq(License.Apache2),
homepage := Some(url("https://github.com/AnyMindGroup/zio-pubsub")),
name := "ZIO Google Cloud Pub/Sub",
organization := "com.anymindgroup",
licenses := Seq(License.Apache2),
homepage := Some(url("https://github.com/AnyMindGroup/zio-pubsub")),
developers := List(
Developer(id = "rolang", name = "Roman Langolf", email = "rolang@pm.me", url = url("https://github.com/rolang")),
Developer(
id = "dutch3883",
name = "Panuwach Boonyasup",
email = "dutch3883@hotmail.com",
url = url("https://github.com/dutch3883"),
),
Developer(
id = "qhquanghuy",
name = "Huy Nguyen",
email = "huy_ngq@flinters.vn",
url = url("https://github.com/qhquanghuy"),
),
),
zioVersion := "2.1.5",
scala213 := _scala2,
scala3 := _scala3,
Expand Down Expand Up @@ -44,20 +59,26 @@ inThisBuild(
})
case j => j
},
sonatypeCredentialHost := xerial.sbt.Sonatype.sonatypeCentralHost,
// remove the release step modification once public
ciReleaseJobs := ciReleaseJobs.value.map(j =>
j.copy(steps = j.steps.map {
case Step.SingleStep("Release", _, _, _, _, _, _) =>
Step.SingleStep(
name = "Release",
run = Some("sbt +publish"),
env = Map(
"ARTIFACT_REGISTRY_USERNAME" -> "${{ vars.ARTIFACT_REGISTRY_USERNAME }}",
"ARTIFACT_REGISTRY_PASSWORD" -> "${{ secrets.ARTIFACT_REGISTRY_PASSWORD }}",
),
)
case s => s
})
j.copy(
steps = j.steps.map {
case Step.SingleStep(name @ "Release", _, _, _, _, _, env) =>
Step.SingleStep(
name = name,
run = Some(
"""|echo "$PGP_SECRET" | base64 -d -i - > /tmp/signing-key.gpg
| && echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
| && (echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)
| && sbt '+publishSigned; sonatypeCentralRelease'""".stripMargin
),
env = env,
)
case s => s
},
condition = Some(Condition.Expression("startsWith(github.ref, 'refs/tags/v')")),
)
),
scalafmt := true,
scalafmtSbtCheck := true,
Expand All @@ -84,16 +105,10 @@ lazy val commonSettings = List(
Compile / scalacOptions --= sys.env.get("CI").fold(Seq("-Xfatal-warnings"))(_ => Nil),
Test / scalafixConfig := Some(new File(".scalafix_test.conf")),
Test / scalacOptions --= Seq("-Xfatal-warnings"),
credentials += {
for {
username <- sys.env.get("ARTIFACT_REGISTRY_USERNAME")
apiKey <- sys.env.get("ARTIFACT_REGISTRY_PASSWORD")
} yield Credentials("https://asia-maven.pkg.dev", "asia-maven.pkg.dev", username, apiKey)
}.getOrElse(Credentials(Path.userHome / ".ivy2" / ".credentials")),
) ++ scalafixSettings

val releaseSettings = List(
publishTo := Some("AnyChat Maven" at "https://asia-maven.pkg.dev/anychat-staging/maven")
publishTo := sonatypePublishToBundle.value
)

val noPublishSettings = List(
Expand Down
13 changes: 9 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
val zioSbtVersion = "0.4.0-alpha.28"
addSbtPlugin("dev.zio" % "zio-sbt-website" % zioSbtVersion)
addSbtPlugin("dev.zio" % "zio-sbt-ci" % zioSbtVersion)
addSbtPlugin("dev.zio" % "zio-sbt-ecosystem" % zioSbtVersion exclude ("org.scala-native", "sbt-scala-native"))
addSbtPlugin("dev.zio" % "zio-sbt-website" % zioSbtVersion)

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
// need sbt-sonatype version which supports new Sonatype Central API added in v3.11.0 https://github.com/xerial/sbt-sonatype/releases/tag/v3.11.0
// might be removed later once zio-sbt-ci / sbt-ci-release update sbt-sonatype
addSbtPlugin("dev.zio" % "zio-sbt-ci" % zioSbtVersion exclude ("org.xerial.sbt", "sbt-sonatype"))
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.11.0")

// zio-sbt-ecosystem depends on scala-native 0.5.x which breaks the build, for now only 0.4.x is supported
addSbtPlugin("dev.zio" % "zio-sbt-ecosystem" % zioSbtVersion exclude ("org.scala-native", "sbt-scala-native"))
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")

addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")

Expand Down

0 comments on commit 14f480e

Please sign in to comment.