Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldrn committed Oct 7, 2023
1 parent 09b7a3c commit 655d66b
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 78 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/publication-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CD | publication

on:
workflow_run:
workflows: [ "CI | library & demo app" ]
types: [ completed ]
branches: [ main ]

jobs:
lib-modules-build:
name: Build library modules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Official Gradle Wrapper Validation Action
uses: gradle/wrapper-validation-action@v1

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: adopt

- name: Set up Gradle cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-gradle-${{ github.run_id }}
path: |
~/.gradle/caches
~/.gradle/wrapper
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Grant execute permission for gradlew script
run: chmod +x gradlew

- name: Build all lib modules except demo app
run: ./gradlew build -x :demo-app:build -x check

publication:
name: Publish library artifacts
runs-on: ubuntu-latest
needs: [ lib-modules-check, demo-app-build ]
steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: adopt

- name: Set up Gradle cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-gradle-${{ github.run_id }}
path: |
~/.gradle/caches
~/.gradle/wrapper
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Grant execute permission for gradlew script
run: chmod +x gradlew

- name: Publish snapshot
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository

delete-cache:
name: Delete cache
if: always()
runs-on: ubuntu-latest
needs: [ lib-modules-check, demo-app-build ]
steps:
- uses: actions/checkout@v2

- name: Delete cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete ${{ runner.os }}-gradle-${{ github.run_id }} --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

[![](https://github.com/gabrieldrn/Konstellation/workflows/CI%20|%20library%20%26%20demo%20app/badge.svg?branch=develop)]()

Konstellation is a Jetpack Compose library that provides a set of components and tools to build
beautiful and consistent graphs.
Konstellation is a Jetpack Compose library that provides a set of components and tools to draw graphs.

<p align="center">
<picture>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

/**
* A plugin used by android libraries modules from Konstellation to configure themselves. It
* provides a convention to keep consistency across those modules.
* Keeps consistent configurations across android libraries modules.
*/
class KonstellationAndroidLibraryConventionPlugin : Plugin<Project> {

Expand All @@ -31,7 +30,7 @@ class KonstellationAndroidLibraryConventionPlugin : Plugin<Project> {

setupExplicitApi()

// TODO Not sure if proguard/R8 is relevant for libraries.
// TODO Proguard/R8

defaultConfig {
consumerProguardFiles.add(file("consumer-rules.pro"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dev.gabrieldrn.konstellation.buildlogic.JAVA_VERSION
import dev.gabrieldrn.konstellation.buildlogic.getPlugin
import dev.gabrieldrn.konstellation.buildlogic.javaVersion
import dev.gabrieldrn.konstellation.buildlogic.libs
import dev.gabrieldrn.konstellation.buildlogic.setupExplicitApi
import org.gradle.api.Plugin
Expand All @@ -21,8 +21,8 @@ class KonstellationJavaLibraryConventionPlugin : Plugin<Project> {
}

extensions.configure<JavaPluginExtension> {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
sourceCompatibility = JAVA_VERSION
targetCompatibility = JAVA_VERSION
}

setupExplicitApi()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
import dev.gabrieldrn.konstellation.buildlogic.Constants
import dev.gabrieldrn.konstellation.buildlogic.GROUP_ID
import dev.gabrieldrn.konstellation.buildlogic.MAVEN_REPO_NAME
import dev.gabrieldrn.konstellation.buildlogic.MAVEN_REPO_PASSWORD_ENV_KEY
import dev.gabrieldrn.konstellation.buildlogic.MAVEN_REPO_URL
import dev.gabrieldrn.konstellation.buildlogic.MAVEN_REPO_USERNAME_ENV_KEY
import dev.gabrieldrn.konstellation.buildlogic.extensions.PublicationConfigExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import java.net.URI

class KonstellationPublicationPlugin : Plugin<Project> {

private fun Project.publishing(config: PublishingExtension.() -> Unit) =
extensions.configure(config)

override fun apply(target: Project) = with(target) {
override fun apply(target: Project): Unit = with(target) {

val version = (properties["VERSION"] ?: error("Project version is unspecified.")) as String
val publicationConfig = extensions.create<PublicationConfigExtension>(
name = "publicationConfig",
/*args = */ name
)

val mavenRepoUsername = System.getenv(Constants.MAVEN_REPO_USERNAME_ENV_KEY)
?: properties[Constants.MAVEN_REPO_USERNAME_LOCAL_KEY] as String?
val mavenRepoUsername = findProperty(MAVEN_REPO_USERNAME_ENV_KEY) as String?
?: System.getenv("GITHUB_ACTOR")

val artifactId = if (group.toString().contains("charts")) {
"${name}-chart"
} else {
name
}

require(!mavenRepoUsername.isNullOrEmpty()) {
"Maven publication: Unable to retrieve the username for the credentials repository." +
"Either '${Constants.MAVEN_REPO_USERNAME_ENV_KEY}' env variable " +
"or '${Constants.MAVEN_REPO_USERNAME_LOCAL_KEY}' local property is not set."
}

val mavenRepoPassword = System.getenv(Constants.MAVEN_REPO_PASSWORD_ENV_KEY)
?: properties[Constants.MAVEN_REPO_PASSWORD_LOCAL_KEY] as String?

require(!mavenRepoPassword.isNullOrEmpty()) {
"Maven publication: Unable to retrieve the password for the credentials repository." +
"Either '${Constants.MAVEN_REPO_PASSWORD_ENV_KEY}' env variable " +
"or '${Constants.MAVEN_REPO_PASSWORD_LOCAL_KEY}' local property is not set."
}
val mavenRepoPassword = findProperty(MAVEN_REPO_PASSWORD_ENV_KEY) as String?
?: System.getenv("GITHUB_TOKEN")

pluginManager.apply("org.gradle.maven-publish")

Expand All @@ -50,39 +39,54 @@ class KonstellationPublicationPlugin : Plugin<Project> {
.filterNot {
it.name.contains("test", ignoreCase = true)
}
// .onEach { println(it.name) }
.map { it.dependencies }
.flatten()
.filter { it.group?.trim()?.isNotEmpty() ?: false }
.toList()
.forEach { dep ->
dependenciesNode.appendNode("dependency").apply {
appendNode("groupId", dep.group)
appendNode(
"groupId",
// Replace local group id with the proper project group id.
dep.group.takeIf { it != this@with.group } ?: GROUP_ID
)
appendNode("artifactId", dep.name)
appendNode("version", dep.version)
}
}
}
}

publishing {
publications {
create<MavenPublication>(name) {
groupId = Constants.GROUP_ID
this.artifactId = artifactId
this.version = version
artifact("$projectDir/build/outputs/aar/$name-release.aar")
configurePom()
afterEvaluate {
publishing {
publications {
create<MavenPublication>(publicationConfig.publicationName.ifEmpty { name }) {
groupId = GROUP_ID
artifactId = publicationConfig.artifactId
version = "${properties["project.version"]}"
file("$projectDir/build/outputs/aar")
.listFiles { f -> f.name.contains("release", ignoreCase = true) }
?.first()
?.let { artifact(it) }
configurePom()
}
}
}

// Nomad-shared GitHub Maven repo
repositories.maven {
name = Constants.MAVEN_REPO_NAME
url = URI.create(Constants.MAVEN_REPO_URL)
credentials {
username = mavenRepoUsername
password = mavenRepoPassword
if (!mavenRepoUsername.isNullOrEmpty() && !mavenRepoPassword.isNullOrEmpty()) {
repositories.maven {
name = MAVEN_REPO_NAME
url = uri(MAVEN_REPO_URL)
credentials {
username = mavenRepoUsername
password = mavenRepoPassword
}
}
} else {
logger.warn(
"No username or password found for $MAVEN_REPO_NAME. " +
"Please set the '$MAVEN_REPO_USERNAME_ENV_KEY' " +
"and '$MAVEN_REPO_PASSWORD_ENV_KEY' gradle properties."
)
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package dev.gabrieldrn.konstellation.buildlogic

/**
* Global constants for the build logic.
*/
@Suppress("UndocumentedPublicProperty")
object Constants {
const val GROUP_ID = "dev.gabrieldrn.konstellation"
const val MAVEN_REPO_NAME = "GitHub"
const val MAVEN_REPO_URL =
"https://maven.pkg.github.com/gabrieldrn/Konstellation"
const val MAVEN_REPO_USERNAME_ENV_KEY = "GPR_USER"
const val MAVEN_REPO_PASSWORD_ENV_KEY = "GPR_KEY"
const val MAVEN_REPO_USERNAME_LOCAL_KEY = "GITHUB_USER"
const val MAVEN_REPO_PASSWORD_LOCAL_KEY = "GITHUB_PERSONAL_ACCESS_TOKEN"
}
import org.gradle.api.JavaVersion

internal val JAVA_VERSION = JavaVersion.VERSION_17
internal const val STRICT_API_COMPILER_ARG = "-Xexplicit-api=strict"

internal const val GROUP_ID = "dev.gabrieldrn.konstellation"

internal const val MAVEN_REPO_NAME = "GitHubPackages"
internal const val MAVEN_REPO_URL = "https://maven.pkg.github.com/gabrieldrn/Konstellation"
internal const val MAVEN_REPO_USERNAME_ENV_KEY = "gpr.user"
internal const val MAVEN_REPO_PASSWORD_ENV_KEY = "gpr.key"
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

private const val STRICT_API_COMPILER_ARG = "-Xexplicit-api=strict"

/**
* Shortcut to configure Kotlin compiler options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ internal fun Project.configureKotlinAndroidCommon(
}

compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
sourceCompatibility = JAVA_VERSION
targetCompatibility = JAVA_VERSION
}

kotlinOptions {
jvmTarget = javaVersion.toString()
jvmTarget = JAVA_VERSION.toString()
}

buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.gabrieldrn.konstellation.buildlogic.extensions

open class PublicationConfigExtension(
defaultArtifactId: String = "",
) {
var publicationName: String = ""
var artifactId: String = defaultArtifactId
}
5 changes: 5 additions & 0 deletions charts/line/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ android {
namespace = "dev.gabrieldrn.konstellation.charts.line"
}

publicationConfig {
publicationName = "LineChart"
artifactId = "line-chart"
}

//dokkaHtml.configure {
// dokkaSourceSets {
// named("main") {
Expand Down
1 change: 0 additions & 1 deletion charts/line/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
VERSION=0.1.0
1 change: 0 additions & 1 deletion core/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
VERSION=0.1.0
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

project.version=0.1.0-SNAPSHOT

0 comments on commit 655d66b

Please sign in to comment.