diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index c7389ab..7195299 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -37,21 +37,33 @@ jobs: ORG_GRADLE_PROJECT_githubToken: ${{ secrets.GITHUBTOKEN }} ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} - ORG_GRADLE_PROJECT_sonatypeUser: ${{ secrets.SONATYPE_USER }} - ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - run: ./gradlew -Pversion=$VERSION build sourcesJar dokkaGeneratePublicationHtml publishToSonatype closeAndReleaseSonatypeStagingRepository + JRELEASER_DEPLOY_MAVEN_MAVENCENTRAL_MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + JRELEASER_DEPLOY_MAVEN_MAVENCENTRAL_MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + run: ./gradlew -Pversion=$VERSION build sourcesJar dokkaGeneratePublicationHtml publish jreleaserDeploy - - name: Checkout main branch + - name: Display JReleaser trace.log (only on failure) + if: failure() + run: | + if [ -f build/jreleaser/trace.log ]; then + echo "trace.log Content:" + tail -1000 build/jreleaser/trace.log + else + echo "trace.log file not found" + fi + + - name: Checkout main branch (only if releasing from main) + if: github.ref == 'refs/heads/main' uses: actions/checkout@v4.2.2 with: ref: main fetch-depth: 0 - - name: Update README + - name: Update README (only if releasing from main) + if: github.ref == 'refs/heads/main' run: sh .github/scripts/update-readme-version.sh - - name: Create Pull Request + - name: Create Pull Request (only if releasing from main) + if: github.ref == 'refs/heads/main' uses: stefanzweifel/git-auto-commit-action@v5.0.1 with: commit_message: Dependency version in README.md updated to ${{ env.VERSION }} diff --git a/build.gradle.kts b/build.gradle.kts index 384c36b..1f0a51a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,8 @@ import org.jetbrains.kotlin.gradle.swiftexport.ExperimentalSwiftExportDsl import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.jreleaser.model.Active +import java.time.LocalDate plugins { alias(libs.plugins.kotlin.multiplatform) @@ -19,10 +21,20 @@ plugins { alias(libs.plugins.versions) `maven-publish` signing - alias(libs.plugins.publish) + alias(libs.plugins.jreleaser) } -val githubAccount = "xemantic" +data class Settings( + val description: String, + val gitHubAccount: String, + val copyright: String +) + +val settings = Settings( + description = "The power-assert compatible assertions DSL and some other testing goodies - a Kotlin multiplatform testing library", + gitHubAccount = "xemantic", + copyright = "(c) ${LocalDate.now().year} Xemantic" +) val javaTarget = libs.versions.javaTarget.get() val kotlinTarget = KotlinVersion.fromVersion(libs.versions.kotlinTarget.get()) @@ -32,8 +44,6 @@ val githubActor: String? by project val githubToken: String? by project val signingKey: String? by project val signingPassword: String? by project -val sonatypeUser: String? by project -val sonatypePassword: String? by project println( """ @@ -181,7 +191,7 @@ powerAssert { // https://kotlinlang.org/docs/dokka-migration.html#adjust-configuration-options dokka { pluginsConfiguration.html { - footerMessage.set("(c) 2024 Xemantic") + footerMessage.set(settings.copyright) } } @@ -190,12 +200,18 @@ val javadocJar by tasks.registering(Jar::class) { from(tasks.dokkaGeneratePublicationHtml) } +val stagingDeployDir = layout.buildDirectory.dir("staging-deploy").get().asFile + publishing { repositories { - if (!isReleaseBuild) { + if (isReleaseBuild) { + maven { + url = stagingDeployDir.toURI() + } + } else { maven { name = "GitHubPackages" - setUrl("https://maven.pkg.github.com/$githubAccount/${rootProject.name}") + setUrl("https://maven.pkg.github.com/${settings.gitHubAccount}/${rootProject.name}") credentials { username = githubActor password = githubToken @@ -206,50 +222,22 @@ publishing { publications { withType { artifact(javadocJar) - pom { - name = "xemantic-kotlin-test" - description = "The power-assert compatible assertions DSL and some other testing goodies - " + - "a Kotlin multiplatform testing library." - url = "https://github.com/$githubAccount/${rootProject.name}" - inceptionYear = "2024" - organization { - name = "Xemantic" - url = "https://xemantic.com" - } - licenses { - license { - name = "The Apache Software License, Version 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" - distribution = "repo" - } - } - scm { - url = "https://github.com/$githubAccount/${rootProject.name}" - connection = "scm:git:git:github.com/$githubAccount/${rootProject.name}.git" - developerConnection = "scm:git:https://github.com/$githubAccount/${rootProject.name}.git" - } - ciManagement { - system = "GitHub" - url = "https://github.com/$githubAccount/${rootProject.name}/actions" - } - issueManagement { - system = "GitHub" - url = "https://github.com/$githubAccount/${rootProject.name}/issues" - } - developers { - developer { - id = "morisil" - name = "Kazik Pogoda" - email = "morisil@xemantic.com" - } - } - } + pom { setUpPomDetails() } } } } if (isReleaseBuild) { + tasks.named("jreleaserDeploy").configure { + mustRunAfter("publish") + } + + stagingDeployDir.mkdirs() + + // fixes https://github.com/jreleaser/jreleaser/issues/1292 + layout.buildDirectory.dir("jreleaser").get().asFile.mkdir() + // workaround for KMP/gradle signing issue // https://github.com/gradle/gradle/issues/26091 tasks { @@ -284,15 +272,69 @@ if (isReleaseBuild) { sign(publishing.publications) } - nexusPublishing { - repositories { - sonatype { //only for users registered in Sonatype after 24 Feb 2021 - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - username.set(sonatypeUser) - password.set(sonatypePassword) + jreleaser { + project { + description = settings.description + copyright = settings.copyright + } + deploy { + maven { + mavenCentral { + create("maven-central") { + applyMavenCentralRules = false // Already checked + active = Active.ALWAYS + url = "https://central.sonatype.com/api/v1/publisher" + maxRetries = 240 + stagingRepository(stagingDeployDir.path) + } + } + } + } + release { + github { + // we are releasing through GitHub UI + skipRelease = true + skipTag = true } } } } + +fun MavenPom.setUpPomDetails() { + name = rootProject.name + description = settings.description + url = "https://github.com/${settings.gitHubAccount}/${rootProject.name}" + inceptionYear = "2024" + organization { + name = "Xemantic" + url = "https://xemantic.com" + } + licenses { + license { + name = "The Apache Software License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + distribution = "repo" + } + } + scm { + url = "https://github.com/${settings.gitHubAccount}/${rootProject.name}" + connection = "scm:git:git:github.com/${settings.gitHubAccount}/${rootProject.name}.git" + developerConnection = "scm:git:https://github.com/${settings.gitHubAccount}/${rootProject.name}.git" + } + ciManagement { + system = "GitHub" + url = "https://github.com/${settings.gitHubAccount}/${rootProject.name}/actions" + } + issueManagement { + system = "GitHub" + url = "https://github.com/${settings.gitHubAccount}/${rootProject.name}/issues" + } + developers { + developer { + id = "morisil" + name = "Kazik Pogoda" + email = "morisil@xemantic.com" + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 100f73b..61f02a9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ kotlin = "2.1.0" versionsPlugin = "0.51.0" dokkaPlugin = "2.0.0" -publishPlugin = "2.0.0" +jreleaserPlugin = "1.16.0" binaryCompatibilityValidatorPlugin = "0.17.0" @@ -18,5 +18,5 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref kotlin-plugin-power-assert = { id = "org.jetbrains.kotlin.plugin.power-assert", version.ref = "kotlin" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaPlugin" } versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" } -publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "publishPlugin" } kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompatibilityValidatorPlugin" } +jreleaser = { id = "org.jreleaser", version.ref = "jreleaserPlugin" }