Skip to content

Commit aa64cc5

Browse files
Publishing
1 parent 1a9effa commit aa64cc5

File tree

5 files changed

+117
-18
lines changed

5 files changed

+117
-18
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ jobs:
4141
- "3.8.2"
4242
name: Test on Scala ${{ matrix.scala }}
4343
steps:
44-
- uses: actions/checkout@v4
45-
- uses: actions/setup-java@v4
44+
- uses: actions/checkout@v6
4645
with:
47-
distribution: temurin
48-
java-version: 17
49-
cache: sbt
50-
- name: Install sbt
51-
run: |
52-
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
53-
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
54-
sudo apt-get update
55-
sudo apt-get install -y sbt
46+
fetch-depth: 0
47+
- uses: coursier/cache-action@v8
48+
- uses: coursier/setup-action@v3.0.0
49+
with:
50+
jvm: "temurin:1.17.0.15"
51+
apps: sbt
5652
- name: Run tests
5753
run: sbt "++${{ matrix.scala }}; tests/test"

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Sonatype Release
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags: ["*"]
7+
8+
jobs:
9+
release-tag:
10+
runs-on: ubuntu-latest
11+
12+
name: ${{ startsWith(github.ref, 'refs/tags/') && 'Publish Tag as Release' || 'Publish Snapshot' }}
13+
14+
steps:
15+
- uses: actions/checkout@v6
16+
with:
17+
fetch-depth: 0
18+
- uses: coursier/cache-action@v8
19+
- name: Import GPG key for signing the release
20+
uses: crazy-max/ghaction-import-gpg@v7
21+
with:
22+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
23+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
24+
- uses: coursier/setup-action@v3.0.0
25+
with:
26+
jvm: "temurin:1.17.0.15"
27+
apps: sbt
28+
- name: Publish all projects
29+
run: sbt ci-release
30+
env:
31+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
32+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}

build.sbt

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import com.jsuereth.sbtpgp.PgpKeys.publishSigned
2+
3+
// Used to publish snapshots to Maven Central.
4+
val mavenCentralSnapshots = "Maven Central Snapshots" at "https://central.sonatype.com/repository/maven-snapshots"
5+
6+
// Versions:
7+
18
val scala2_13 = "2.13.16"
29

310
val scala3Versions = Seq(
@@ -13,18 +20,75 @@ val scala3Latest = scala3Versions.last
1320

1421
val newtypeVersion = "0.4.4"
1522

16-
ThisBuild / organization := "com.kubuszok"
17-
ThisBuild / versionScheme := Some("early-semver")
23+
// Common settings:
24+
25+
val publishSettings = Seq(
26+
organization := "com.kubuszok",
27+
homepage := Some(url("https://github.com/MateuszKubuszok/scala-newtype-compat")),
28+
organizationHomepage := Some(url("https://kubuszok.com")),
29+
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
30+
scmInfo := Some(
31+
ScmInfo(
32+
url("https://github.com/MateuszKubuszok/scala-newtype-compat/"),
33+
"scm:git:git@github.com:MateuszKubuszok/scala-newtype-compat.git"
34+
)
35+
),
36+
startYear := Some(2026),
37+
developers := List(
38+
Developer("MateuszKubuszok", "Mateusz Kubuszok", "", url("https://github.com/MateuszKubuszok"))
39+
),
40+
pomExtra := (
41+
<issueManagement>
42+
<system>GitHub issues</system>
43+
<url>https://github.com/MateuszKubuszok/scala-newtype-compat/issues</url>
44+
</issueManagement>
45+
),
46+
publishTo := {
47+
if (isSnapshot.value) Some(mavenCentralSnapshots)
48+
else localStaging.value
49+
},
50+
publishMavenStyle := true,
51+
Test / publishArtifact := false,
52+
pomIncludeRepository := {
53+
_ => false
54+
},
55+
versionScheme := Some("early-semver"),
56+
git.useGitDescribe := true,
57+
git.uncommittedSignifier := None,
58+
// Sonatype ignores isSnapshot setting and only looks at -SNAPSHOT suffix in version:
59+
// https://central.sonatype.org/publish/publish-maven/#performing-a-snapshot-deployment
60+
// meanwhile sbt-git used to set up SNAPSHOT if there were uncommitted changes:
61+
// https://github.com/sbt/sbt-git/issues/164
62+
// (now this suffix is empty by default) so we need to fix it manually.
63+
git.gitUncommittedChanges := git.gitCurrentTags.value.isEmpty,
64+
git.uncommittedSignifier := Some("SNAPSHOT")
65+
)
66+
67+
val noPublishSettings =
68+
Seq(publish / skip := true, publishArtifact := false)
69+
70+
// Modules:
1871

1972
lazy val root = project
2073
.in(file("."))
74+
.enablePlugins(GitVersioning, GitBranchPrompt)
75+
.settings(publishSettings)
76+
.settings(noPublishSettings)
2177
.settings(
22-
publish / skip := true,
23-
crossScalaVersions := Nil
78+
name := "scala-newtype-compat-root",
79+
crossScalaVersions := Nil,
80+
commands += Command.command("ci-release") { state =>
81+
val extracted = Project.extract(state)
82+
val tags = extracted.get(git.gitCurrentTags)
83+
val cmd = if (tags.nonEmpty) "publishSigned ; sonaRelease" else "publishSigned"
84+
cmd :: state
85+
}
2486
)
2587
.aggregate(compat, plugin, tests)
2688

2789
lazy val compat = project
90+
.enablePlugins(GitVersioning, GitBranchPrompt)
91+
.settings(publishSettings)
2892
.settings(
2993
name := "newtype-compat",
3094
crossScalaVersions := scala2_13 +: scala3Versions,
@@ -36,6 +100,8 @@ lazy val compat = project
36100
)
37101

38102
lazy val plugin = project
103+
.enablePlugins(GitVersioning, GitBranchPrompt)
104+
.settings(publishSettings)
39105
.settings(
40106
name := "newtype-plugin",
41107
crossScalaVersions := scala3Versions,
@@ -45,9 +111,11 @@ lazy val plugin = project
45111

46112
lazy val tests = project
47113
.dependsOn(compat)
114+
.enablePlugins(GitVersioning, GitBranchPrompt)
115+
.settings(publishSettings)
116+
.settings(noPublishSettings)
48117
.settings(
49118
name := "newtype-compat-tests",
50-
publish / skip := true,
51119
crossScalaVersions := scala2_13 +: scala3Versions,
52120
scalaVersion := scala3Latest,
53121
scalacOptions ++= {

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.10.11
1+
sbt.version=1.12.6

project/plugins.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2")
1+
// git
2+
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0")
3+
// publishing
4+
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")

0 commit comments

Comments
 (0)