Skip to content

Commit 423e414

Browse files
authored
Add Gradle and GitHub Actions tooling to package for Maven Central (#59)
* Maven publishing for ldk-node-android * GHA to publish ldk-node-android to Maven Central * Maven Publish for ldk-node-jvm * GHA action to publish ldk-node-jvm * Copy .so file if building with Linux host * Point everything upstream * Set Android libraryVersion to 0.0.1-SNAPSHOT
1 parent 319f4ae commit 423e414

File tree

9 files changed

+338
-3
lines changed

9 files changed

+338
-3
lines changed

.github/workflows/publish-android.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish ldk-node-android to Maven Central
2+
on: [workflow_dispatch]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-20.04
7+
steps:
8+
- name: "Check out PR branch"
9+
uses: actions/checkout@v2
10+
11+
- name: "Cache"
12+
uses: actions/cache@v2
13+
with:
14+
path: |
15+
~/.cargo/registry
16+
~/.cargo/git
17+
./target
18+
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
19+
20+
- name: "Set up JDK"
21+
uses: actions/setup-java@v2
22+
with:
23+
distribution: temurin
24+
java-version: 11
25+
26+
- name: "Install Rust Android targets"
27+
run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
28+
29+
- name: "Build ldk-node-android library"
30+
run: |
31+
export PATH=$PATH:$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin
32+
./scripts/uniffi_bindgen_generate_kotlin_android.sh
33+
34+
- name: "Publish to Maven Local and Maven Central"
35+
env:
36+
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.PGP_KEY_ID }}
37+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SECRET_KEY }}
38+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PGP_PASSPHRASE }}
39+
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.NEXUS_USERNAME }}
40+
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.NEXUS_PASSWORD }}
41+
run: |
42+
cd bindings/kotlin/ldk-node-android
43+
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository

.github/workflows/publish-jvm.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Publish ldk-node-jvm to Maven Central
2+
on: [workflow_dispatch]
3+
4+
jobs:
5+
build-jvm-macOS-M1-native-lib:
6+
name: "Create M1 and x86_64 JVM native binaries"
7+
runs-on: macos-12
8+
steps:
9+
- name: "Checkout publishing branch"
10+
uses: actions/checkout@v2
11+
12+
- name: Cache
13+
uses: actions/cache@v3
14+
with:
15+
path: |
16+
~/.cargo/registry
17+
~/.cargo/git
18+
./target
19+
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
20+
21+
- name: Set up JDK
22+
uses: actions/setup-java@v2
23+
with:
24+
distribution: temurin
25+
java-version: 11
26+
27+
- name: Install aarch64 Rust target
28+
run: rustup target add aarch64-apple-darwin
29+
30+
- name: Build ldk-node-jvm library
31+
run: |
32+
./scripts/uniffi_bindgen_generate_kotlin.sh
33+
34+
# build aarch64 + x86_64 native libraries and upload
35+
- name: Upload macOS native libraries for reuse in publishing job
36+
uses: actions/upload-artifact@v3
37+
with:
38+
# name: no name is required because we upload the entire directory
39+
# the default name "artifact" will be used
40+
path: /Users/runner/work/ldk-node/ldk-node/bindings/kotlin/ldk-node-jvm/lib/src/main/resources/
41+
42+
build-jvm-full-library:
43+
name: "Create full ldk-node-jvm library"
44+
needs: [build-jvm-macOS-M1-native-lib]
45+
runs-on: ubuntu-20.04
46+
steps:
47+
- name: "Check out PR branch"
48+
uses: actions/checkout@v2
49+
50+
- name: "Cache"
51+
uses: actions/cache@v2
52+
with:
53+
path: |
54+
~/.cargo/registry
55+
~/.cargo/git
56+
./target
57+
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
58+
59+
- name: "Set up JDK"
60+
uses: actions/setup-java@v2
61+
with:
62+
distribution: temurin
63+
java-version: 11
64+
65+
- name: "Build ldk-node-jvm library"
66+
run: |
67+
./scripts/uniffi_bindgen_generate_kotlin.sh
68+
69+
- name: Download macOS native libraries from previous job
70+
uses: actions/download-artifact@v3
71+
id: download
72+
with:
73+
# download the artifact created in the prior job (named "artifact")
74+
name: artifact
75+
path: ./bindings/kotlin/ldk-node-jvm/lib/src/main/resources/
76+
77+
- name: "Publish to Maven Local and Maven Central"
78+
env:
79+
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.PGP_KEY_ID }}
80+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SECRET_KEY }}
81+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PGP_PASSPHRASE }}
82+
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.NEXUS_USERNAME }}
83+
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.NEXUS_PASSWORD }}
84+
run: |
85+
cd bindings/kotlin/ldk-node-jvm
86+
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository

bindings/kotlin/ldk-node-android/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,23 @@ plugins {
1414
// library version is defined in gradle.properties
1515
val libraryVersion: String by project
1616

17+
// These properties are required here so that the nexus publish-plugin
18+
// finds a staging profile with the correct group (group is otherwise set as "")
19+
// and knows whether to publish to a SNAPSHOT repository or not
20+
// https://github.com/gradle-nexus/publish-plugin#applying-the-plugin
21+
group = "org.lightningdevkit"
1722
version = libraryVersion
23+
24+
nexusPublishing {
25+
repositories {
26+
create("sonatype") {
27+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
28+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
29+
30+
val ossrhUsername: String? by project
31+
val ossrhPassword: String? by project
32+
username.set(ossrhUsername)
33+
password.set(ossrhPassword)
34+
}
35+
}
36+
}

bindings/kotlin/ldk-node-android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536m
22
android.useAndroidX=true
33
android.enableJetifier=true
44
kotlin.code.style=official
5-
libraryVersion=0.1
5+
libraryVersion=0.0.1-SNAPSHOT

bindings/kotlin/ldk-node-android/lib/build.gradle.kts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.*
22
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
33

4+
// library version is defined in gradle.properties
5+
val libraryVersion: String by project
6+
47
plugins {
58
id("com.android.library")
69
id("org.jetbrains.kotlin.android") version "1.6.10"
10+
11+
id("maven-publish")
12+
id("signing")
713
}
814

915
repositories {
@@ -49,3 +55,79 @@ dependencies {
4955
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
5056
androidTestImplementation("org.jetbrains.kotlin:kotlin-test-junit")
5157
}
58+
59+
afterEvaluate {
60+
publishing {
61+
publications {
62+
create<MavenPublication>("maven") {
63+
groupId = "org.lightningdevkit"
64+
artifactId = "ldk-node-android"
65+
version = libraryVersion
66+
67+
from(components["release"])
68+
pom {
69+
name.set("ldk-node-android")
70+
description.set(
71+
"LDK Node, a ready-to-go node implementation built using LDK."
72+
)
73+
url.set("https://lightningdevkit.org")
74+
licenses {
75+
license {
76+
name.set("APACHE 2.0")
77+
url.set("https://github.com/lightningdevkit/ldk-node/blob/main/LICENSE-APACHE")
78+
}
79+
license {
80+
name.set("MIT")
81+
url.set("https://github.com/lightningdevkit/ldk-node/blob/main/LICENSE-MIT")
82+
}
83+
}
84+
developers {
85+
developer {
86+
id.set("tnull")
87+
name.set("Elias Rohrer")
88+
email.set("[email protected]")
89+
}
90+
developer {
91+
id.set("jurvis")
92+
name.set("Jurvis Tan")
93+
email.set("[email protected]")
94+
}
95+
}
96+
scm {
97+
connection.set("scm:git:github.com/lightningdevkit/ldk-node.git")
98+
developerConnection.set("scm:git:ssh://github.com/lightningdevkit/ldk-node.git")
99+
url.set("https://github.com/lightningdevkit/ldk-node/tree/main")
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
107+
signing {
108+
val signingKeyId: String? by project
109+
val signingKey: String? by project
110+
val signingPassword: String? by project
111+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
112+
sign(publishing.publications)
113+
}
114+
115+
//tasks.named<Test>("test") {
116+
// // Use JUnit Platform for unit tests.
117+
// useJUnitPlatform()
118+
//
119+
// testLogging {
120+
// events(PASSED, SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
121+
// exceptionFormat = FULL
122+
// showExceptions = true
123+
// showCauses = true
124+
// showStackTraces = true
125+
// showStandardStreams = true
126+
// }
127+
//}
128+
129+
//// This task dependency ensures that we build the bindings
130+
//// binaries before running the tests
131+
//tasks.withType<KotlinCompile> {
132+
// dependsOn("buildAndroidLib")
133+
//}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
}
5+
dependencies {
6+
classpath("com.android.tools.build:gradle:7.1.2")
7+
}
8+
}
9+
10+
plugins {
11+
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
12+
}
13+
14+
// library version is defined in gradle.properties
15+
val libraryVersion: String by project
16+
17+
// These properties are required here so that the nexus publish-plugin
18+
// finds a staging profile with the correct group (group is otherwise set as "")
19+
// and knows whether to publish to a SNAPSHOT repository or not
20+
// https://github.com/gradle-nexus/publish-plugin#applying-the-plugin
21+
group = "org.lightningdevkit"
22+
version = libraryVersion
23+
24+
nexusPublishing {
25+
repositories {
26+
create("sonatype") {
27+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
28+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
29+
30+
val ossrhUsername: String? by project
31+
val ossrhPassword: String? by project
32+
username.set(ossrhUsername)
33+
password.set(ossrhPassword)
34+
}
35+
}
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.jvmargs=-Xmx1536m
2+
kotlin.code.style=official
3+
libraryVersion=0.0.1-SNAPSHOT

bindings/kotlin/ldk-node-jvm/lib/build.gradle.kts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.*
22
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
33

4+
// library version is defined in gradle.properties
5+
val libraryVersion: String by project
6+
47
plugins {
58
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
69
id("org.jetbrains.kotlin.jvm") version "1.7.10"
710

811
// Apply the java-library plugin for API and implementation separation.
9-
`java-library`
12+
id("java-library")
13+
id("maven-publish")
14+
id("signing")
1015
}
1116

1217
repositories {
@@ -48,3 +53,59 @@ tasks.named<Test>("test") {
4853
showStandardStreams = true
4954
}
5055
}
56+
57+
afterEvaluate {
58+
publishing {
59+
publications {
60+
create<MavenPublication>("maven") {
61+
groupId = "org.lightningdevkit"
62+
artifactId = "ldk-node-jvm"
63+
version = libraryVersion
64+
65+
from(components["java"])
66+
pom {
67+
name.set("ldk-node-jvm")
68+
description.set(
69+
"LDK Node, a ready-to-go node implementation built using LDK."
70+
)
71+
url.set("https://lightningdevkit.org")
72+
licenses {
73+
license {
74+
name.set("APACHE 2.0")
75+
url.set("https://github.com/lightningdevkit/ldk-node/blob/main/LICENSE-APACHE")
76+
}
77+
license {
78+
name.set("MIT")
79+
url.set("https://github.com/lightningdevkit/ldk-node/blob/main/LICENSE-MIT")
80+
}
81+
}
82+
developers {
83+
developer {
84+
id.set("tnull")
85+
name.set("Elias Rohrer")
86+
email.set("[email protected]")
87+
}
88+
developer {
89+
id.set("jurvis")
90+
name.set("Jurvis Tan")
91+
email.set("[email protected]")
92+
}
93+
}
94+
scm {
95+
connection.set("scm:git:github.com/lightningdevkit/ldk-node.git")
96+
developerConnection.set("scm:git:ssh://github.com/lightningdevkit/ldk-node.git")
97+
url.set("https://github.com/lightningdevkit/ldk-node/tree/main")
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
105+
signing {
106+
val signingKeyId: String? by project
107+
val signingKey: String? by project
108+
val signingPassword: String? by project
109+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
110+
sign(publishing.publications)
111+
}

scripts/uniffi_bindgen_generate_kotlin.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
55
PACKAGE_DIR="org/lightningdevkit/ldknode"
66
UNIFFI_BINDGEN_BIN="cargo run --features=uniffi/cli --bin uniffi-bindgen"
77

8+
DYNAMIC_LIB_PATH="target/release/libldk_node.dylib"
9+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
10+
DYNAMIC_LIB_PATH="target/release/libldk_node.so"
11+
fi
12+
813
#rustup target add aarch64-apple-darwin
914
#cargo build --target aarch64-apple-darwin || exit 1
1015
cargo build --release || exit 1
@@ -15,4 +20,4 @@ mkdir -p "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/darwin-aarch64/ |
1520

1621
cp "$TARGET_DIR"/"$PACKAGE_DIR"/ldk_node.kt "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin/"$PACKAGE_DIR"/ || exit 1
1722
#cp ./target/aarch64-apple-darwin/debug/libldk_node.dylib "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/darwin-aarch64/libldk_node.dylib || exit 1
18-
cp target/release/libldk_node.dylib "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/libldk_node.dylib || exit 1
23+
cp $DYNAMIC_LIB_PATH "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/libldk_node.dylib || exit 1

0 commit comments

Comments
 (0)