Skip to content

Commit

Permalink
dry run upload & logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fbzli committed Oct 7, 2024
1 parent 75fa4ac commit 9f7f9ee
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ch.ubique.gradle.alpaka.extensions

import kotlin.reflect.KProperty1

fun Any.prettyPrint(): String {
return this::class
.members
.filterIsInstance<KProperty1<Any, *>>()
.joinToString(separator = "\n") { property ->
property.name + ": " + property.get(this).toString().replace("\n", "\\n")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package ch.ubique.gradle.alpaka.task

import ch.ubique.gradle.alpaka.extensions.getResDirs
import ch.ubique.gradle.alpaka.extensions.prettyPrint
import ch.ubique.gradle.alpaka.model.UploadRequest
import ch.ubique.gradle.alpaka.network.BackendRepository
import ch.ubique.gradle.alpaka.network.OkHttpInstance
Expand Down Expand Up @@ -64,6 +65,10 @@ abstract class UploadToAlpakaBackendTask : DefaultTask() {
@get:InputFile
abstract var webIcon: Provider<File>

@get:Input
@set:Option(option = "alpaka-dryrun", description = "Execute the Alpaka upload as a dry-run.")
var dryrun: Boolean = false

@TaskAction
fun uploadAction() {
val proxy = proxy
Expand All @@ -84,10 +89,22 @@ abstract class UploadToAlpakaBackendTask : DefaultTask() {
signature = signature,
)

val apkFile = apk.get()
val webIconFile = webIcon.get()

logger.lifecycle("apk file: ${apkFile.relativeTo(project.rootDir).path} (${apkFile.length() / 1024} kB)")
logger.lifecycle("icon file: ${webIconFile.relativeTo(project.rootDir).path} (${webIconFile.length() / 1024} kB)")
logger.lifecycle("metadata:\n${uploadRequest.prettyPrint().prependIndent()}")

if (dryrun) {
logger.lifecycle("Dry-run completed.")
return
}

logger.lifecycle("Starting upload to Alpaka.")
try {
val backendRepository = BackendRepository()
backendRepository.appsUpload(uploadRequest, apk.get(), webIcon.get(), uploadKey)
backendRepository.appsUpload(uploadRequest, apkFile, webIconFile, uploadKey)
logger.lifecycle("Upload to Alpaka successful.")
} catch (e: Exception) {
val message = if (e is HttpException) {
Expand Down
2 changes: 1 addition & 1 deletion examplegroovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdk 26
targetSdk 34
versionCode 1
versionName project.version.toString()
versionName "1.0"

alpakaUploadKey = "defaultConfig upload key"
}
Expand Down
4 changes: 4 additions & 0 deletions examplegroovy/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
4 changes: 2 additions & 2 deletions examplekts/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ch.ubique.gradle.alpaka.extensions.applicationvariant.launcherIconLabel
import ch.ubique.gradle.alpaka.extensions.applicationvariant.alpakaUploadKey
import ch.ubique.gradle.alpaka.extensions.applicationvariant.launcherIconLabel

plugins {
alias(libs.plugins.androidApplication)
Expand All @@ -16,7 +16,7 @@ android {
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = project.version.toString()
versionName = "1.0"

alpakaUploadKey = "defaultConfig upload key"
}
Expand Down
4 changes: 4 additions & 0 deletions examplekts/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down

0 comments on commit 9f7f9ee

Please sign in to comment.