From f29de253f89332532b146c83393bf9997246bd42 Mon Sep 17 00:00:00 2001 From: Hu Shenghao Date: Fri, 8 Nov 2024 11:11:45 +0800 Subject: [PATCH] chore: Add UpdateChangelogsTask Signed-off-by: Hu Shenghao --- build-logic/convention/src/main/kotlin/Dls.kt | 4 ++ .../src/main/kotlin/EasterEggApp.kt | 3 + .../tasks/UpdateChangelogsTask.kt | 56 +++++++++++++++++++ build.gradle.kts | 6 -- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/com/dede/android_eggs/tasks/UpdateChangelogsTask.kt diff --git a/build-logic/convention/src/main/kotlin/Dls.kt b/build-logic/convention/src/main/kotlin/Dls.kt index c07d33e3..93b6b8a6 100644 --- a/build-logic/convention/src/main/kotlin/Dls.kt +++ b/build-logic/convention/src/main/kotlin/Dls.kt @@ -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 @@ -49,6 +50,9 @@ fun DependencyHandler.implementation(flavor: String, dependencyNotation: Any): D val Project.javaExtension: JavaPluginExtension get() = extensions.getByName("java") +val Project.android: AppExtension + get() = extensions.getByName("android") + fun Project.configureAndroid(configure: Action? = null) { javaExtension.toolchain { diff --git a/build-logic/convention/src/main/kotlin/EasterEggApp.kt b/build-logic/convention/src/main/kotlin/EasterEggApp.kt index 56f5e93e..9ea3885f 100644 --- a/build-logic/convention/src/main/kotlin/EasterEggApp.kt +++ b/build-logic/convention/src/main/kotlin/EasterEggApp.kt @@ -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 @@ -36,6 +37,8 @@ class EasterEggApp : Plugin { fatal += listOf("NewApi", "InlinedApi") } } + + UpdateChangelogsTask.register(this) } } } \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/com/dede/android_eggs/tasks/UpdateChangelogsTask.kt b/build-logic/convention/src/main/kotlin/com/dede/android_eggs/tasks/UpdateChangelogsTask.kt new file mode 100644 index 00000000..ddcce39c --- /dev/null +++ b/build-logic/convention/src/main/kotlin/com/dede/android_eggs/tasks/UpdateChangelogsTask.kt @@ -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 { + + fun register(project: Project) { + project.afterEvaluate(this) + } + + override fun execute(project: Project) { + with(project) { + val task = tasks.register("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 + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty + + init { + @Suppress("LeakingThis") + commandLine("python3", "changelogs.py") + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 16c0b588..74ec6c44 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,9 +15,3 @@ tasks.wrapper { task("clean") { delete(rootProject.layout.buildDirectory) } - -task("changelogs") { - // requirement python3 - workingDir("script/changelogs") - commandLine("python3", "changelogs.py") -}