Skip to content
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
7 changes: 5 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
root = true

[*.{kt,kts}]
disabled_rules = filename
max_line_length = off
insert_final_newline = true
ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_name_count_to_use_star_import_for_members = 999
ij_java_class_count_to_use_import_on_demand = 999
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

ktlint_ignore_back_ticked_identifier = true

# Disabled annotation formatting so @Inject constructor() doesn't go to new line
ktlint_standard_annotation = disabled
156 changes: 10 additions & 146 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
@@ -1,155 +1,19 @@
name: Commit

on: push

env:
api_level: 29
commitlint_version: '17'
conventional_changelog_version: '5'
java_version: 11
ktlint_version: '0.46.1'
node_version: 18
semantic_release_version: '20'
on: [ push, workflow_dispatch ]

jobs:
commit_lint:
name: Commit Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
with:
fetch-depth: 0
- name: Run Commit Lint
id: commitlint
uses: ./.github/actions/commit-lint
with:
node_version: ${{ env.node_version }}
commitlint_version: ${{ env.commitlint_version }}

code_lint:
name: Code Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Run ktlint
id: ktlint
uses: ./.github/actions/code-lint
with:
ktlint_version: ${{ env.ktlint_version }}

validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3

determine_version:
name: Version Determination
runs-on: ubuntu-latest
outputs:
releaseType: ${{ steps.determine_version.outputs.releaseType }}
releaseChannel: ${{ steps.determine_version.outputs.releaseChannel }}
buildVersion: ${{ steps.determine_version.outputs.buildVersion }}
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Determine Version
id: determine_version
uses: ./.github/actions/determine-version
with:
node_version: ${{ env.node_version }}
semantic_release_version: ${{ env.semantic_release_version }}
conventional_changelog_version: ${{ env.conventional_changelog_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build
needs: [ commit_lint, code_lint, validation ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Build
id: build
uses: ./.github/actions/build
with:
java_version: ${{ env.java_version }}
env:
BUILD_VERSION: "${{ needs.determine_version.outputs.buildVersion }}"

unit_tests:
name: Unit Tests
needs: [ commit_lint, code_lint, validation ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Unit Tests
id: unit_tests
uses: ./.github/actions/unit-tests
with:
java_version: ${{ env.java_version }}

instrumentation_tests:
name: Instrumentation Tests
needs: [ commit_lint, code_lint ]
runs-on: macos-11
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Run Tests
id: instrumentation_tests
uses: ./.github/actions/instrumentation-test
with:
java_version: ${{ env.java_version }}
api_level: ${{ env.api_level }}

release:
name: Release
runs-on: ubuntu-latest
needs: [ determine_version, build, unit_tests, instrumentation_tests ]
if: needs.determine_version.outputs.releaseType != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
releaseType: ${{ steps.release.outputs.releaseType }}
releaseChannel: ${{ steps.release.outputs.releaseChannel }}
buildVersion: ${{ steps.release.outputs.buildVersion }}
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Release
id: release
uses: ./.github/actions/release
with:
node_version: ${{ env.node_version }}
semantic_release_version: ${{ env.semantic_release_version }}
conventional_changelog_version: ${{ env.conventional_changelog_version }}

publish:
name: Publication
runs-on: ubuntu-latest
needs: release
if: needs.release.outputs.releaseType != ''
env:
RELEASE_TYPE: ${{ needs.release.outputs.releaseType }}
RELEASE_CHANNEL: ${{ needs.release.outputs.releaseChannel }}
BUILD_VERSION: ${{ needs.release.outputs.buildVersion }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
semantic_library_workflow:
name: push
uses: krogerco/Shared-CI-Workflow-Android/.github/workflows/semantic_library_workflow.yml@v1.5.0
with:
java_version: '24'
ktlint_version: '-1'
test_command: 'test'
secrets:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyId }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyPassword }}
steps:
- name: Checkout
uses: actions/checkout@v3.3.0
- name: Publish
id: publish
uses: ./.github/actions/publish
with:
java_version: ${{ env.java_version }}
REPO_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
name: Check PR Title
runs-on: ubuntu-latest
steps:
- uses: thehanimo/pr-title-checker@v1.3.4
- uses: thehanimo/pr-title-checker@v1.4.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_configuration_owner: 'krogerco'
github_configuration_repo: 'Shared-CI-Workflow-Android'
github_configuration_path: '.github/config/pr-title-checker-config.json'
github_configuration_ref: 'v1.0.0'
25 changes: 18 additions & 7 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import com.kroger.gradle.config.junit5

plugins {
id(Plugins.androidLibrary.id)
id(Plugins.release.id)
alias(libs.plugins.conventions.publishedAndroidLibrary)
}

android {
namespace = "com.kroger.telemetry.android"
}

kover {
currentProject {
createVariant("default") {
add("debug")
}
}
}

dependencies {
api(project(":telemetry"))

implementation(libs.coroutinesAndroid)
implementation(libs.stdLib)
implementation(libs.kotlinx.coroutinesAndroid)

testImplementation(libs.coroutinesTest)
testImplementation(libs.jupiterApi)
testRuntimeOnly(libs.jupiterEngine)
junit5()
testImplementation(libs.kotlinx.coroutinesTest)
}
2 changes: 0 additions & 2 deletions android/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ package com.kroger.telemetry.android.facet

import com.kroger.telemetry.facet.Facet

public data class ToastFacet(val message: String) : Facet
public data class ToastFacet(
val message: String,
) : Facet
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ private val logPrinter: (PrintRelay.Message) -> Unit = { message ->
Log.println(message.significance.toLogPriority(), message.tag, message.value)
}

private fun Significance.toLogPriority(): Int = when (this) {
Significance.VERBOSE -> Log.VERBOSE
Significance.DEBUG -> Log.DEBUG
Significance.INFORMATIONAL -> Log.INFO
Significance.WARNING -> Log.WARN
Significance.ERROR -> Log.ERROR
Significance.INTERNAL_ERROR -> Log.ERROR
}
private fun Significance.toLogPriority(): Int =
when (this) {
Significance.VERBOSE -> Log.VERBOSE
Significance.DEBUG -> Log.DEBUG
Significance.INFORMATIONAL -> Log.INFO
Significance.WARNING -> Log.WARN
Significance.ERROR -> Log.ERROR
Significance.INTERNAL_ERROR -> Log.ERROR
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class ToastRelay internal constructor(
private val toaster: Toaster,
public val configuration: Configuration,
) : Relay {

/**
* A set of configurable options for a ToastRelay.
* @property toastLength Should be one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG]. Defaults to short.
Expand Down Expand Up @@ -83,31 +82,42 @@ public class ToastRelay internal constructor(

override suspend fun process(event: Event) {
val toastFacets = event.facets.filterIsInstance(ToastFacet::class.java)
val shouldToastWithoutToastFacet = event.hasHighEnoughSignificance() &&
configuration.toastSignificantEvents
val shouldToastWithoutToastFacet =
event.hasHighEnoughSignificance() &&
configuration.toastSignificantEvents
val shouldToast = toastFacets.isNotEmpty() || shouldToastWithoutToastFacet
if (shouldToast && configuration.enabled) {
val message = toastFacets.firstOrNull()?.message ?: event.description
val correctedLength = when (configuration.toastLength) {
Toast.LENGTH_SHORT -> configuration.toastLength
Toast.LENGTH_LONG -> configuration.toastLength
else -> Toast.LENGTH_SHORT
}
val correctedLength =
when (configuration.toastLength) {
Toast.LENGTH_SHORT -> configuration.toastLength
Toast.LENGTH_LONG -> configuration.toastLength
else -> Toast.LENGTH_SHORT
}
toaster.toast(message, correctedLength)
}
}

private fun Event.hasHighEnoughSignificance(): Boolean = facets
.filterIsInstance(Significance::class.java)
.any { it >= configuration.minimumSignificance }
private fun Event.hasHighEnoughSignificance(): Boolean =
facets
.filterIsInstance(Significance::class.java)
.any { it >= configuration.minimumSignificance }
}

internal interface Toaster {
suspend fun toast(message: String, length: Int)
suspend fun toast(
message: String,
length: Int,
)
}

private class ToasterImpl(private val context: Context) : Toaster {
override suspend fun toast(message: String, length: Int) = withContext(Dispatchers.Main) {
private class ToasterImpl(
private val context: Context,
) : Toaster {
override suspend fun toast(
message: String,
length: Int,
) = withContext(Dispatchers.Main) {
Toast.makeText(context, message, length).show()
}
}
Expand All @@ -119,8 +129,9 @@ private interface Toggles {
private fun sampleToastConfig() {
val propertyChangeConfig = ToastRelay.Configuration.Default(toastSignificantEvents = true)

class PropertyBehaviorChangeConfig(private val toggles: Toggles) :
ToastRelay.Configuration by ToastRelay.Configuration.Default() {
class PropertyBehaviorChangeConfig(
private val toggles: Toggles,
) : ToastRelay.Configuration by ToastRelay.Configuration.Default() {
override var enabled: Boolean
get() = toggles["ToastRelay Toggle"]
set(_) = Unit
Expand Down
Loading
Loading