diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9f5052..4fa906c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,3 +94,71 @@ jobs: path: | **/build/outputs/aar/*.aar **/build/libs/*.jar + publish: + name: Publish Release + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Make gradlew executable + run: chmod +x ./gradlew + + - name: Extract version from Git tag + id: version + run: | + TAG=${GITHUB_REF#refs/tags/} + VERSION_NAME=${TAG#v} + echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV + + - name: Detect release type + id: release_type + run: | + if [[ "${GITHUB_REF}" == *alpha* ]]; then + echo "release_stage=alpha" >> $GITHUB_OUTPUT + elif [[ "${GITHUB_REF}" == *beta* ]]; then + echo "release_stage=beta" >> $GITHUB_OUTPUT + else + echo "release_stage=stable" >> $GITHUB_OUTPUT + fi + - name: Restore gradle.properties + env: + GRADLE_PROPERTIES: ${{ secrets.GRADLE_PROPERTIES }} + shell: bash + run: | + mkdir -p ~/.gradle/ + echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV + echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + + - name: Publish to Maven Central + run: ./gradlew formz:publishAllPublicationsToMavenCentral --no-configuration-cache -PVERSION_NAME=${{ env.VERSION_NAME }} + + - name: Upload GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ github.ref_name }} + name: Release ${{ github.ref_name }} + body: | + 🚀 **Release:** `${{ github.ref_name }}` + 🏷 **Type:** `${{ steps.release_type.outputs.release_stage }}` + + This release was automatically published from CI. + draft: false + prerelease: ${{ steps.release_type.outputs.release_stage != 'stable' }} + files: | + **/build/outputs/aar/*.aar + **/build/libs/*.jar \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index e7c69b4..a9ed3c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,6 +14,7 @@ plugins { alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.arturbosch.detekt) apply false alias(libs.plugins.spotless) apply false + alias(libs.plugins.maven.publish) apply false } val detektVersion = libs.versions.detekt.get() diff --git a/formz/build.gradle.kts b/formz/build.gradle.kts index ad77bfc..b27c2b5 100644 --- a/formz/build.gradle.kts +++ b/formz/build.gradle.kts @@ -3,9 +3,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { alias(libs.plugins.android.library) alias(libs.plugins.jetbrains.kotlin.android) - id("maven-publish") + alias(libs.plugins.maven.publish) + alias(libs.plugins.signing) } - +val versionName = project.findProperty("VERSION_NAME") as String? ?: "0.0.6-alpha" android { namespace = "com.nareshchocha.formz" compileSdk = @@ -39,12 +40,6 @@ android { jvmTarget.set(JvmTarget.JVM_21) } } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } } dependencies { @@ -52,19 +47,37 @@ dependencies { testImplementation(libs.junit) } -publishing { - publications { - create("release") { - groupId = "com.github.ChochaNaresh" - artifactId = "formz" - version = "0.0.5" +val automaticRelease: Boolean = true +mavenPublishing { + publishToMavenCentral(automaticRelease) + signAllPublications() + coordinates("io.github.chochanaresh", "formz", versionName) - afterEvaluate { - from(components["release"]) - /* from { - components.release - }*/ + pom { + name.set("formz") + description.set( + "Formz is a lightweight validation framework for Android forms written in Kotlin. It provides a simple, yet powerful way to define, validate, and manage form inputs in your Android applications. The library is designed with immutability and performance in mind, ensuring that expensive validation logic is computed only once per input." + ) + inceptionYear.set("2025") + url.set("https://github.com/ChochaNaresh/Formz") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt") } } + developers { + developer { + id.set("ChochaNaresh") + name.set("Naresh Chocha") + url.set("https://github.com/ChochaNaresh") + } + } + scm { + url.set("https://github.com/ChochaNaresh/Formz") + connection.set("scm:git:git://github.com/ChochaNaresh/Formz.git") + developerConnection.set("scm:git:ssh://git@github.com/ChochaNaresh/Formz.git") + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0ce522e..a20fdd5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ agp = "8.11.0" kotlin = "2.2.0" detekt = "1.23.8" +mavenPublish = "0.33.0" compileSdk = "36" targetSdk = "36" minSdk = "21" @@ -55,4 +56,8 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = " # code style review arturbosch-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } spotless = { id = "com.diffplug.spotless", version = "7.0.4" } +# maven publish +maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } +# signing +signing = { id = "signing" } diff --git a/secring.gpg b/secring.gpg new file mode 100644 index 0000000..5c7edf1 Binary files /dev/null and b/secring.gpg differ