Skip to content

Commit

Permalink
Maven central (#54)
Browse files Browse the repository at this point in the history
* Adjust POM file

* Use KMP-lokalise-api from maven central

* Adjust group and artifact id

* Sign artifacts

* Add sonatype repositories

* Add GH Actions for CD

* Update version to SNAPSHOT

* Adjust README

* Adjust tests

* Update README
  • Loading branch information
StefMa authored Dec 16, 2023
1 parent 58a72bd commit d3722c1
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 86 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Publish Snapshot'

on:
push:
branches:
- 'main'

env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}

jobs:
publish-snapshot:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Publish to Sonatype Snapshot
run: ./gradlew publishAllPublicationsToSonatypeSnapshotRepository
22 changes: 22 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Publish Maven Central Staging'

on:
push:
tags:
- '*'

env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Publish to Sonatype Staging
run: ./gradlew publishAllPublicationsToSonatypeStagingRepository
3 changes: 2 additions & 1 deletion .github/workflows/test-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
publishingConsumingPluginTest:
runs-on: ubuntu-latest
env:
IOKI_LOKALISE_PLUGIN_TEST_VERSION: ${{ github.head_ref || github.ref_name }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
52 changes: 23 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,6 @@ A Gradle plugin that can up- and downloads strings from [lokalise](https://lokal

### Apply the plugin

Add [JitPack](https://jitpack.io/) to the `settings.gradle[.kts]` file:

```groovy
pluginManagement {
repositories {
maven {
url("https://jitpack.io")
content {
includeGroupByRegex("com.github.ioki-mobility.*")
}
}
resolutionStrategy {
it.eachPlugin {
if (requested.id.id == "com.ioki.lokalise") {
useModule(
"com.github.ioki-mobility.LokaliseGradlePlugin:lokalise:${requested.version}"
)
}
}
}
}
}
```

> **Note**: If you use JitPack, the `[CURRENT_VERSION]` can either be a (git) tag (recommended), branch name, or hash.
Add the plugin to the `build.gradle[.kts]` file:

```kotlin
Expand Down Expand Up @@ -135,11 +109,31 @@ There is also an `downloadTranslationsForAll` task that aggregates all created t

# Release

## Snapshot release

By default, each merge to the `main` branch will create a new SNAPSHOT release.
If you want to use the latest and greatest use the SNAPSHOT version of the plugin.
But please be aware that they might contain bugs or behaviour changes.

To use the SNAPSHOT version you have to include the sonatype snapshot repository to your `settings.gradle[.kts]`
```kotlin
pluginManagement {
repositories {
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
```

## Proper release

* Checkout `main` branch
* Update the `version` in [`build.gradle.kts`](build.gradle.kts)
* Update the `version` in the instrumentation test `consuming of plugin marker publication works`
* Commit with message `Next release`
* Update the `version` in the instrumentation test `consuming of plugin publication via mavenLocal works`
* Commit with message `Prepare next relaese`
* Tag the version with the same version and push
* `git tag -a [VERSION] -m "Next release`
* `git tag [VERSION]`
* `git push origin [VERSION]`
* Update the `version` in [`build.gradle.kts`](build.gradle.kts) to the next **patch** version +`-SNAPSHOT`
* Update the `version` in the instrumentation test `consuming of plugin publication via mavenLocal works`
* Commit and push
* Create a new [release](https://github.com/ioki-mobility/LokaliseGradlePlugin/releases/new)
42 changes: 32 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ plugins {
alias(libs.plugins.kotlin)
`java-gradle-plugin`
`maven-publish`
signing
}

repositories {
mavenCentral()
maven(url = "https://jitpack.io") {
content {
includeGroup("com.github.ioki-mobility.kmp-lokalise-api")
}
}
}

dependencies {
Expand All @@ -34,13 +30,15 @@ java {
withJavadocJar()
}

version = "2.0.0"
group = "com.ioki"
version = "2.1.0-SNAPSHOT"
group = "com.ioki.lokalise"
publishing {
publications {
register("pluginMaven", MavenPublication::class.java) {
artifactId = "lokalise"
artifactId = "lokalise-gradle-plugin"
pom {
name.set("LokaliseGradlePlugin")
description.set("A Gradle plugin that can up- and download strings from lokalise")
url.set("https://github.com/ioki-mobility/LokaliseGradlePlugin")
licenses {
license {
Expand All @@ -58,20 +56,44 @@ publishing {
email.set("[email protected]")
url.set("https://StefMa.guru")
organization.set("ioki")
organizationUrl.set("https://ioki.com")
}
}
scm {
url.set("https://github.com/ioki-mobility/LokaliseGradlePlugin")
connection.set("https://github.com/ioki-mobility/LokaliseGradlePlugin.git")
developerConnection.set("[email protected]:ioki-mobility/LokaliseGradlePlugin.git")
connection.set("scm:git:git://github.com/ioki-mobility/LokaliseGradlePlugin.git")
developerConnection.set("scm:git:ssh://[email protected]:ioki-mobility/LokaliseGradlePlugin.git")
}
}
}
}
repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "SonatypeSnapshot"
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
maven("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
name = "SonatypeStaging"
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
}

tasks.test {
useJUnitPlatform()
}

kotlin.jvmToolchain(8)

signing {
val signingKey = System.getenv("GPG_SIGNING_KEY")
val signingPassword = System.getenv("GPG_SIGNING_PASSWORD")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kotlinVersion = "1.9.21"
[libraries]
test-kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlinVersion" }
test-strikt = "io.strikt:strikt-core:0.34.1"
lokaliseApi = "com.github.ioki-mobility.kmp-lokalise-api:lokalise-api:0.0.1"
lokaliseApi = "com.ioki:lokalise-api:0.0.2"
kotlinCoroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"

[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class LokaliseGradlePluginPublishingTest {
repositories {
gradlePluginPortal()
mavenCentral()
maven(url = "https://jitpack.io") // For transitive dependencies
mavenLocal()
}
}
Expand All @@ -55,7 +54,7 @@ class LokaliseGradlePluginPublishingTest {
fun `consuming of plugin publication via mavenLocal works`() {
val newBuildFile = buildGradle.readText().replace(
oldValue = """id("com.ioki.lokalise")""",
newValue = """id("com.ioki.lokalise") version "2.0.0""""
newValue = """id("com.ioki.lokalise") version "2.1.0-SNAPSHOT""""
)
buildGradle.writeText(newBuildFile)

Expand All @@ -66,47 +65,4 @@ class LokaliseGradlePluginPublishingTest {

expectThat(result.output).contains("BUILD SUCCESSFUL")
}

@Test
fun `consuming of plugin publication via jitpack works`() {
var testVersion = System.getenv("IOKI_LOKALISE_PLUGIN_TEST_VERSION")
?: fail(
"Please provide plugin version from jitpack" +
" via environment variable 'IOKI_LOKALISE_PLUGIN_TEST_VERSION'"
)
val isSemverVersion = Regex("[0-9]+\\.[0-9]+\\.[0-9]+").matches(testVersion)
if (!isSemverVersion) {
testVersion += "-SNAPSHOT"
}
val newBuildFile = buildGradle.readText().replace(
oldValue = """id("com.ioki.lokalise")""",
newValue = """id("com.ioki.lokalise") version "$testVersion""""
)
buildGradle.writeText(newBuildFile)
val newSettingsFile = settingsGradle.readText().replace(
oldValue = """gradlePluginPortal()""",
newValue =
"""
gradlePluginPortal()
maven(url = "https://jitpack.io")
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.ioki.lokalise") {
useModule(
"com.github.ioki-mobility.LokaliseGradlePlugin:lokalise:${'$'}{requested.version}"
)
}
}
}
"""
)
settingsGradle.writeText(newSettingsFile)

val result: BuildResult = GradleRunner.create()
.withProjectDir(testTmpPath.toFile())
.withArguments("tasks")
.build()

expectThat(result.output).contains("BUILD SUCCESSFUL")
}
}

0 comments on commit d3722c1

Please sign in to comment.