Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:

runs-on: ubuntu-latest

permissions:
checks: write
pull-requests: write

steps:
- uses: actions/checkout@v3
- name: set up JDK 17
Expand All @@ -25,10 +29,24 @@ jobs:
- name: Build with Gradle
run: ./gradlew build

- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: lib/build/test-results/**/*.xml

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-report
path: lib/build/reports/tests/test/

- name: Validate Maven Central publishing setup
run: ./gradlew :lib:publishToMavenLocal --dry-run

- name: Validate Gradle Plugin Portal publishing setup
continue-on-error: ${{ github.base_ref != 'production' && github.ref_name != 'production' }}
run: ./gradlew :lib:publishPlugins --validate-only
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ gradle-app.setting

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Kotlin ###
.kotlin
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ buildscript {

dependencies {
// ...
classpath 'com.appswithlove.updraft:updraft:3.0.0'
classpath 'com.appswithlove.updraft:updraft:3.0.1'
}
}
```
Expand All @@ -37,7 +37,7 @@ or

```kotlin
plugins {
id("com.appswithlove.updraft") version "3.0.0"
id("com.appswithlove.updraft") version "3.0.1"
}
```

Expand Down Expand Up @@ -125,7 +125,7 @@ buildscript {
// ...
}
dependencies {
classpath 'com.appswithlove.updraft:updraft:3.0.0'
classpath 'com.appswithlove.updraft:updraft:3.0.1'
// ...
}
}
Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ plugins {
alias(libs.plugins.coveralls)
alias(libs.plugins.kotlin.jvm) apply false
id("signing")
// Define Updraft plugin
// alias(libs.plugins.updraft) apply false
alias(libs.plugins.updraft) apply false
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

GROUP=com.appswithlove.updraft
POM_ARTIFACT_ID=updraft
VERSION_NAME=3.0.0
VERSION_NAME=3.0.1

POM_NAME=updraft-plugin-android
POM_DESCRIPTION=This is a gradle Android plugin for automated uploads to Updraft
Expand Down
11 changes: 8 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ activityCompose = "1.11.0"
coreKtx = "1.17.0"
lifecycleRuntimeKtx = "2.9.4"
cglibNodep = "3.3.0"
junit5 = "5.14.3"
kotest = "5.9.1"
dokkaGradlePlugin = "2.0.0"
junit = "4.13.2"
updraft = "2.2.9"
updraft = "3.0.0"
maven-publish = "0.34.0"
gradle-publish = "2.0.0"
coveralls = "2.4.0"
Expand All @@ -23,6 +25,10 @@ ui = { module = "androidx.compose.ui:ui" }
ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
cglib-nodep = { module = "cglib:cglib-nodep", version.ref = "cglibNodep" }
junit5-bom = { module = "org.junit:junit-bom", version.ref = "junit5" }
junit5-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit5" }
junit5-launcher = { module = "org.junit.platform:junit-platform-launcher" }
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokkaGradlePlugin" }
gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "agp" }
Expand All @@ -37,5 +43,4 @@ maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publ
gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-publish" }
coveralls = { id = "com.github.kt3k.coveralls", version.ref = "coveralls" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
# Define Updraft plugin
# updraft = { id = "com.appswithlove.updraft", version.ref = "updraft" }
updraft = { id = "com.appswithlove.updraft", version.ref = "updraft" }
13 changes: 11 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@ plugins {

dependencies {
implementation(gradleApi())
testImplementation(gradleTestKit())
testRuntimeOnly(libs.cglib.nodep)
implementation(libs.kotlin.gradle.plugin)
implementation(libs.gradle)
implementation(libs.gradle.api)
implementation(libs.kotlin.stdlib)

testImplementation(gradleTestKit())
testRuntimeOnly(libs.cglib.nodep)
testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.jupiter)
testImplementation(libs.kotest.assertions)
testRuntimeOnly(libs.junit5.launcher)
}

tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
})
testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
}
Expand Down
27 changes: 17 additions & 10 deletions lib/src/main/kotlin/com/appswithlove/updraft/UpdraftPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class UpdraftPlugin : Plugin<Project> {
override fun apply(project: Project) {
val updraftExtension = project.extensions.create("updraft", UpdraftExtension::class.java)

val androidComponents = project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
val androidComponents =
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
androidComponents.onVariants { variant ->
val variantName = variant.name
val variantNameCapitalized = variantName.replaceFirstChar { it.uppercase() }
Expand Down Expand Up @@ -90,10 +91,10 @@ class UpdraftPlugin : Plugin<Project> {
task.releaseNotes.set(releaseNotesProvider)

task.doFirst {
val outputFile = apkFile.getOrNull()?.asFile
if (outputFile == null || !outputFile.exists()) {
throw GradleException("Could not find a build artifact. (Make sure to run assemble$variantNameCapitalized task first)")
}
validateBuildArtifact(
apkFile.getOrNull()?.asFile,
"assemble$variantNameCapitalized",
)
}
}

Expand All @@ -111,16 +112,16 @@ class UpdraftPlugin : Plugin<Project> {
task.releaseNotes.set(releaseNotesProvider)

task.doFirst {
val outputFile = aabFile.getOrNull()?.asFile
if (outputFile == null || !outputFile.exists()) {
throw GradleException("Could not find a build artifact. (Make sure to run bundle$variantNameCapitalized task first)")
}
validateBuildArtifact(
aabFile.getOrNull()?.asFile,
"bundle$variantNameCapitalized",
)
}
}
}
}

private fun getReleaseNotes(
internal fun getReleaseNotes(
project: Project,
flavors: List<String>,
updraftExtension: UpdraftExtension,
Expand Down Expand Up @@ -166,4 +167,10 @@ class UpdraftPlugin : Plugin<Project> {
}
}
}

internal fun validateBuildArtifact(outputFile: File?, taskName: String) {
if (outputFile == null || !outputFile.exists()) {
throw GradleException("Could not find a build artifact. (Make sure to run $taskName task first)")
}
}
}
66 changes: 39 additions & 27 deletions lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,50 @@ abstract class UpdraftTask : DefaultTask() {
it.standardOutput = os
}

val execResponse = JsonSlurperClassic().parseText(os.toString())

if (execResponse is Map<*, *> && execResponse.isNotEmpty()) {
when {
execResponse["success"] == "ok" -> {
val publicUrl = execResponse["public_link"]
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
if (publicUrl != null) println("Get it here -> $publicUrl")
println("--------------------------------------")
}

execResponse["detail"] == "Not found." -> {
throw GradleException("Could not updraft to the given url. Please recheck that.")
}

else -> {
throw GradleException(os.toString())
}
}
} else {
println(execResponse)
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
println("--------------------------------------")
}
handleResponse(os.toString())
}
}
}

companion object {
private fun createCurlParam(text: String?, name: String): String {
internal fun handleResponse(response: String) {
val execResponse = JsonSlurperClassic().parseText(response)

if (execResponse is Map<*, *> && execResponse.isNotEmpty()) {
when {
execResponse["success"] == "ok" -> {
val publicUrl = execResponse["public_link"]
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
if (publicUrl != null) println("Get it here -> $publicUrl")
println("--------------------------------------")
}

// App bundles (AAB) are processed asynchronously: Updraft accepts the upload and returns a task id
execResponse["task_id"] != null -> {
println("\n--------------------------------------")
println("Your App was uploaded to Updraft and is being processed.")
execResponse["task_upload_description"]?.let { println(it) }
println("--------------------------------------")
}

execResponse["detail"] == "Not found." -> {
throw GradleException("Could not updraft to the given url. Please recheck that.")
}

else -> {
throw GradleException(response)
}
}
} else {
println(execResponse)
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
println("--------------------------------------")
}
}

internal fun createCurlParam(text: String?, name: String): String {
return if (text.isNullOrBlank()) "" else "-F $name=$text"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.appswithlove.updraft

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class CreateCurlParamTest {

@Test
fun createCurlParam_withNullText_returnsEmpty() {
UpdraftTask.createCurlParam(null, "custom_branch") shouldBe ""
}

@Test
fun createCurlParam_withBlankText_returnsEmpty() {
UpdraftTask.createCurlParam(" ", "custom_branch") shouldBe ""
}

@Test
fun createCurlParam_withValue_returnsFormattedParam() {
UpdraftTask.createCurlParam("main", "custom_branch") shouldBe "-F custom_branch=main"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.appswithlove.updraft

import io.kotest.matchers.shouldNotBe
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.Test

class GitValueSourcesTest {

private val project = ProjectBuilder.builder().build()

@Test
fun gitBranch_obtain_returnsNonNullString() {
val result = project.providers.of(GitBranchValueSource::class.java) {}.get()
result shouldNotBe null
}

@Test
fun gitCommit_obtain_returnsNonNullString() {
val result = project.providers.of(GitCommitValueSource::class.java) {}.get()
result shouldNotBe null
}

@Test
fun gitTags_obtain_returnsNonNullString() {
val result = project.providers.of(GitTagsValueSource::class.java) {}.get()
result shouldNotBe null
}

@Test
fun gitUrl_obtain_returnsNonNullString() {
val result = project.providers.of(GitUrlValueSource::class.java) {}.get()
result shouldNotBe null
}
}
31 changes: 31 additions & 0 deletions lib/src/test/kotlin/com/appswithlove/updraft/HandleResponseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.appswithlove.updraft

import org.gradle.api.GradleException
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows

class HandleResponseTest {

@Test
fun handleResponse_withSuccessOk_succeeds() {
assertDoesNotThrow { UpdraftTask.handleResponse("""{"success":"ok","public_link":"https://example.com"}""") }
}

@Test
fun handleResponse_withTaskId_succeeds() {
assertDoesNotThrow {
UpdraftTask.handleResponse("""{"task_id":"b0e7","task_upload_description":"You can check the results of the build processing at the link: https://example.com/b0e7/"}""")
}
}

@Test
fun handleResponse_withNotFound_throws() {
assertThrows<GradleException> { UpdraftTask.handleResponse("""{"detail":"Not found."}""") }
}

@Test
fun handleResponse_withUnknownResponse_throws() {
assertThrows<GradleException> { UpdraftTask.handleResponse("""{"error":"invalid app"}""") }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.appswithlove.updraft

import io.kotest.matchers.maps.shouldBeEmpty
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class UpdraftExtensionTest {

private val extension = UpdraftExtension()

@Test
fun urls_default_isEmpty() {
extension.urls.shouldBeEmpty()
}

@Test
fun releaseNotes_default_isNull() {
extension.releaseNotes shouldBe null
}
}
Loading
Loading