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
uses: gradle/gradle-build-action@v2
- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
- name: Apply formatting if failed
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
run: ./gradlew assemble

@ -29,7 +29,7 @@ import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
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.language.base.plugins.LifecycleBasePlugin
import org.gradle.process.ExecOperations
@ -58,7 +58,7 @@ abstract class GenerateBadgingTask : DefaultTask() {
aapt2Executable.get().asFile.absolutePath,
"dump",
"badging",
apk.get().asFile.absolutePath
apk.get().asFile.absolutePath,
)
standardOutput = badging.asFile.get().outputStream()
}
@ -86,12 +86,12 @@ abstract class CheckBadgingTask : DefaultTask() {
if (
Files.mismatch(
goldenBadging.get().asFile.toPath(),
generatedBadging.get().asFile.toPath()
generatedBadging.get().asFile.toPath(),
) != -1L
) {
throw GradleException(
"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(
baseExtension: BaseExtension,
componentsExtension: ApplicationAndroidComponentsExtension
componentsExtension: ApplicationAndroidComponentsExtension,
) {
// Registers a callback to be called, when a new variant is configured
componentsExtension.onVariants { variant ->
// Registers a new task to verify the app bundle.
val generateBadging = tasks.register<GenerateBadgingTask>("generate${variant.name}Badging") {
val capitalizedVariantName = variant.name.capitalized()
val generateBadging =
tasks.register<GenerateBadgingTask>("generate${capitalizedVariantName}Badging") {
apk.set(
variant.artifacts.get(SingleArtifact.APK_FROM_BUNDLE)
variant.artifacts.get(SingleArtifact.APK_FROM_BUNDLE),
)
aapt2Executable.set(
File(
baseExtension.sdkDirectory,
"build-tools/${baseExtension.buildToolsVersion}/aapt2"
)
"build-tools/${baseExtension.buildToolsVersion}/aapt2",
),
)
badging.set(
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)
into(project.layout.projectDirectory)
}
val checkBadgingTaskName = "check${variant.name}Badging"
val checkBadgingTaskName = "check${capitalizedVariantName}Badging"
tasks.register<CheckBadgingTask>(checkBadgingTaskName) {
goldenBadging.set(
project.layout.projectDirectory.file("${variant.name}-badging.txt"))
project.layout.projectDirectory.file("${variant.name}-badging.txt"),
)
generatedBadging.set(
generateBadging.get().badging
generateBadging.get().badging,
)
output.set(
project.layout.buildDirectory.dir("intermediates/$checkBadgingTaskName")
project.layout.buildDirectory.dir("intermediates/$checkBadgingTaskName"),
)
}
}

Loading…
Cancel
Save