Skip to content

Commit

Permalink
Add github workflows (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-megh-l authored Jan 1, 2024
1 parent 9839dce commit 81f5b05
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 20 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
28 changes: 24 additions & 4 deletions compose-recyclerview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,18 +33,30 @@ 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
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.3"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}

publishing {
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}

dependencies {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,7 +39,6 @@ class ComposeRecyclerViewAdapter :
notifyItemChanged(0)
}


inner class ComposeRecyclerViewHolder(val composeView: ComposeView) :
RecyclerView.ViewHolder(composeView)

Expand All @@ -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)
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
}
// 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
}
42 changes: 42 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -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/"))
}
}
}

0 comments on commit 81f5b05

Please sign in to comment.