Use explicit Gradle tasks to handle build artifact collection (#1745)
This commit is contained in:
parent
f08ad35d2e
commit
acc448ce74
10 changed files with 98 additions and 13 deletions
2
.github/workflows/deploy_snapshot.yml
vendored
2
.github/workflows/deploy_snapshot.yml
vendored
|
@ -33,7 +33,7 @@ jobs:
|
|||
SNAPSHOT: "true"
|
||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||
with:
|
||||
arguments: --no-configuration-cache :app:assembleFreeRelease :app:assembleNonFreeRelease
|
||||
arguments: --no-configuration-cache collectFreeReleaseApks collectNonFreeReleaseApks
|
||||
|
||||
- name: Clean secrets
|
||||
run: scripts/signing-cleanup.sh
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
|
||||
|
||||
plugins {
|
||||
id("com.github.android-password-store.android-application")
|
||||
|
@ -11,6 +10,7 @@ plugins {
|
|||
id("com.github.android-password-store.kotlin-kapt")
|
||||
id("com.github.android-password-store.versioning-plugin")
|
||||
id("com.github.android-password-store.sentry")
|
||||
id("com.github.android-password-store.rename-artifacts")
|
||||
id("dagger.hilt.android.plugin")
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,6 @@ fun isSnapshot(): Boolean {
|
|||
}
|
||||
|
||||
android {
|
||||
if (isSnapshot()) {
|
||||
applicationVariants.all {
|
||||
outputs.all {
|
||||
(this as BaseVariantOutputImpl).outputFileName = "aps-${flavorName}_$versionName.apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
compileOptions { isCoreLibraryDesugaringEnabled = true }
|
||||
|
||||
defaultConfig {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package artifacts
|
||||
|
||||
import com.android.build.api.variant.BuiltArtifactsLoader
|
||||
import java.io.File
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
/** Task to collect APKs in a given [outputDirectory]. */
|
||||
@CacheableTask
|
||||
abstract class CollectApksTask : DefaultTask() {
|
||||
@get:InputFiles @get:PathSensitive(PathSensitivity.NONE) abstract val apkFolder: DirectoryProperty
|
||||
|
||||
@get:Input abstract val variantName: Property<String>
|
||||
|
||||
@get:Internal abstract val builtArtifactsLoader: Property<BuiltArtifactsLoader>
|
||||
|
||||
@get:OutputDirectory abstract val outputDirectory: DirectoryProperty
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val outputDir = outputDirectory.asFile.get()
|
||||
outputDir.mkdirs()
|
||||
val builtArtifacts =
|
||||
builtArtifactsLoader.get().load(apkFolder.get()) ?: throw RuntimeException("Cannot load APKs")
|
||||
builtArtifacts.elements.forEach { artifact ->
|
||||
File(artifact.outputFile)
|
||||
.renameTo(outputDir.resolve("APS-${variantName.get()}-${artifact.versionName}.apk"))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package artifacts
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
abstract class CollectBundleTask : DefaultTask() {
|
||||
@get:InputFile abstract val bundleFile: RegularFileProperty
|
||||
|
||||
@get:Input abstract val variantName: Property<String>
|
||||
|
||||
@get:Input abstract val versionName: Property<String>
|
||||
|
||||
@get:OutputDirectory abstract val outputDirectory: DirectoryProperty
|
||||
|
||||
@TaskAction
|
||||
fun taskAction() {
|
||||
val outputDir = outputDirectory.asFile.get()
|
||||
outputDir.mkdirs()
|
||||
bundleFile
|
||||
.get()
|
||||
.asFile
|
||||
.renameTo(outputDir.resolve("APS-${variantName.get()}-${versionName.get()}.aab"))
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import flavors.FlavorDimensions
|
||||
import flavors.ProductFlavors
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import com.android.build.gradle.TestedExtension
|
||||
import flavors.configureSlimTests
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import artifacts.CollectApksTask
|
||||
import artifacts.CollectBundleTask
|
||||
import com.android.build.api.artifact.SingleArtifact
|
||||
|
||||
plugins { id("com.android.application") }
|
||||
|
||||
androidComponents {
|
||||
onVariants { variant ->
|
||||
project.tasks.register<CollectApksTask>("collect${variant.name.capitalize()}Apks") {
|
||||
variantName.set(variant.name)
|
||||
apkFolder.set(variant.artifacts.get(SingleArtifact.APK))
|
||||
builtArtifactsLoader.set(variant.artifacts.getBuiltArtifactsLoader())
|
||||
outputDirectory.set(project.layout.projectDirectory.dir("outputs"))
|
||||
}
|
||||
project.tasks.register<CollectBundleTask>("collect${variant.name.capitalize()}Bundle") {
|
||||
variantName.set(variant.name)
|
||||
versionName.set(android.defaultConfig.versionName)
|
||||
bundleFile.set(variant.artifacts.get(SingleArtifact.BUNDLE))
|
||||
outputDirectory.set(project.layout.projectDirectory.dir("outputs"))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ private const val EXCEPTION_MESSAGE =
|
|||
private const val CROWDIN_BUILD_API_URL =
|
||||
"https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
|
||||
|
||||
@Suppress("Unused")
|
||||
class CrowdinDownloadPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gradle.kotlin.dsl.register
|
|||
* Base on PublicSuffixListGenerator from OkHttp:
|
||||
* https://github.com/square/okhttp/blob/master/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.java
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class PublicSuffixListPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.tasks.register<PSLUpdateTask>("updatePSL") {
|
||||
|
|
|
@ -11,8 +11,5 @@ mkdir -p "$SSHDIR"
|
|||
echo "$ACTIONS_DEPLOY_KEY" > "$SSHDIR/key"
|
||||
chmod 600 "$SSHDIR/key"
|
||||
export SERVER_DEPLOY_STRING="$SSH_USERNAME@$SERVER_ADDRESS:$SERVER_DESTINATION"
|
||||
mkdir -p "$GITHUB_WORKSPACE/APS"
|
||||
cp -v ./app/build/outputs/apk/free/release/*.apk "$GITHUB_WORKSPACE/APS/"
|
||||
cp -v ./app/build/outputs/apk/nonFree/release/*.apk "$GITHUB_WORKSPACE/APS/"
|
||||
cd "$GITHUB_WORKSPACE/APS"
|
||||
cd "$GITHUB_WORKSPACE/app/outputs/"
|
||||
rsync -ahvcr --omit-dir-times --progress --delete --no-o --no-g -e "ssh -i $SSHDIR/key -o StrictHostKeyChecking=no -p $SSH_PORT" . "$SERVER_DEPLOY_STRING"
|
||||
|
|
Loading…
Reference in a new issue