Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND-136: add :gears:kotlin :gears:compose, update ci #52

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ name: CI
on:
push:
branches: [main]
# Release tag format is [module-name]-v[androidx-version]-[ktx-version]
# For example: fragment-ktx-v1.3.5-0
tags: ['*-ktx-v*-[0-9]+']
# Release tag format is [module-name]-[namespace-name]-v[version]-[sub-version]
# For example: fragment-ktx-v1.3.5-0, compose-gears-v.1.1.1-1
tags:
- '*-ktx-v*-[0-9]+'
- '*-gears-v*-[0-9]+'
pull_request:
branches: [main]

Expand Down Expand Up @@ -34,7 +36,7 @@ jobs:
run: ./gradlew detektAll detektReleaseAll

publish:
name: Publish KTX
name: Publish gears
needs: check
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
Expand All @@ -49,17 +51,24 @@ jobs:
distribution: 'temurin'
java-version: 17

- name: Get module name from tag
id: get-module-name
- name: Get namespace and module name from tag
id: parse-tag
run: |
tag=${GITHUB_REF#refs/tags/}
echo "result=${tag/-v*}" >> "$GITHUB_OUTPUT"
module=$(echo "${tag%-*-v*}")
namespace=$(echo "${tag/-v*}" | rev | cut -d '-' -f 1 | rev)
sonulen marked this conversation as resolved.
Show resolved Hide resolved
echo "module=$module" >> "$GITHUB_OUTPUT"
echo "namespace=$namespace" >> "$GITHUB_OUTPUT"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Run Publish
run: ./gradlew :ktx:${{ steps.get-module-name.outputs.result }}:publish
run: ./gradlew :${{ steps.parse-tag.outputs.namespace }}:${{ steps.parse-tag.outputs.module }}:publish
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_githubPackagesUsername: ${{ github.actor }}
ORG_GRADLE_PROJECT_githubPackagesPassword: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ java {
dependencies {
implementation(rmr.infrastructure.publish)
implementation(rmr.infrastructure.android)
implementation(libs.publish.gradlePlugin)
implementation(stack.gradle.android.cacheFixGradlePlugin)
implementation(stack.kotlin.gradlePlugin)
implementation(stack.detekt.gradlePlugin)
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/convention.library.kotlin.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins {
id("com.redmadrobot.kotlin-library")
id("convention.publishing")
id("convention.detekt")
}
32 changes: 17 additions & 15 deletions buildSrc/src/main/kotlin/convention.publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import com.redmadrobot.build.dsl.*
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id("com.redmadrobot.publish-config")
id("com.redmadrobot.publish")
id("com.vanniktech.maven.publish")
}

redmadrobot {
publishing {
signArtifacts = !isRunningOnCi
pom {
setGitHubProject("RedMadRobot/gears-android")
mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
signAllPublications()

licenses {
mit()
}
pom {
name.convention(project.name)
description.convention(project.description)

developers {
developer(id = "osipxd", name = "Osip Fatkullin", email = "[email protected]")
developer(id = "sonulen", name = "Andrey Tolmachev", email = "[email protected]")
}
licenses {
mit()
}

developers {
developer(id = "osipxd", name = "Osip Fatkullin", email = "[email protected]")
developer(id = "sonulen", name = "Andrey Tolmachev", email = "[email protected]")
}

setGitHubProject("RedMadRobot/gears-android")
}
}

publishing {
repositories {
if (isRunningOnCi) githubPackages("RedMadRobot/gears-android")
if (isReleaseVersion && credentialsExist("ossrh")) ossrh()
}
}
1 change: 1 addition & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ naming:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)'
ignoreAnnotated: ['Composable']
excludeClassPattern: '$^'
FunctionParameterNaming:
active: true
Expand Down
3 changes: 3 additions & 0 deletions gears/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// For some reason gradle.properties in this project doesn't affect its subprojects
val gearsGroup = group
subprojects { group = gearsGroup }
5 changes: 5 additions & 0 deletions gears/gears-compose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Unreleased

### Added

- `FixedFontScaleContainer` - A container that fixes the font scale, ignoring values that are set in the phone's system settings
53 changes: 53 additions & 0 deletions gears/gears-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# compose <GitHub path="RedMadRobot/gears-android/tree/main/gears/compose"/>
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.gears/gears-compose?style=flat-square)][mavenCentral]
[![License](https://img.shields.io/github/license/RedMadRobot/gears-android?style=flat-square)][license]

---
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

A set of gears for compose.

## Installation

Add the dependency:
```groovy
repositories {
mavenCentral()
google()
}

dependencies {
implementation("com.redmadrobot.gears:gears-compose:<version>")
}
```


The library was developed and tested using:

> - `compose-runtime` [1.6.5](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.6.5)
> - `compose-ui` [1.6.5](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.6.5)

> [!NOTE]
> These dependencies will be transiently included in your project.

## Usage

| Gear | Description |
|:--------------------|:-----------|
| `FixedFontScaleContainer` | A container that fixes the font scale, ignoring values, that are set in the phone's system settings |

## Contributing

Merge requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.


[mavenCentral]: https://search.maven.org/artifact/com.redmadrobot.gears/compose
[license]: ../LICENSE
27 changes: 27 additions & 0 deletions gears/gears-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
convention.library.android
}

version = "0.1.0"
description = "A set of gears for compose"

redmadrobot {
android.minSdk = 21
}

android {
namespace = "$group.compose"

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = androidx.versions.compose.compiler.get()
}
}

dependencies {
api(androidx.compose.ui)
api(androidx.compose.runtime)
}
43 changes: 43 additions & 0 deletions gears/gears-compose/src/main/kotlin/FixedFontScaleContainer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.redmadrobot.extensions.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density

/**
* A container that fixes the font scale, ignoring values,
* that are set in the phone's system settings
*/
@Composable
public fun FixedFontScaleContainer(
content: @Composable () -> Unit,
) {
val fixedFontScaleDensity = Density(LocalDensity.current.density)
CompositionLocalProvider(
LocalDensity provides fixedFontScaleDensity,
content = content,
)
}

/**
* A container that restricts the font scale, ignoring values,
* that are set in the phone's system settings
*
* @param limit - the upper limit of font enlargement
*/
@Composable
public fun LimitedFontScaleContainer(
limit: Float,
content: @Composable () -> Unit,
) {
val fontScale = LocalDensity.current.fontScale.coerceAtMost(limit)
val fixedFontScaleDensity = Density(
density = LocalDensity.current.density,
fontScale = fontScale,
)
CompositionLocalProvider(
LocalDensity provides fixedFontScaleDensity,
content = content,
)
}
6 changes: 6 additions & 0 deletions gears/gears-kotlin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Unreleased

### Added

- `T.applyIf` - Applies the given block of modifications to the T if the condition is true
- `T.applyIfNotNull` - Applies the given block of modifications to the T if the value is not null
52 changes: 52 additions & 0 deletions gears/gears-kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# kotlin <GitHub path="RedMadRobot/gears-android/tree/main/gears/kotlin"/>
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.gears/kotlin?style=flat-square)][mavenCentral]
[![License](https://img.shields.io/github/license/RedMadRobot/gears-android?style=flat-square)][license]

---
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

A set of gears for kotlin.

## Installation

Add the dependency:
```groovy
repositories {
mavenCentral()
google()
}

dependencies {
implementation("com.redmadrobot.gears:gears-kotlin:<version>")
}
```

The library was developed and tested using:

> - `kotlin` [1.9.23](https://github.com/JetBrains/kotlin/releases/tag/v1.9.23)

> [!NOTE]
> These dependencies will be transiently included in your project.

## Usage

| Gear | Description |
|:-----------------------|:---------------------------------------------------------------------------------------------|
| `T.applyIf` | Applies the given block of modifications to the T if the condition is true |
| `T.applyIfNotNull` | Applies the given block of modifications to the T if the value is not null |

## Contributing

Merge requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.


[mavenCentral]: https://search.maven.org/artifact/com.redmadrobot.gears/gears-kotlin
[license]: ../LICENSE
10 changes: 10 additions & 0 deletions gears/gears-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
convention.library.kotlin
}

version = "0.1.0"
description = "A set of gears for kotlin"

dependencies {
api(kotlin("stdlib"))
}
19 changes: 19 additions & 0 deletions gears/gears-kotlin/src/main/kotlin/ApplyIf.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.redmadrobot.gears.kotlin

/**
* Calls the specified function [block] with [this] value as its receiver if the [condition] is `true`
* and returns its result.
*/
public inline fun <T> T.applyIf(
condition: Boolean,
block: T.() -> T,
): T = if (condition) block() else this

/**
* Calls the specified function [block] with [this] value as its receiver if the [value] is not null
* and returns its result.
*/
public inline fun <T, P : Any> T.applyIfNotNull(
value: P?,
block: T.(P) -> T
): T = if (value != null) block(value) else this
1 change: 1 addition & 0 deletions gears/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group=com.redmadrobot.gears
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[versions]
androidGradlePlugin = "8.4.0"
androidGradlePlugin = "8.4.1"
assertj-core = "3.25.1"
androidx-arch-core = "2.2.0"
viewbinding = "8.4.0"
viewbinding = "8.4.1"
publish-plugin = "0.28.0"

[libraries]
androidx-viewbinding = { module = "androidx.databinding:viewbinding", version.ref = "viewbinding" }
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj-core" }
androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "androidx-arch-core"}
android-gradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
publish-gradlePlugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "publish-plugin" }
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ include(
":ktx:lifecycle-livedata-ktx",
":ktx:resources-ktx",
":ktx:viewbinding-ktx",
":gears:gears-compose",
":gears:gears-kotlin",
)