Skip to content

Commit 4d9476c

Browse files
committed
Update Publish
1 parent adc25d8 commit 4d9476c

File tree

3 files changed

+32
-74
lines changed

3 files changed

+32
-74
lines changed

.github/workflows/publish.yml

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
name: Publish Library
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
release_type:
7-
description: "Select release target"
8-
required: true
9-
type: choice
10-
options:
11-
- local
12-
- github
13-
- sonatype
14-
- all
15-
release:
16-
types: [created]
4+
push:
5+
tags:
6+
- "*.*.*" # v1.0.0, v0.1.5 등의 태그가 푸시되면 자동 실행
7+
workflow_dispatch: # 필요시 수동 실행도 가능
178

189
jobs:
1910
publish:
@@ -39,22 +30,8 @@ jobs:
3930
- name: Run tests
4031
run: ./gradlew :library:test
4132

42-
# ✅ Local test build
43-
- name: Publish to Maven Local
44-
if: github.event.inputs.release_type == 'local'
45-
run: ./gradlew :library:publishToMavenLocal
46-
47-
# ✅ GitHub Packages
48-
- name: Publish to GitHub Packages
49-
if: github.event.inputs.release_type == 'github' || github.event.inputs.release_type == 'all' || github.event_name == 'release'
50-
env:
51-
GITHUB_USERNAME: ${{ github.actor }}
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
run: ./gradlew :library:publishReleasePublicationToGitHubPackagesRepository
54-
55-
# ✅ GPG Configuration (for Sonatype signing)
33+
# ✅ GPG Configuration (for Maven Central signing)
5634
- name: Configure GPG
57-
if: github.event.inputs.release_type == 'sonatype' || github.event.inputs.release_type == 'all' || github.event_name == 'release'
5835
env:
5936
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
6037
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
@@ -93,21 +70,18 @@ jobs:
9370
9471
gpg --list-secret-keys
9572
96-
# ✅ Publish to Maven Central (Sonatype)
73+
# ✅ Publish to Maven Central via Central Portal API
74+
# Uses https://central.sonatype.com/api/v1/publisher/upload
9775
- name: Publish to Maven Central
98-
if: github.event.inputs.release_type == 'sonatype' || github.event.inputs.release_type == 'all' || github.event_name == 'release'
9976
env:
100-
SONATYPE_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }}
101-
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}
77+
ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
78+
ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
10279
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
10380
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
10481
run: |
105-
./gradlew :library:publishReleasePublicationToSonatypeRepository \
106-
-PsonatypeUsername=$SONATYPE_USERNAME \
107-
-PsonatypePassword=$SONATYPE_PASSWORD \
108-
-Psigning.keyId=$GPG_KEY_ID \
109-
-Psigning.password="$ORG_GRADLE_PROJECT_signingPassword" \
110-
--no-daemon --stacktrace
82+
./gradlew :library:publishAllPublicationsToCentralPortal \
83+
--no-daemon \
84+
--stacktrace
11185
11286
# ✅ Upload artifacts
11387
- name: Upload build artifacts

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ composeBom = "2024.09.00"
1111
appcompat = "1.7.1"
1212
material = "1.12.0"
1313
coroutines = "1.8.0"
14+
nmcp = "0.0.8"
1415

1516
[libraries]
1617
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -38,4 +39,5 @@ android-application = { id = "com.android.application", version.ref = "agp" }
3839
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3940
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
4041
android-library = { id = "com.android.library", version.ref = "agp" }
42+
nmcp = { id = "com.gradleup.nmcp", version.ref = "nmcp" }
4143

library/build.gradle.kts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(libs.plugins.android.library)
33
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.nmcp)
45
id("maven-publish")
56
id("signing")
67
}
@@ -107,26 +108,7 @@ publishing {
107108
}
108109

109110
repositories {
110-
// Local Maven
111-
maven {
112-
name = "local"
113-
url = uri(layout.buildDirectory.dir("repo"))
114-
}
115-
116-
// Sonatype OSSRH
117-
maven {
118-
name = "sonatype"
119-
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
120-
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
121-
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
122-
123-
credentials {
124-
username = findProperty("SONATYPE_USERNAME") as String? ?: System.getenv("SONATYPE_USERNAME")
125-
password = findProperty("SONATYPE_PASSWORD") as String? ?: System.getenv("SONATYPE_PASSWORD")
126-
}
127-
}
128-
129-
// GitHub Packages
111+
// GitHub Packages (optional)
130112
maven {
131113
name = "GitHubPackages"
132114
url = uri("https://maven.pkg.github.com/pelagornis/kotlin-rex")
@@ -138,27 +120,27 @@ publishing {
138120
}
139121
}
140122

141-
// Signing Configuration
123+
// Signing Configuration (for Maven Central)
142124
signing {
143-
isRequired = gradle.taskGraph.allTasks.any {
144-
it.name.contains("publishReleasePublicationToSonatypeRepository") ||
145-
it.name.contains("publishReleasePublicationToGitHubPackagesRepository")
125+
val signingKey = findProperty("signingKey") as String? ?: System.getenv("ORG_GRADLE_PROJECT_signingKey")
126+
val signingPassword = findProperty("signingPassword") as String? ?: System.getenv("ORG_GRADLE_PROJECT_signingPassword")
127+
128+
if (!signingKey.isNullOrEmpty() && !signingPassword.isNullOrEmpty()) {
129+
// In-memory signing (for CI/CD)
130+
useInMemoryPgpKeys(signingKey, signingPassword)
131+
} else {
132+
// Use GPG agent for local signing
133+
useGpgCmd()
146134
}
147135

148-
if (isRequired) {
149-
val signingKey = findProperty("signingKey") as String? ?: System.getenv("ORG_GRADLE_PROJECT_signingKey")
150-
val signingPassword = findProperty("signingPassword") as String? ?: System.getenv("ORG_GRADLE_PROJECT_signingPassword")
151-
152-
if (!signingKey.isNullOrEmpty() && !signingPassword.isNullOrEmpty()) {
153-
useInMemoryPgpKeys(signingKey, signingPassword)
154-
} else {
155-
useGpgCmd()
156-
}
157-
158-
sign(publishing.publications["release"])
159-
}
136+
sign(publishing.publications["release"])
160137
}
161138

139+
// Maven Central Publishing via Central Portal API
140+
// https://central.sonatype.com/api/v1/
141+
// The nmcp plugin automatically uploads to Central Portal API
142+
// It reads SONATYPE_USERNAME and SONATYPE_PASSWORD from environment variables
143+
162144
// Debug Task
163145
tasks.register("printPublicationInfo") {
164146
doLast {

0 commit comments

Comments
 (0)