Skip to content

Commit

Permalink
feat: impl SDK version generation task (#6)
Browse files Browse the repository at this point in the history
* wip: wip

* feat: impl SDK version generation task
  • Loading branch information
RyuNen344 authored Jun 2, 2024
1 parent ad5f32b commit 09ad210
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
module: [ "glyph-ktx", "glyph-compose" ]
module: [ "glyph-ktx", "glyph-ktx-compose" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
module: [ "glyph-ktx", "glyph-compose" ]
module: [ "glyph-ktx", "glyph-ktx-compose" ]
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 0 additions & 2 deletions glyph-compose/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ apply from: rootProject.layout.projectDirectory.file("gradle/android.gradle")
apply from: rootProject.layout.projectDirectory.file("gradle/publish.gradle")
apply from: rootProject.layout.projectDirectory.file("gradle/testing.gradle")

android.namespace = "io.github.ryunen344.glyph.compose"
android.namespace = "io.github.ryunen344.glyph.ktx.compose"

dependencies {
api fileTree(dir: '../Glyph-Developer-Kit/sdk', include: '*.jar')
implementation projects.glyphKtx
}
File renamed without changes.
2 changes: 2 additions & 0 deletions glyph-ktx-compose/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_NAME=glyph-ktx-compose
POM_DESCRIPTION=glyph-ktx-compose
1 change: 1 addition & 0 deletions glyph-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

apply from: rootProject.layout.projectDirectory.file("gradle/android.gradle")
apply from: rootProject.layout.projectDirectory.file("gradle/publish.gradle")
apply from: rootProject.layout.projectDirectory.file("gradle/sdk-version.gradle")
apply from: rootProject.layout.projectDirectory.file("gradle/testing.gradle")

android.namespace = "io.github.ryunen344.glyph.ktx"
Expand Down
66 changes: 66 additions & 0 deletions gradle/sdk-version.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import javax.inject.Inject

abstract class GitSubmoduleHashValueSource implements ValueSource<String, org.gradle.api.provider.ValueSourceParameters.None> {
@Inject
abstract ExecOperations getExecOperations()

@Override
String obtain() {
return new ByteArrayOutputStream().withStream { os ->
execOperations.exec {
it.commandLine "git", "rev-parse", "HEAD:Glyph-Developer-Kit"
it.standardOutput = os
}
os.toString().trim()
}
}
}

class GenerateVersionFileTask extends DefaultTask {

@OutputDirectory
File outputDir

@Input
String packageName

@Input
String gitSubmoduleHash

{
group = 'git'
description = 'Generate SDK version file'
}

@TaskAction
def invoke() {
outputDir.delete()
File packageDir = new File(outputDir, packageName.replace((char) '.', File.separatorChar))
packageDir.mkdirs()
File outputFile = new File(packageDir, "Version.kt")
def text = "package ${packageName}\n\n/** This value is generated, automatically. Do not modify. **/\npublic const val GLYPH_SDK_VERSION = \"${gitSubmoduleHash}\""
new FileOutputStream(outputFile).withStream { os ->
os.write(text.getBytes())
}
}
}

def versionDir = project.layout.buildDirectory.dir("sdk-version")

android.sourceSets {
main {
java.srcDir(versionDir)
}
}

def generateVersionFileTask = tasks.register("generateVersionFileTask", GenerateVersionFileTask) {
outputDir = versionDir.get().asFile
packageName = android.namespace
gitSubmoduleHash = providers.of(GitSubmoduleHashValueSource.class) {}.get()
}

afterEvaluate {
tasks.withType(Jar).configureEach { dependsOn(generateVersionFileTask) }
tasks.named("compileDebugKotlin").configure { dependsOn(generateVersionFileTask) }
tasks.named("compileReleaseKotlin").configure { dependsOn(generateVersionFileTask) }
}
File renamed without changes.
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ develocity {
rootProject.name = "GlyphKtxRoot"
include(
":glyph-ktx",
":glyph-compose",
":glyph-ktx-compose",
":sample-ktx",
":sample-compose"
":sample-ktx-compose"
)

0 comments on commit 09ad210

Please sign in to comment.