Skip to content

Commit

Permalink
Configure Sonatype repo publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
alllex committed Sep 22, 2023
1 parent 84cac9e commit 5c7aa87
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/.ci-java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21
28 changes: 28 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check

on:
workflow_dispatch: {}
pull_request: {}
push:
branches: [ main ]
tags: [ 'v*' ]

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: zulu
java-version-file: .github/workflows/.ci-java-version

- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
arguments: check
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
workflow_dispatch: {}
push:
tags:
- 'v*'

concurrency:
group: "release"
cancel-in-progress: false

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: zulu
java-version-file: .github/workflows/.ci-java-version

- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- name: Publish artifacts
run: ./gradlew :publishAllPublicationsToSonatypeRepository :closeSonatypeStagingRepository --no-parallel
env:
ORG_GRADLE_PROJECT_signingKeyId: ${{secrets.SIGNING_KEY_ID}}
ORG_GRADLE_PROJECT_signingKey: ${{secrets.SIGNING_KEY}}
ORG_GRADLE_PROJECT_signingPassword: ${{secrets.SIGNING_PASSWORD}}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.SONATYPE_USERNAME}}
ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.SONATYPE_PASSWORD}}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The bindings are generated directly from the source-of-truth [Bot API spec](http

### Alpha

- [ ] License
- [ ] Squash history
- [ ] Error handling

Expand Down
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
alias(libs.plugins.nexus.publish) // must be applied in the root project
}

nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ log4j = ["log4j-api", "log4j-core", "log4j-slf4j-impl"]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinTarget" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinTarget" }
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.0" }
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" }
#versions = { id = "com.github.ben-manes.versions", version = "0.45.0" }
62 changes: 60 additions & 2 deletions tbot-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ plugins {
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlinx.binaryCompatibilityValidator)
`maven-publish`
signing
alias(libs.plugins.dokka)
}

repositories {
mavenCentral()
}

val publishVersion = project.layout.projectDirectory.file("../version.txt").asFile.readText().trim()

group = "me.alllex.telegram.botkit"
version = "0.3.0-SNAPSHOT"
version = publishVersion

java.toolchain.languageVersion = libs.versions.jvmToolchain.map { JavaLanguageVersion.of(it) }

Expand Down Expand Up @@ -89,11 +93,65 @@ val sourcesJar by tasks.registering(Jar::class) {
from(sourceSets.main.map { it.allSource })
}

val javadocJar by tasks.registering(Jar::class) {
description = "Produce javadoc with Dokka HTML inside"
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml)
archiveClassifier = "javadoc"
}

publishing {
publications {
register("mavenJava", MavenPublication::class) {
artifactId = "tbot-api-jvm"
from(components["java"])
artifact(sourcesJar.get())
artifact(sourcesJar)
artifact(javadocJar)
}
}
}

// Gradle hasn't updated the signing plugin to be compatible with lazy-configuration, so it needs weird workarounds:
afterEvaluate {
// Register signatures in afterEvaluate, otherwise the signing plugin creates the signing tasks
// too early, before all the publications are added.
signing {
val signingKeyId: String? by project
val signingKey: String? by project
val signingPassword: String? by project

if (signingKeyId != null) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}
}
}

publishing {
publications.withType<MavenPublication>().configureEach {
pom {
name = "Telegram BotKit"
description = "Fluent Kotlin bindings for Telegram Bot API"
url = "https://github.com/alllex/telegram-bot-kit"
licenses {
license {
name = "MIT"
url = "https://opensource.org/licenses/MIT"
}
}
developers {
developer {
id = "alllex"
name = "Alex by Software"
email = "[email protected]"
url = "https://alllex.me"
}
}
scm {
connection = "scm:git:[email protected]:alllex/telegram-bot-kit.git"
developerConnection = "scm:git:[email protected]:alllex/telegram-bot-kit.git"
url = "https://github.com/alllex/telegram-bot-kit"
}
}
}
}
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.1-SNAPSHOT

0 comments on commit 5c7aa87

Please sign in to comment.