From 81f5b052911d0eb3992fcc615e111ee0e162e7b4 Mon Sep 17 00:00:00 2001 From: Megh Lath <98312779+cp-megh-l@users.noreply.github.com> Date: Mon, 1 Jan 2024 16:48:14 +0530 Subject: [PATCH] Add github workflows (#5) --- .github/workflows/build.yaml | 21 +++++++ .github/workflows/publish.yml | 29 +++++++++ build.gradle.kts | 5 ++ compose-recyclerview/build.gradle.kts | 28 +++++++-- .../adapter/ComposeRecyclerViewAdapter.kt | 17 +---- scripts/publish-module.gradle | 62 +++++++++++++++++++ scripts/publish-root.gradle | 42 +++++++++++++ 7 files changed, 184 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/publish.yml create mode 100644 scripts/publish-module.gradle create mode 100644 scripts/publish-root.gradle diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..edf1bfb --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +name: Android Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: 17 + cache: 'gradle' + distribution: adopt + + - name: Build with Gradle + run: ./gradlew build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ec6ab39 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,29 @@ +name: Publish +on: + push: + tags: + - '*' + +jobs: + publish: + name: Release build and publish + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: adopt + java-version: 17 + + - name: Publish to MavenCentral + run: ./gradlew compose_recyclerview:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} + PUBLISH_VERSION: ${{ secrets.PUBLISH_VERSION }} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 1d4323b..49aa71c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,4 +3,9 @@ plugins { id("com.android.application") version "8.1.2" apply false id("org.jetbrains.kotlin.android") version "1.9.10" apply false id("com.android.library") version "8.1.2" apply false + id ("io.github.gradle-nexus.publish-plugin") version "1.1.0" +} + +apply{ + from("${rootDir}/scripts/publish-root.gradle") } \ No newline at end of file diff --git a/compose-recyclerview/build.gradle.kts b/compose-recyclerview/build.gradle.kts index cb154b8..13f2360 100644 --- a/compose-recyclerview/build.gradle.kts +++ b/compose-recyclerview/build.gradle.kts @@ -3,6 +3,15 @@ plugins { id("org.jetbrains.kotlin.android") } +ext { + set("PUBLISH_GROUP_ID", "com.canopas") + set("PUBLISH_ARTIFACT_ID", "compose_recyclerview") +} + +apply{ + from("${rootDir}/scripts/publish-module.gradle") +} + android { namespace = "com.example.compose_recyclerview" compileSdk = 34 @@ -24,11 +33,11 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "11" } buildFeatures { compose = true @@ -36,6 +45,18 @@ android { composeOptions { kotlinCompilerExtensionVersion = "1.5.3" } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } + + publishing { + singleVariant("release") { + withJavadocJar() + withSourcesJar() + } + } } dependencies { @@ -44,7 +65,6 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") implementation("androidx.activity:activity-compose:1.8.2") implementation("com.google.android.material:material:1.11.0") - implementation("androidx.compose.foundation:foundation:1.5.4") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") diff --git a/compose-recyclerview/src/main/java/com/example/compose_recyclerview/adapter/ComposeRecyclerViewAdapter.kt b/compose-recyclerview/src/main/java/com/example/compose_recyclerview/adapter/ComposeRecyclerViewAdapter.kt index bf248f5..aa7f94c 100644 --- a/compose-recyclerview/src/main/java/com/example/compose_recyclerview/adapter/ComposeRecyclerViewAdapter.kt +++ b/compose-recyclerview/src/main/java/com/example/compose_recyclerview/adapter/ComposeRecyclerViewAdapter.kt @@ -1,8 +1,6 @@ package com.example.compose_recyclerview.adapter import android.view.ViewGroup -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row import androidx.compose.runtime.Composable import androidx.compose.ui.platform.ComposeView import androidx.recyclerview.widget.RecyclerView @@ -41,7 +39,6 @@ class ComposeRecyclerViewAdapter : notifyItemChanged(0) } - inner class ComposeRecyclerViewHolder(val composeView: ComposeView) : RecyclerView.ViewHolder(composeView) @@ -55,19 +52,7 @@ class ComposeRecyclerViewAdapter : holder.composeView.apply { tag = holder setContent { - when (layoutOrientation) { - LayoutOrientation.Horizontal -> { - Row { - itemBuilder?.invoke(position) - } - } - - LayoutOrientation.Vertical -> { - Column { - itemBuilder?.invoke(position) - } - } - } + itemBuilder?.invoke(position) } } } diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..e1b3ed3 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,62 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +group = PUBLISH_GROUP_ID +version = rootProject.ext["publish_version"] + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + // The coordinates of the library, being set from variables that + // we'll set up later + groupId PUBLISH_GROUP_ID + artifactId PUBLISH_ARTIFACT_ID + version rootProject.ext["publish_version"] + + /// Two artifacts, the `aar` (or `jar`) and the sources + if (project.plugins.findPlugin("com.android.library")) { + from components.release + } else { + artifact("$buildDir/libs/${project.getName()}-${version}.jar") + } + + // Mostly self-explanatory metadata + pom { + name = PUBLISH_ARTIFACT_ID + description = 'Integrating Jetpack Compose composables within traditional RecyclerView' + url = 'https://github.com/canopas/compose-recyclerview' + licenses { + license { + name = 'License' + url = 'https://github.com/canopas/compose-recyclerview/blob/master/LICENSE.txt' + } + } + developers { + developer { + id = 'cp-megh-l' + name = 'Megh Canopas' + email = 'megh.l@canopas.com' + } + // Add all other devs here... + } + + scm { + connection = 'scm:git:github.com/canopas/compose-recyclerview.git' + developerConnection = 'scm:git:ssh://github.com/canopas/compose-recyclerview.git' + url = 'https://github.com/canopas/ComposeRecyclerView' + } + } + } + } + } +} +signing { + useInMemoryPgpKeys( + rootProject.ext["signing.keyId"], + rootProject.ext["signing.key"], + rootProject.ext["signing.password"], + ) + + sign publishing.publications +} \ No newline at end of file diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle new file mode 100644 index 0000000..8b47822 --- /dev/null +++ b/scripts/publish-root.gradle @@ -0,0 +1,42 @@ +// Create variables with empty default values +ext["ossrhUsername"] = '' +ext["ossrhPassword"] = '' +ext["sonatypeStagingProfileId"] = '' +ext["signing.keyId"] = '' +ext["signing.password"] = '' +ext["signing.key"] = '' +ext["snapshot"] = '' +ext["publish_version"] = '' + +File secretPropsFile = project.rootProject.file('local.properties') + +if (secretPropsFile.exists()) { + + Properties p = new Properties() + + new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } + + p.each { name, value -> ext[name] = value } + +} else { + ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') + ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') + ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') + ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') + ext["signing.password"] = System.getenv('SIGNING_PASSWORD') + ext["signing.key"] = System.getenv('SIGNING_KEY') + ext["snapshot"] = System.getenv('SNAPSHOT') + ext["publish_version"] = System.getenv('PUBLISH_VERSION') +} + +nexusPublishing { + repositories { + sonatype { + stagingProfileId = sonatypeStagingProfileId + username = ossrhUsername + password = ossrhPassword + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + } + } +} \ No newline at end of file