Skip to content

Commit

Permalink
chore: Add UpdateChangelogsTask
Browse files Browse the repository at this point in the history
Signed-off-by: Hu Shenghao <[email protected]>
  • Loading branch information
hushenghao committed Nov 8, 2024
1 parent 02502f4 commit f29de25
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
4 changes: 4 additions & 0 deletions build-logic/convention/src/main/kotlin/Dls.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("SpellCheckingInspection", "ObjectPropertyName")

import com.android.build.api.dsl.ApplicationBuildType
import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
Expand Down Expand Up @@ -49,6 +50,9 @@ fun DependencyHandler.implementation(flavor: String, dependencyNotation: Any): D
val Project.javaExtension: JavaPluginExtension
get() = extensions.getByName<JavaPluginExtension>("java")

val Project.android: AppExtension
get() = extensions.getByName<AppExtension>("android")

fun <T : BaseExtension> Project.configureAndroid(configure: Action<T>? = null) {

javaExtension.toolchain {
Expand Down
3 changes: 3 additions & 0 deletions build-logic/convention/src/main/kotlin/EasterEggApp.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.dede.android_eggs.tasks.UpdateChangelogsTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
Expand Down Expand Up @@ -36,6 +37,8 @@ class EasterEggApp : Plugin<Project> {
fatal += listOf("NewApi", "InlinedApi")
}
}

UpdateChangelogsTask.register(this)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.dede.android_eggs.tasks

import android
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.internal.extensions.stdlib.capitalized
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.register

abstract class UpdateChangelogsTask : Exec() {

companion object Register : Action<Project> {

fun register(project: Project) {
project.afterEvaluate(this)
}

override fun execute(project: Project) {
with(project) {
val task = tasks.register<UpdateChangelogsTask>("updateChangelogs") {
workingDir("${rootDir.absolutePath}/script/changelogs")
outputDir = file("${rootDir.absolutePath}/fastlane/metadata/android")
observedFiles = files(
"${rootDir.absolutePath}/CHANGELOG.md",
"${rootDir.absolutePath}/CHANGELOG_zh.md"
)
group = "custom"
}

android.applicationVariants.forEach { variant ->
val variantName = variant.name.capitalized()
val assembleTask = tasks.findByName("assemble$variantName")
assembleTask?.dependsOn(task)
}
}
}

}

@get:Input
abstract val observedFiles: Property<FileCollection>

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

init {
@Suppress("LeakingThis")
commandLine("python3", "changelogs.py")
}
}
6 changes: 0 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ tasks.wrapper {
task<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

task<Exec>("changelogs") {
// requirement python3
workingDir("script/changelogs")
commandLine("python3", "changelogs.py")
}

0 comments on commit f29de25

Please sign in to comment.