diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..72f2600 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Publish to Maven Central + +on: + workflow_dispatch: + push: + tags: + - '*' + +jobs: + deploy: + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + GPG_KEY: ${{ secrets.GPG_KEY }} + + steps: + - uses: actions/checkout@v4 + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: Configure GPG Key + run: | + mkdir ~/.gpgkey + echo $GPG_KEY > ~/.gpgkey/secring.gpg.b64 + base64 -d ~/.gpgkey/secring.gpg.b64 > ~/.gpgkey/secring.gpg + + - name: Deploy to Sonatype + env: + MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + + run: | + ./gradlew publishToSonatype closeAndReleaseStagingRepository --no-parallel --no-daemon -Psigning.keyId=${{secrets.GPG_KEY_ID}} -Psigning.password=${{secrets.GPG_KEY_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gpgkey/secring.gpg) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d7493c8..0000000 --- a/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -buildscript { - dependencies { - classpath "org.jlleitschuh.gradle:ktlint-gradle:12.1.1" - } -} - -plugins { - alias(libs.plugins.android.library) apply false - alias(libs.plugins.android.application) apply false - alias(libs.plugins.kotlin.android) apply false - alias(libs.plugins.detekt) apply false - alias(libs.plugins.kotlin.multiplatform) apply false - alias(libs.plugins.compose.compiler) apply false -} - -//apply git hooks -apply from: "scripts/git-hooks.gradle.kts" - -subprojects { - apply from: "../scripts/ktlint.gradle" -} - - -afterEvaluate { - tasks.named("clean") { - dependsOn(installGitHooks) - } -} - -tasks.register('clean', Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..32ad7a0 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("root.publication") + alias(libs.plugins.android.library) apply false + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.detekt) apply false + alias(libs.plugins.kotlin.multiplatform) apply false + alias(libs.plugins.compose.compiler) apply false + alias(libs.plugins.ktlint) + signing +} + +apply { + from("scripts/git-hooks.gradle.kts") +} + +subprojects { + pluginManager.apply("org.jlleitschuh.gradle.ktlint") +} + +ktlint { + version = "1.4.0" +} + +group = "io.github.rafsanjani" diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts new file mode 100644 index 0000000..c989dbd --- /dev/null +++ b/convention-plugins/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation("io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin:2.0.0") +} + +gradlePlugin { + val rootPackageName = "com.foreverrafs.datepickertimeline" + + plugins { + register("ModulePublicationConventionPlugin") { + id = "module.publication" + implementationClass = "$rootPackageName.ModulePublication" + } + register("RootPublicationConventionPlugin") { + id = "root.publication" + implementationClass = "$rootPackageName.RootPublication" + } + } +} diff --git a/convention-plugins/settings.gradle.kts b/convention-plugins/settings.gradle.kts new file mode 100644 index 0000000..909d511 --- /dev/null +++ b/convention-plugins/settings.gradle.kts @@ -0,0 +1,21 @@ +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + + versionCatalogs { + create("libs") { + from("io.github.rafsanjani:versions:2024.10.27") + } + } +} diff --git a/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/ModulePublication.kt b/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/ModulePublication.kt new file mode 100644 index 0000000..570311c --- /dev/null +++ b/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/ModulePublication.kt @@ -0,0 +1,74 @@ +package com.foreverrafs.datepickertimeline + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.publish.PublicationContainer +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType +import org.gradle.plugins.signing.SigningExtension + +class ModulePublication : Plugin { + override fun apply(target: Project) { + with(target) { + applyPlugins() + + publishing { + // Configure all publications + publications.withType { + val mavenPublication = this as? MavenPublication + + mavenPublication?.artifactId = + "datepickertimeline${ + "-$name".takeUnless { "kotlinMultiplatform" in name }.orEmpty() + }".removeSuffix("Release") + + pom { + name.set("Date Picker Timeline") + description.set("A linear date picker for jetpack compose multiplatform") + url.set("https://github.com/rafsanjani/datepickertimeline") + + licenses { + license { + name.set("MIT") + url.set("https://opensource.org/licenses/mit") + } + } + issueManagement { + system.set("Github") + url.set("https://github.com/rafsanjani/datepickertimeline/issues") + } + scm { + connection.set("https://github.com/rafsanjani/datepickertimeline.git") + url.set("https://github.com/rafsanjani/datepickertimeline.git") + } + developers { + developer { + id.set("RafsanjaniAziz") + name.set("Rafsanjani Abdul-Aziz") + email.set("foreverrafs@gmail.com") + } + } + } + } + } + + signing { + sign(publications) + } + } + } +} + +private fun Project.applyPlugins() { + pluginManager.apply("signing") + pluginManager.apply("maven-publish") +} + +private fun Project.signing(action: SigningExtension.() -> Unit) = extensions.configure(action) +private fun Project.publishing(action: PublishingExtension.() -> Unit) = extensions.configure(action) + +private val SigningExtension.publications: PublicationContainer + get() = project.extensions.getByType().publications diff --git a/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/RootPublication.kt b/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/RootPublication.kt new file mode 100644 index 0000000..48976f8 --- /dev/null +++ b/convention-plugins/src/main/kotlin/com/foreverrafs/datepickertimeline/RootPublication.kt @@ -0,0 +1,33 @@ +package com.foreverrafs.datepickertimeline + +import io.github.gradlenexus.publishplugin.NexusPublishExtension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure + +class RootPublication : Plugin { + override fun apply(target: Project) { + with(target) { + pluginManager.apply("io.github.gradle-nexus.publish-plugin") + + nexusPublishing { + repositories { + sonatype { + val stagingProfileID = System.getenv("OSSRH_STAGING_PROFILE_ID") + val mavenCentralUsername = System.getenv("MAVEN_CENTRAL_USERNAME") + val mavenCentralPassword = System.getenv("MAVEN_CENTRAL_PASSWORD") + + useStaging.set(true) + + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + username.set(mavenCentralUsername) + password.set(mavenCentralPassword) + } + } + } + } + } +} + +private fun Project.nexusPublishing(action: NexusPublishExtension.() -> Unit) = extensions.configure(action) diff --git a/datepickertimeline/build.gradle.kts b/datepickertimeline/build.gradle.kts index 425ecb0..bdd2224 100644 --- a/datepickertimeline/build.gradle.kts +++ b/datepickertimeline/build.gradle.kts @@ -1,12 +1,18 @@ @file:Suppress("UnusedPrivateProperty") plugins { + id("module.publication") alias(libs.plugins.android.library) alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.compose.multiplatform) alias(libs.plugins.compose.compiler) + id("org.jetbrains.dokka") version "1.9.20" + `maven-publish` + signing } +version = "1.0.0" + @OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class) kotlin { androidTarget() @@ -56,8 +62,27 @@ android { minSdk = libs.versions.minimumSdk.get().toInt() } + publishing { + singleVariant("release") { + withSourcesJar() + } + } + compileOptions { targetCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17 } + + afterEvaluate { + configure { + publications.all { + val mavenPublication = this as? MavenPublication + + mavenPublication?.artifactId = + "datepickertimeline${ + "-$name".takeUnless { "kotlinMultiplatform" in name }.orEmpty() + }".removeSuffix("Release") + } + } + } } diff --git a/datepickertimeline/src/commonMain/kotlin/com/foreverrafs/datepicker/state/DatePickerState.kt b/datepickertimeline/src/commonMain/kotlin/com/foreverrafs/datepicker/state/DatePickerState.kt index 035b7b3..a20a780 100644 --- a/datepickertimeline/src/commonMain/kotlin/com/foreverrafs/datepicker/state/DatePickerState.kt +++ b/datepickertimeline/src/commonMain/kotlin/com/foreverrafs/datepicker/state/DatePickerState.kt @@ -66,14 +66,16 @@ class DatePickerState( restore = { DatePickerState( selectedDate = LocalDate( - it[0].toString().toInt(), // year - it[1].toString().toInt(), // month - it[2].toString().toInt(), // day + // year + it[0].toString().toInt(), + // month + it[1].toString().toInt(), + // day + it[2].toString().toInt(), ), shouldScrollToSelectedDate = it[3] .toString() .toBoolean(), - // shouldScrollToSelectedDate ) }, ) diff --git a/scripts/ktlint.gradle b/scripts/ktlint.gradle deleted file mode 100644 index ab1e6f7..0000000 --- a/scripts/ktlint.gradle +++ /dev/null @@ -1,13 +0,0 @@ -apply plugin: "org.jlleitschuh.gradle.ktlint" - -ktlint { - version = "1.4.0" - - reporters { - reporter "plain" - reporter "checkstyle" - reporter "html" - } - - outputColorName = "RED" -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 96a3493..38bee06 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,10 @@ pluginManagement { + includeBuild("convention-plugins") repositories { gradlePluginPortal() google() mavenCentral() + mavenLocal() } } @@ -10,7 +12,9 @@ dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() + gradlePluginPortal() mavenCentral() + mavenLocal() } versionCatalogs {