Skip to content

Commit 4bd9def

Browse files
authored
Restrict publish worflow to production env, remove auto snapshot publishing (#6)
* Restrict publish worflow to production env, remove auto snapshot publishing * Refactoring, allow usage of signing.local for snapshot publishing
1 parent a67f35b commit 4bd9def

File tree

8 files changed

+44
-65
lines changed

8 files changed

+44
-65
lines changed

.github/workflows/publish-snapshot.yml

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

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
publish:
1010
name: Publish to Maven Central
1111
runs-on: ubuntu-latest
12+
environment: production
1213

1314
steps:
1415
- name: Checkout code

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
.externalNativeBuild
99
.cxx
1010
local.properties
11+
signing.local
1112
firebase-debug.log

build.gradle.kts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
val signingProperties = java.util.Properties().apply {
4+
file("signing.local").takeIf { it.exists() }?.inputStream()?.use { load(it) }
5+
}
6+
7+
fun getSigningProperty(key: String): String? =
8+
providers.environmentVariable(key).orNull ?: signingProperties.getProperty(key)
9+
210
plugins {
311
alias(libs.plugins.android.application) apply false
412
alias(libs.plugins.android.library) apply false
@@ -15,8 +23,8 @@ nexusPublishing {
1523
sonatype {
1624
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
1725
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
18-
username.set(providers.environmentVariable("SONATYPE_USERNAME"))
19-
password.set(providers.environmentVariable("SONATYPE_PASSWORD"))
26+
username.set(getSigningProperty("SONATYPE_USERNAME"))
27+
password.set(getSigningProperty("SONATYPE_PASSWORD"))
2028
}
2129
}
2230
}
@@ -29,8 +37,8 @@ allprojects {
2937
name = "snapshot"
3038
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
3139
credentials {
32-
username = providers.environmentVariable("SONATYPE_USERNAME").orNull ?: ""
33-
password = providers.environmentVariable("SONATYPE_PASSWORD").orNull ?: ""
40+
username = getSigningProperty("SONATYPE_USERNAME") ?: ""
41+
password = getSigningProperty("SONATYPE_PASSWORD") ?: ""
3442
}
3543
}
3644
}

gradle/publishing.gradle.kts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import org.gradle.api.publish.PublishingExtension
22
import org.gradle.api.publish.maven.MavenPublication
3+
import org.gradle.plugins.signing.SigningExtension
4+
5+
val signingProperties = java.util.Properties().apply {
6+
rootProject.file("signing.local").takeIf { it.exists() }?.inputStream()?.use { load(it) }
7+
}
8+
9+
fun getSigningProperty(key: String): String? =
10+
System.getenv(key) ?: signingProperties.getProperty(key)
11+
12+
fun getSigningPropertyWithNewlines(key: String): String? =
13+
System.getenv(key) ?: signingProperties.getProperty(key)?.replace("\\n", "\n")
14+
15+
extra["signingProperties"] = signingProperties
16+
extra["getSigningProperty"] = ::getSigningProperty
317

418
plugins.withId("maven-publish") {
519
afterEvaluate {
620
extensions.configure<PublishingExtension> {
721
publications.withType<MavenPublication>().configureEach {
822
groupId = "com.mercari"
9-
version = System.getenv("VERSION") ?: project.property("navEntryScopeVersion") as String
23+
version = getSigningProperty("VERSION") ?: project.property("navEntryScopeVersion") as String
1024

1125
pom {
1226
url.set("https://github.com/mercari/nav-entry-scope-android")
@@ -38,4 +52,17 @@ plugins.withId("maven-publish") {
3852
}
3953
}
4054
}
55+
56+
plugins.withId("signing") {
57+
val publishing = extensions.getByType<PublishingExtension>()
58+
val signing = extensions.getByType<SigningExtension>()
59+
60+
val signingKey = getSigningPropertyWithNewlines("SIGNING_KEY")
61+
val signingPassword = getSigningProperty("SIGNING_PASSWORD")
62+
63+
if (signingKey != null && signingPassword != null) {
64+
signing.useInMemoryPgpKeys(signingKey, signingPassword)
65+
signing.sign(publishing.publications)
66+
}
67+
}
4168
}

gradle/signing.gradle.kts

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

nav-entry-scope/lib/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ afterEvaluate {
8383
}
8484
}
8585

86-
apply(from = rootProject.file("gradle/publishing.gradle.kts"))
87-
apply(from = rootProject.file("gradle/signing.gradle.kts"))
86+
apply(from = rootProject.file("gradle/publishing.gradle.kts"))

nav-entry-scope/processor/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ publishing {
4444
}
4545
}
4646

47-
apply(from = rootProject.file("gradle/publishing.gradle.kts"))
48-
apply(from = rootProject.file("gradle/signing.gradle.kts"))
47+
apply(from = rootProject.file("gradle/publishing.gradle.kts"))

0 commit comments

Comments
 (0)