Skip to content

Commit

Permalink
Prepare for initial 0.1.0 release.
Browse files Browse the repository at this point in the history
 * Bump version to 0.1.0 official.
 * Create CHANGELOG.md
 * Create RELEASING.md
 * Update build scripts for `maven-publish` and `signing`
 * Update README.md for separate runtime/generator usage.
  • Loading branch information
darronschall committed Dec 6, 2022
1 parent 06a2221 commit 296c05a
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2022-12-05

Initial Release
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# PBandK Service Generator for Twirp
# PBandK Service Generator and Runtime for Twirp KMM

The project is a [service generator plugin](https://github.com/streem/pbandk#service-code-generation) for [PBandK](https://github.com/streem/pbandk) that generates Kotlin client integration for [Twirp](https://github.com/twitchtv/twirp) services. The generated client code leverages [PBandK](https://github.com/streem/pbandk) for protobuf messages, [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization) for [JSON handling of Twirp service errors](https://twitchtv.github.io/twirp/docs/errors.html), and [KTor](https://github.com/ktorio/ktor) for HTTP. All of these choices enable the generated client code to be leveraged in [Kotlin Multiplatform Mobile](https://kotlinlang.org/lp/mobile/) projects, sharing the network integration layer with both iOS and Android native apps.
This project is a [service generator plugin](https://github.com/streem/pbandk#service-code-generation) for [PBandK](https://github.com/streem/pbandk) that generates Kotlin client integration for [Twirp](https://github.com/twitchtv/twirp) services. The generated client code leverages [PBandK](https://github.com/streem/pbandk) for protobuf messages, [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization) for [JSON handling of Twirp service errors](https://twitchtv.github.io/twirp/docs/errors.html), and [KTor](https://github.com/ktorio/ktor) for HTTP. All of these choices enable the generated client code to be leveraged in [Kotlin Multiplatform Mobile](https://kotlinlang.org/lp/mobile/) projects, sharing the network integration layer with both iOS and Android native apps.

## Usage
There are two parts to this project - the [generator](./generator) itself, and the supporting [runtime](./runtime) for leveraging the generated service code.

Download the latest release, currently `0.1.0-SNAPSHOT`, and pass it to `protoc` via `pbandk`:
## Generator

In general, follow [PBandK Usage](https://github.com/streem/pbandk#usage) instructions, but supply the `twirp-kmm-generator` as the `kotlin_service_gen` option as described in [PBandK's Service Code Generation documentation](https://github.com/streem/pbandk#service-code-generation).

### Usage

Download the latest release, currently `0.1.0`, and pass it to `protoc` via `pbandk`:

```bash
# Download the library to ~
cd ~/
curl -O https://repo1.maven.org/maven2/com/collectiveidea/twirp/twirp-kmm-generator/0.1.0-SNAPSHOT/twirp-kmm-generator-0.1.0-SNAPSHOT.jar
curl -O https://github.com/collectiveidea/twirp-kmm/releases/download/0.1.0/twirp-kmm-generator-0.1.0.jar
```


Pass the jar and generator class name as the `kotlin_service_gen` option to `pbandk_out`:

```bash
cd ~/exampleProject
protoc --pbandk_out=kotlin_service_gen='~/twirp-kmm-generator-0.1.0-SNAPSHOT.jar|com.collectiveidea.twirp.Generator',kotlin_package=com.example.api:src/main/kotlin src/main/proto/example.proto
protoc --pbandk_out=kotlin_service_gen='~/twirp-kmm-generator-0.1.0.jar|com.collectiveidea.twirp.Generator',kotlin_package=com.example.api:src/main/kotlin src/main/proto/example.proto
```

# Build
### Build

To build the library locally, run:

Expand All @@ -33,3 +42,24 @@ Then, the built version can be used, instead of the latest release, by supplying
protoc --pbandk_out=kotlin_service_gen='/Users/darron/Development/twirp-kmm/generator/build/libs/twirp-kmm-generator-0.1.0-SNAPSHOT.jar|com.collectiveidea.twirp.Generator',kotlin_package=com.example.api:shared/src/commonMain/kotlin shared/src/commonMain/proto/example.proto
```

## Runtime

The runtime provides an [`installTwirp`](./runtime/src/commonMain/kotlin/com/collectiveidea/twirp/HttpClientTwirpHelper.kt) helper for configuration a KTor HTTPClient for Twirp integration.

First, add the runtime as a dependency:

```
implementation "com.collectiveidea.twirp:twirp-kmm-runtime:0.1.0"
```

Then, configure the HTTPClient and pass the client into the generated service constructor:

```kotlin
val client = HttpClient(engine) {
installTwirp(baseUrl)
}

val exampleService = ExampleServiceImpl(client)
```

Service methods throw a [`ServiceException`](./runtime/src/commonMain/kotlin/com/collectiveidea/twirp/ServiceException.kt) on error. The `ServiceException` contains the parsed error response from the Twirp service JSON body.
44 changes: 44 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Releasing

1. Update `version` in `gradle.properties` to the release version.

2. Update the `CHANGELOG.md`.

3. Update the `README.md` to reflect the new release version number.

4. Commit

```
$ git commit -am "Prepare version X.Y.Z"
```

5. Tag

```
$ git tag -am "Version X.Y.Z" X.Y.Z
```

6. Push!

```
$ git push && git push --tags
```

7. Build (generator)

```
$ ./gradlew build
```

8. Create GitHub Release
1. Visit the [New Releases](https://github.com/collectiveidea/twirp-kmm/releases/new) page.
2. Supply release version and changelog
3. Upload `generator/build/libs/twirp-kmm-generator-X.Y.Z.jar` artifact.

9. Publish (runtime)

```
$ ./gradlew publish
```

10. Visit [Sonatype Nexus](https://s01.oss.sonatype.org) and promote the artifact.
39 changes: 39 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,42 @@ allprojects {
google()
}
}

fun gradlePropertyOrEnvironmentVariable(name: String) = (project.findProperty(name) ?: System.getenv(name)) as? String

val signingKeyAsciiArmored = gradlePropertyOrEnvironmentVariable("SIGNING_KEY")
val signingKeyPassword = gradlePropertyOrEnvironmentVariable("SIGNING_PASSWORD")
if (signingKeyAsciiArmored != null) {
subprojects {
plugins.withType<SigningPlugin> {
configure<SigningExtension> {
useInMemoryPgpKeys(signingKeyAsciiArmored, signingKeyPassword)
sign(extensions.getByType<PublishingExtension>().publications)
}
}
}
}

val sonatypeUsername = gradlePropertyOrEnvironmentVariable("SONATYPE_USERNAME")
val sonatypePassword = gradlePropertyOrEnvironmentVariable("SONATYPE_PASSWORD")
if (sonatypeUsername != null) {
subprojects {
plugins.withType<MavenPublishPlugin>() {
configure<PublishingExtension> {
repositories {
maven {
name = "oss"
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = if (version.toString().endsWith("-SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl

credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
37 changes: 37 additions & 0 deletions buildSrc/src/main/kotlin/MavenPublicationExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import org.gradle.api.publish.maven.MavenPublication

fun MavenPublication.configureTwirpKmmPOM(pomDescription: String) {
val pomName = artifactId

pom {
name.set(pomName)
description.set(pomDescription)

licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}

url.set("https://github.com/collectiveidea/twirp-kmm")

issueManagement {
system.set("Github")
url.set("https://github.com/collectiveidea/twirp-kmm/issues")
}

scm {
connection.set("https://github.com/collectiveidea/twirp-kmm.git")
url.set("https://github.com/collectiveidea/twirp-kmm")
}

developers {
developer {
id.set("collectiveidea")
name.set("Collective Idea")
url.set("https://github.com/collectiveidea")
}
}
}
}
16 changes: 16 additions & 0 deletions generator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
plugins {
id("org.jetbrains.kotlin.jvm")
`maven-publish`
signing
}

repositories {
mavenCentral()
}

description = "Twirp service generator PBandK plugin for use in Kotlin Multiplatform Mobile projects."

dependencies {
compileOnly("pro.streem.pbandk:pbandk-runtime:0.14.1")
compileOnly("pro.streem.pbandk:protoc-gen-pbandk-lib:0.14.1")
Expand All @@ -28,3 +32,15 @@ tasks.jar {
)
}
}

val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

publishing {
publications.withType<MavenPublication> {
artifact(javadocJar.get())

configureTwirpKmmPOM(project.description!!)
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version=0.1.0-SNAPSHOT
group=com.collectiveidea
version=0.1.0
group=com.collectiveidea.twirp

kotlin.code.style=official

Expand Down
16 changes: 16 additions & 0 deletions runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.serialization")
`maven-publish`
signing
}

description = "Runtime for Twirp service generator PBandK plugin for use in Kotlin Multiplatform Mobile projects."

kotlin {
android {
publishAllLibraryVariants()
Expand Down Expand Up @@ -67,3 +71,15 @@ android {
}
namespace = "com.collectiveidea"
}

val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

publishing {
publications.withType<MavenPublication> {
artifact(javadocJar.get())

configureTwirpKmmPOM(project.description!!)
}
}

0 comments on commit 296c05a

Please sign in to comment.