Skip to content

Commit 2401211

Browse files
committed
setup maven central
1 parent a55003a commit 2401211

File tree

6 files changed

+188
-86
lines changed

6 files changed

+188
-86
lines changed

.github/workflows/BuildTest.yml renamed to .github/workflows/BuildTestSnapshot.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Test
1+
name: Build, test and snapshot
22

33
on:
44
push:
@@ -9,7 +9,8 @@ on:
99
- 'epic/**'
1010
pull_request:
1111
branches:
12-
- 'staging'
12+
- 'epic/**'
13+
types: [ closed ]
1314

1415
jobs:
1516
build_test:
@@ -62,4 +63,49 @@ jobs:
6263
uses: actions/upload-artifact@v4
6364
with:
6465
name: test-results
65-
path: lib/build/outputs/androidTest-results
66+
path: lib/build/outputs/androidTest-results
67+
68+
snapshot:
69+
# This job must explicitly depend on build_test
70+
needs: build_test
71+
# Run for direct commits to epic branches OR when PRs are merged into epic branches
72+
# AND only when build_test succeeds
73+
if: >
74+
success() &&
75+
((github.event_name == 'push' && startsWith(github.ref, 'refs/heads/epic/')) ||
76+
(github.event_name == 'pull_request' && github.event.action == 'closed' &&
77+
github.event.pull_request.merged == true && startsWith(github.base_ref, 'epic/')))
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Checkout code
81+
uses: actions/checkout@v4
82+
83+
- name: Set up JDK
84+
uses: actions/setup-java@v3
85+
with:
86+
distribution: 'temurin'
87+
java-version: '17'
88+
89+
- name: Restore gradle.properties
90+
env:
91+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
92+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
93+
shell: bash
94+
run: |
95+
mkdir -p ~/.gradle/
96+
echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
97+
echo "MAVEN_CENTRAL_USERNAME=${MAVEN_CENTRAL_USERNAME}">> ~/.gradle/gradle.properties
98+
echo "MAVEN_CENTRAL_PASSWORD=${MAVEN_CENTRAL_PASSWORD}">> ~/.gradle/gradle.properties
99+
echo "IS_SNAPSHOT_RELEASE=true">> ~/.gradle/gradle.properties
100+
cat ~/.gradle/gradle.properties
101+
102+
- name: Setup Gradle with caching
103+
uses: gradle/actions/setup-gradle@v4
104+
with:
105+
cache-read-only: false
106+
107+
- name: Setup Android SDK
108+
uses: android-actions/setup-android@v3
109+
110+
- name: Publish SNAPSHOT
111+
run: ./gradlew design-library:publishMavenPublicationToSonatypeSnapshotsRepository
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'staging'
7+
pull_request:
8+
branches:
9+
- 'staging'
10+
types: [closed]
11+
workflow_dispatch: # Allow manual triggering
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch all history for proper versioning
21+
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: 'temurin'
26+
java-version: '17'
27+
cache: 'gradle'
28+
29+
- name: Set up Gradle
30+
uses: gradle/actions/setup-gradle@v3
31+
32+
- name: Create Gradle Properties
33+
env:
34+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
35+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
36+
W3W_GPG_SECRET_KEY: ${{ secrets.W3W_GPG_SECRET_KEY }}
37+
W3W_GPG_PUBLIC_KEY: ${{ secrets.W3W_GPG_PUBLIC_KEY }}
38+
W3W_GPG_PASSPHRASE: ${{ secrets.W3W_GPG_PASSPHRASE }}
39+
W3W_GITHUB_TOKEN: ${{ secrets.W3W_GITHUB_TOKEN }}
40+
shell: bash
41+
run: |
42+
mkdir -p ~/.gradle/
43+
echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
44+
echo "MAVEN_CENTRAL_USERNAME=${MAVEN_CENTRAL_USERNAME}" >> ~/.gradle/gradle.properties
45+
echo "MAVEN_CENTRAL_PASSWORD=${MAVEN_CENTRAL_PASSWORD}" >> ~/.gradle/gradle.properties
46+
echo "W3W_GITHUB_TOKEN=${W3W_GITHUB_TOKEN}" >> ~/.gradle/gradle.properties
47+
echo "W3W_GPG_SECRET_KEY=${W3W_GPG_SECRET_KEY}" >> ~/.gradle/gradle.properties
48+
echo "W3W_GPG_PUBLIC_KEY=${W3W_GPG_PUBLIC_KEY}" >> ~/.gradle/gradle.properties
49+
echo "W3W_GPG_PASSPHRASE=${W3W_GPG_PASSPHRASE}" >> ~/.gradle/gradle.properties
50+
cat ~/.gradle/gradle.properties
51+
52+
- name: Clean build
53+
run: ./gradlew clean
54+
55+
- name: Publish to local staging repository
56+
run: ./gradlew :lib:publishMavenPublicationToStagingLocalRepository
57+
58+
- name: Release with JReleaser
59+
run: ./gradlew :lib:jreleaserFullRelease
60+
env:
61+
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
JRELEASER_GIT_ROOT_SEARCH: true
63+
64+
- name: JReleaser output
65+
if: always()
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: jreleaser-release
69+
path: |
70+
lib/build/jreleaser/trace.log
71+
lib/build/jreleaser/output.properties
72+
73+
- name: Upload staging directory
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: staging-deploy
77+
path: lib/build/staging-deploy/

.github/workflows/Release.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
alias(libs.plugins.kotlin.android) apply false
1313
alias(libs.plugins.compose.compiler) apply false
1414
alias(libs.plugins.gradle.ktlint) apply false
15+
alias(libs.plugins.jreleaser) apply false
1516
alias(libs.plugins.autonomousapps.analysis)
1617
}
1718

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ compileSdk = "35"
55
minSdk = "24"
66
autonomousappsAnalysis = "1.20.0"
77
gradleKtlint = "10.1.0"
8+
jreleaser = "1.17.0"
89

910
# CameraX
1011
camerax = "1.4.2"
@@ -115,6 +116,7 @@ test-mlkit-text-korean = { group = "com.google.mlkit", name = "text-recognition-
115116
[plugins]
116117
android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" }
117118
gradle-ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "gradleKtlint" }
119+
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
118120
autonomousapps-analysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "autonomousappsAnalysis" }
119121
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
120122
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

lib/build.gradle.kts

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import java.net.URI
1+
import java.util.Base64
22

33
plugins {
44
alias(libs.plugins.android.library)
@@ -7,6 +7,7 @@ plugins {
77
id(libs.plugins.signing.get().pluginId)
88
alias(libs.plugins.dokka)
99
alias(libs.plugins.compose.compiler)
10+
id(libs.plugins.jreleaser.get().pluginId)
1011
id(libs.plugins.kotlin.parcelize.get().pluginId)
1112
id(libs.plugins.jacoco.get().pluginId)
1213
}
@@ -160,37 +161,18 @@ tasks.register("checkSnapshotDependencies") {
160161

161162
//region publishing
162163

163-
val ossrhUsername = findProperty("OSSRH_USERNAME") as String?
164-
val ossrhPassword = findProperty("OSSRH_PASSWORD") as String?
165-
val signingKey = findProperty("SIGNING_KEY") as String?
166-
val signingKeyPwd = findProperty("SIGNING_KEY_PWD") as String?
167-
164+
//region publishing
168165
publishing {
169-
repositories {
170-
maven {
171-
name = "sonatype"
172-
val releasesRepoUrl =
173-
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
174-
val snapshotsRepoUrl =
175-
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
176-
url = if (version.toString()
177-
.endsWith("SNAPSHOT")
178-
) URI.create(snapshotsRepoUrl) else URI.create(releasesRepoUrl)
179-
180-
credentials {
181-
username = ossrhUsername
182-
password = ossrhPassword
183-
}
184-
}
185-
publications {
186-
create<MavenPublication>("Maven") {
187-
artifactId = "w3w-android-ocr-components"
188-
groupId = "com.what3words"
189-
version = project.version.toString()
190-
afterEvaluate {
191-
from(components["release"])
192-
}
166+
publications {
167+
create<MavenPublication>("maven") {
168+
afterEvaluate {
169+
from(components["release"])
193170
}
171+
172+
groupId = "com.what3words"
173+
artifactId = "w3w-android-ocr-components"
174+
version = project.version.toString()
175+
194176
withType(MavenPublication::class.java) {
195177
val publicationName = name
196178
val dokkaJar =
@@ -230,13 +212,57 @@ publishing {
230212
}
231213
}
232214
}
215+
// POM metadata
216+
}
217+
}
218+
219+
repositories {
220+
maven {
221+
name = "sonatypeSnapshots"
222+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
223+
credentials {
224+
username = findProperty("MAVEN_CENTRAL_USERNAME") as? String
225+
password = findProperty("MAVEN_CENTRAL_PASSWORD") as? String
226+
}
227+
}
228+
maven {
229+
name = "stagingLocal"
230+
url = uri(layout.buildDirectory.dir("staging-deploy").get().asFile.absolutePath)
233231
}
234232
}
235233
}
236234

237-
signing {
238-
useInMemoryPgpKeys(signingKey, signingKeyPwd)
239-
sign(publishing.publications)
235+
jreleaser {
236+
release {
237+
github {
238+
repoOwner = "what3words"
239+
overwrite = true
240+
}
241+
}
242+
243+
signing {
244+
active.set(org.jreleaser.model.Active.ALWAYS)
245+
armored.set(true)
246+
publicKey.set(String(Base64.getDecoder().decode(findProperty("W3W_GPG_PUBLIC_KEY")?.toString())))
247+
secretKey.set(String(Base64.getDecoder().decode(findProperty("W3W_GPG_SECRET_KEY")?.toString())))
248+
passphrase.set(findProperty("W3W_GPG_PASSPHRASE")?.toString())
249+
}
250+
deploy {
251+
maven {
252+
mavenCentral {
253+
create("sonatype") {
254+
active.set(org.jreleaser.model.Active.ALWAYS)
255+
url.set("https://central.sonatype.com/api/v1/publisher")
256+
stagingRepository(layout.buildDirectory.dir("staging-deploy").get().asFile.absolutePath)
257+
username.set(findProperty("MAVEN_CENTRAL_USERNAME")?.toString())
258+
password.set(findProperty("MAVEN_CENTRAL_PASSWORD")?.toString())
259+
verifyPom.set(false)
260+
setStage(org.jreleaser.model.api.deploy.maven.MavenCentralMavenDeployer.Stage.UPLOAD.toString())
261+
}
262+
}
263+
}
264+
}
240265
}
266+
//endregion
241267

242268
//endregion

0 commit comments

Comments
 (0)