Skip to content

Commit 3f8b7b6

Browse files
committed
Add publishing logic
1 parent 329e4b9 commit 3f8b7b6

6 files changed

Lines changed: 149 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Cache Gradle
2+
description: Caches Gradle files
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: actions/cache@v2
7+
with:
8+
path: |
9+
~/.gradle/caches
10+
~/.gradle/wrapper
11+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
12+
restore-keys: |
13+
${{ runner.os }}-gradle-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Cache Konan
2+
description: Caches Konan files
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: actions/cache@v2
7+
with:
8+
path: ~/.konan
9+
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
10+
restore-keys: |
11+
${{ runner.os }}-konan-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish a Kotlin release
2+
on:
3+
push:
4+
tags:
5+
- 'v[0-9]+.[0-9]+.[0-9]+'
6+
- 'v[0-9]+.[0-9]+.[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-Beta'
8+
- 'v[0-9]+.[0-9]+.[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-RC'
9+
- 'v[0-9]+.[0-9]+.[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-RC[0-9]+'
10+
- 'v[0-9]+.[0-9]+.[0-9]+-ALPHA-[0-9]+'
11+
- 'v[0-9]+.[0-9]+.[0-9]+-ALPHA-[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+'
12+
- 'v[0-9]+.[0-9]+.[0-9]+-ALPHA-[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-Beta'
13+
- 'v[0-9]+.[0-9]+.[0-9]+-ALPHA-[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-RC'
14+
- 'v[0-9]+.[0-9]+.[0-9]+-ALPHA-[0-9]+-kotlin-[0-9]+.[0-9]+.[0-9]+-RC[0-9]+'
15+
jobs:
16+
publish-kotlin-libraries:
17+
runs-on: macos-12
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
- name: Gradle Wrapper Validation
22+
uses: gradle/wrapper-validation-action@v1
23+
- name: Setup JDK
24+
uses: actions/setup-java@v2
25+
with:
26+
distribution: 'zulu'
27+
java-version: '11'
28+
- name: Cache Gradle
29+
uses: ./.github/actions/cache-gradle
30+
- name: Cache Konan
31+
uses: ./.github/actions/cache-konan
32+
- name: Publish to Sonatype
33+
run: ./gradlew publishAllPublicationsToSonatypeRepository
34+
env:
35+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
36+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
37+
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
38+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
39+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
plugins {
2+
`maven-publish`
3+
signing
4+
}
5+
6+
ext["signing.keyId"] = null
7+
ext["signing.password"] = null
8+
ext["signing.secretKey"] = null
9+
ext["signing.secretKeyRingFile"] = null
10+
ext["ossrhUsername"] = null
11+
ext["ossrhPassword"] = null
12+
val localPropsFile = project.rootProject.file("local.properties")
13+
if (localPropsFile.exists()) {
14+
localPropsFile.reader()
15+
.use { java.util.Properties().apply { load(it) } }
16+
.onEach { (name, value) -> ext[name.toString()] = value }
17+
} else {
18+
ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
19+
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
20+
ext["signing.secretKey"] = System.getenv("SIGNING_SECRET_KEY")
21+
ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
22+
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
23+
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
24+
}
25+
26+
val emptyJavadocJar by tasks.registering(Jar::class) {
27+
archiveClassifier.set("javadoc")
28+
}
29+
30+
fun getExtraString(name: String) = ext[name]?.toString()
31+
32+
publishing {
33+
repositories {
34+
maven {
35+
name = "sonatype"
36+
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
37+
credentials {
38+
username = getExtraString("ossrhUsername")
39+
password = getExtraString("ossrhPassword")
40+
}
41+
}
42+
}
43+
44+
publications.withType<MavenPublication> {
45+
artifact(emptyJavadocJar.get())
46+
47+
pom {
48+
name.set("KMM-ViewModel")
49+
description.set("Library to share Kotlin ViewModels with SwiftUI")
50+
url.set("https://github.com/rickclephas/KMM-ViewModel")
51+
licenses {
52+
license {
53+
name.set("MIT")
54+
url.set("https://opensource.org/licenses/MIT")
55+
}
56+
}
57+
developers {
58+
developer {
59+
id.set("rickclephas")
60+
name.set("Rick Clephas")
61+
email.set("rclephas@gmail.com")
62+
}
63+
}
64+
scm {
65+
url.set("https://github.com/rickclephas/KMM-ViewModel")
66+
}
67+
}
68+
}
69+
}
70+
71+
getExtraString("signing.keyId")?.let { keyId ->
72+
signing {
73+
getExtraString("signing.secretKey")?.let { secretKey ->
74+
useInMemoryPgpKeys(keyId, secretKey, getExtraString("signing.password"))
75+
}
76+
sign(publishing.publications)
77+
}
78+
}

kmm-viewmodel-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
alias(libs.plugins.android.library)
44
@Suppress("DSL_SCOPE_VIOLATION")
55
alias(libs.plugins.kotlin.multiplatform)
6+
`kmm-viewmodel-publish`
67
}
78

89
kotlin {

0 commit comments

Comments
 (0)