Merge branch 'main' into rpf-update-firebase-ktx

* main:
  Fix action name and version
  Apply spotless automatically during build and commit back to PR
  Fix #1008: Use capitalized variant name when registering gradle tasks

Change-Id: I32f6dc608179586357ed017ae35a05ca97389559
pull/1006/head
Don Turner 1 year ago
commit a9609c8809

@ -34,8 +34,11 @@ jobs:
- name: Setup Gradle - name: Setup Gradle
uses: gradle/gradle-build-action@v2 uses: gradle/gradle-build-action@v2
- name: Check spotless - name: Apply formatting if failed
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply Spotless
- name: Build all build type and flavor permutations - name: Build all build type and flavor permutations
run: ./gradlew assemble run: ./gradlew assemble

@ -29,7 +29,7 @@ import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.configure import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.register
import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.process.ExecOperations import org.gradle.process.ExecOperations
@ -58,7 +58,7 @@ abstract class GenerateBadgingTask : DefaultTask() {
aapt2Executable.get().asFile.absolutePath, aapt2Executable.get().asFile.absolutePath,
"dump", "dump",
"badging", "badging",
apk.get().asFile.absolutePath apk.get().asFile.absolutePath,
) )
standardOutput = badging.asFile.get().outputStream() standardOutput = badging.asFile.get().outputStream()
} }
@ -86,12 +86,12 @@ abstract class CheckBadgingTask : DefaultTask() {
if ( if (
Files.mismatch( Files.mismatch(
goldenBadging.get().asFile.toPath(), goldenBadging.get().asFile.toPath(),
generatedBadging.get().asFile.toPath() generatedBadging.get().asFile.toPath(),
) != -1L ) != -1L
) { ) {
throw GradleException( throw GradleException(
"Generated badging is different from golden badging! " + "Generated badging is different from golden badging! " +
"If this change is intended, run ./gradlew updateBadging" "If this change is intended, run ./gradlew updateBadging",
) )
} }
} }
@ -99,44 +99,47 @@ abstract class CheckBadgingTask : DefaultTask() {
fun Project.configureBadgingTasks( fun Project.configureBadgingTasks(
baseExtension: BaseExtension, baseExtension: BaseExtension,
componentsExtension: ApplicationAndroidComponentsExtension componentsExtension: ApplicationAndroidComponentsExtension,
) { ) {
// Registers a callback to be called, when a new variant is configured // Registers a callback to be called, when a new variant is configured
componentsExtension.onVariants { variant -> componentsExtension.onVariants { variant ->
// Registers a new task to verify the app bundle. // Registers a new task to verify the app bundle.
val generateBadging = tasks.register<GenerateBadgingTask>("generate${variant.name}Badging") { val capitalizedVariantName = variant.name.capitalized()
apk.set( val generateBadging =
variant.artifacts.get(SingleArtifact.APK_FROM_BUNDLE) tasks.register<GenerateBadgingTask>("generate${capitalizedVariantName}Badging") {
) apk.set(
aapt2Executable.set( variant.artifacts.get(SingleArtifact.APK_FROM_BUNDLE),
File( )
baseExtension.sdkDirectory, aapt2Executable.set(
"build-tools/${baseExtension.buildToolsVersion}/aapt2" File(
baseExtension.sdkDirectory,
"build-tools/${baseExtension.buildToolsVersion}/aapt2",
),
) )
)
badging.set( badging.set(
project.layout.buildDirectory.file( project.layout.buildDirectory.file(
"outputs/apk_from_bundle/${variant.name}/${variant.name}-badging.txt" "outputs/apk_from_bundle/${variant.name}/${variant.name}-badging.txt",
),
) )
) }
}
tasks.register<Copy>("update${variant.name}Badging") { tasks.register<Copy>("update${capitalizedVariantName}Badging") {
from(generateBadging.get().badging) from(generateBadging.get().badging)
into(project.layout.projectDirectory) into(project.layout.projectDirectory)
} }
val checkBadgingTaskName = "check${variant.name}Badging" val checkBadgingTaskName = "check${capitalizedVariantName}Badging"
tasks.register<CheckBadgingTask>(checkBadgingTaskName) { tasks.register<CheckBadgingTask>(checkBadgingTaskName) {
goldenBadging.set( goldenBadging.set(
project.layout.projectDirectory.file("${variant.name}-badging.txt")) project.layout.projectDirectory.file("${variant.name}-badging.txt"),
)
generatedBadging.set( generatedBadging.set(
generateBadging.get().badging generateBadging.get().badging,
) )
output.set( output.set(
project.layout.buildDirectory.dir("intermediates/$checkBadgingTaskName") project.layout.buildDirectory.dir("intermediates/$checkBadgingTaskName"),
) )
} }
} }

Loading…
Cancel
Save