Skip to content

Commit d291532

Browse files
Merge pull request #8 from appswithlove/main
Release 2.2.9
2 parents 494912f + 142daf6 commit d291532

5 files changed

Lines changed: 208 additions & 147 deletions

File tree

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ jobs:
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4444
with:
45-
tag_name: v${{ steps.get_version.outputs.version }}
46-
release_name: Release v${{ steps.get_version.outputs.version }}
45+
tag_name: ${{ steps.get_version.outputs.version }}
46+
release_name: ${{ steps.get_version.outputs.version }}
4747
body: |
48-
Automated release v${{ steps.get_version.outputs.version }}
48+
Automated release ${{ steps.get_version.outputs.version }}
4949
5050
Published to:
5151
- Maven Central Portal

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ buildscript {
2323
2424
dependencies {
2525
...
26-
classpath 'com.appswithlove.updraft:updraft:2.2.8'
26+
classpath 'com.appswithlove.updraft:updraft:2.2.9'
2727
}
2828
}
2929
```
@@ -32,7 +32,7 @@ or
3232

3333
```kotlin
3434
plugins {
35-
id("com.appswithlove.updraft") version "2.2.8"
35+
id("com.appswithlove.updraft") version "2.2.9"
3636
}
3737
```
3838

@@ -114,7 +114,7 @@ buildscript {
114114
...
115115
}
116116
dependencies {
117-
classpath 'com.appswithlove.updraft:updraft:2.2.8'
117+
classpath 'com.appswithlove.updraft:updraft:2.2.9'
118118
...
119119
}
120120
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
GROUP=com.appswithlove.updraft
2121
POM_ARTIFACT_ID=updraft
22-
VERSION_NAME=2.2.8
22+
VERSION_NAME=2.2.9
2323

2424
POM_NAME=updraft-plugin-android
2525
POM_DESCRIPTION=This is a gradle Android plugin for automated uploads to Updraft
Lines changed: 76 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,117 @@
11
package com.appswithlove.updraft
22

3-
import groovy.json.JsonSlurperClassic
43
import org.gradle.api.GradleException
54
import org.gradle.api.Plugin
65
import org.gradle.api.Project
7-
import org.gradle.process.ExecOperations
8-
import javax.inject.Inject
96

107
/**
118
* A plugin for uploading apk files to updraft.*/
129
class UpdraftPlugin implements Plugin<Project> {
1310

14-
private final ExecOperations execOps
15-
16-
@Inject
17-
UpdraftPlugin(ExecOperations execOperations) {
18-
this.execOps = execOperations
19-
}
20-
2111
@Override
2212
void apply(Project project) {
2313
project.extensions.create('updraft', UpdraftExtension.class)
2414
project.android.applicationVariants.all { variant ->
2515

26-
def plugin = this
2716
String variantName = variant.name
2817
String variantNameCapitalized = variantName.capitalize()
29-
String basePath = getProject().getProjectDir().getAbsolutePath()
30-
String filename = variant.outputs[0].outputFile
18+
String projectBasePath = getProject().getProjectDir().getAbsolutePath()
19+
20+
def uploadUrlsProvider = project.providers.provider { project.updraft.urls }
21+
def uploadUrls = uploadUrlsProvider.map { urlsMap ->
22+
def urlsForVariant = urlsMap[variantNameCapitalized]
23+
if (urlsForVariant == null) {
24+
return []
25+
}
26+
if (urlsForVariant instanceof String) {
27+
return [urlsForVariant]
28+
}
29+
return urlsForVariant
30+
}
3131

32-
def urls = project.updraft.urls[variantNameCapitalized]
3332
def gitBranchProvider = project.providers.of(GitBranchValueSource.class) {}
3433
def gitTagsProvider = project.providers.of(GitTagsValueSource.class) {}
3534
def gitCommitProvider = project.providers.of(GitCommitValueSource.class) {}
3635
def gitUrlProvider = project.providers.of(GitUrlValueSource.class) {}
37-
String releaseNotes = getReleaseNotes(project, variant)
38-
String whatsNew = createCurlParam(releaseNotes, "whats_new")
36+
def releaseNotesProvider = project.providers.provider { getReleaseNotes(project, variant) }
3937

40-
// Registers a task for every available build variant / flavor
41-
project.tasks.register("updraft${variantNameCapitalized}") {
42-
// Declares that the project runs after the build, not before.
43-
// If not stated, it will run at every gradle sync.
44-
45-
String gitBranch = createCurlParam(gitBranchProvider.get(), "custom_branch")
46-
String gitTags = createCurlParam(gitTagsProvider.get(), "custom_tags")
47-
String gitCommit = createCurlParam(gitCommitProvider.get(), "custom_commit")
48-
String gitUrl = createCurlParam(gitUrlProvider.get(), "custom_URL")
49-
50-
doLast {
51-
// APK
52-
def apkFile = new File(filename)
53-
String fileWithoutExt = apkFile.name.take(apkFile.name.lastIndexOf('.'))
54-
55-
if (apkFile != null && !apkFile.exists()) {
56-
def apkFolder = new File(apkFile.getParent())
57-
for (File currentFile in apkFolder.listFiles()) {
58-
if (currentFile.getName().startsWith(fileWithoutExt)) {
59-
apkFile = currentFile
60-
}
61-
}
62-
}
38+
def apkFileProvider = project.provider {
39+
def buildDir = project.layout.buildDirectory.get().asFile
40+
def apkDir = new File(buildDir, "outputs/apk/${variant.flavorName}/${variant.buildType.name}")
6341

64-
if (apkFile != null && !apkFile.exists()) {
65-
throw new GradleException("Could not find a build artifact. (Make sure to run assemble${variantNameCapitalized} before)")
42+
if (apkDir.exists() && apkDir.isDirectory()) {
43+
def apkFiles = apkDir.listFiles({ file -> file.name.endsWith(".apk") } as FileFilter)
44+
45+
if (apkFiles && apkFiles.size() > 1) {
46+
throw new GradleException("More than one .apk file exists in ${apkDir}: ${apkFiles*.name}")
6647
}
6748

68-
plugin.upload(apkFile, urls, gitBranch, gitTags, gitCommit, gitUrl, whatsNew)
49+
return apkFiles ? apkFiles[0] : null
6950
}
51+
return null
52+
}
53+
def apkFile = apkFileProvider.flatMap { file ->
54+
file ? project.layout.file(project.provider { file }) : project.objects.fileProperty()
7055
}
7156

72-
// Registers a task for every available build variant / flavor
73-
project.tasks.register("updraftBundle${variantNameCapitalized}") {
74-
// Declares that the project runs after the build, not before.
75-
// If not stated, it will run at every gradle sync.
76-
77-
String gitBranch = createCurlParam(gitBranchProvider.get(), "custom_branch")
78-
String gitTags = createCurlParam(gitTagsProvider.get(), "custom_tags")
79-
String gitCommit = createCurlParam(gitCommitProvider.get(), "custom_commit")
80-
String gitUrl = createCurlParam(gitUrlProvider.get(), "custom_URL")
81-
82-
doLast {
83-
def apkFile = new File(filename)
84-
String fileWithoutExt = apkFile.name.take(apkFile.name.lastIndexOf('.'))
85-
86-
// AAB
87-
def bundlePath =
88-
"${basePath}/build/outputs/bundle/${variantName}/${fileWithoutExt}.aab"
89-
90-
def aabFile = new File(bundlePath)
91-
if (aabFile != null && !aabFile.exists()) {
92-
def aabFolder = new File(aabFile.getParent())
93-
for (File currentFile in aabFolder.listFiles()) {
94-
println("file $currentFile.path")
95-
if (currentFile.getName().startsWith(fileWithoutExt)) {
96-
aabFile = currentFile
97-
}
98-
}
99-
}
57+
def aabFileProvider = project.provider {
58+
def buildDir = project.layout.buildDirectory.get().asFile
59+
def bundleDir = new File(buildDir, "outputs/bundle/${variantName}")
10060

101-
if (aabFile != null && !aabFile.exists()) {
102-
throw new GradleException("Could not find a build artifact. (Make sure to run bundle${variantNameCapitalized} before). \n We tried following location ${bundlePath}")
61+
if (bundleDir.exists() && bundleDir.isDirectory()) {
62+
def aabFiles = bundleDir.listFiles({ file -> file.name.endsWith(".aab") } as FileFilter)
63+
64+
if (aabFiles && aabFiles.size() > 1) {
65+
throw new GradleException("More than one .aab file exists in ${bundleDir}: ${aabFiles*.name}")
10366
}
10467

105-
plugin.upload(aabFile, urls, gitBranch, gitTags, gitCommit, gitUrl, whatsNew)
68+
return aabFiles ? aabFiles[0] : null
10669
}
70+
return null
71+
}
72+
def aabFile = aabFileProvider.flatMap { file ->
73+
file ? project.layout.file(project.provider { file }) : project.objects.fileProperty()
10774
}
108-
}
109-
}
110-
111-
private void upload(file, urls, gitBranch, gitTags, gitCommit, gitUrl, whatsNew) {
112-
if (urls == null || urls.isEmpty()) {
113-
throw new GradleException(
114-
'There was no url provided for this buildVariant. Please check for typos.'
115-
)
116-
}
117-
118-
if (urls instanceof String) {
119-
println("--------------------------------------")
120-
println("Url was not wrapped in array. Doing it for you. :)")
121-
println("url --> [url]")
122-
println("--------------------------------------")
123-
urls = [urls]
124-
}
12575

126-
for (String url in urls) {
127-
//Build and execute of the curl command for Updraft upload
128-
List<String> curlArgs = [
129-
'-X', 'PUT',
130-
'-F', "app=@${file}",
131-
'-F', "build_type=Gradle",
132-
gitBranch,
133-
gitUrl,
134-
gitTags,
135-
gitCommit,
136-
whatsNew,
137-
url
138-
].findAll { it != '' } // Filter out empty strings
139-
140-
new ByteArrayOutputStream().withStream { os ->
141-
execOps.exec {
142-
executable 'curl'
143-
args curlArgs
144-
standardOutput os
76+
// Registers a task for every available build variant / flavor
77+
project.tasks.register("updraft${variantNameCapitalized}", UpdraftTask) {
78+
outputFile.set(apkFile)
79+
isBundle.set(false)
80+
basePath.set(projectBasePath)
81+
currentVariantName.set(variantName)
82+
urls.set(uploadUrls)
83+
gitBranch.set(gitBranchProvider)
84+
gitTags.set(gitTagsProvider)
85+
gitCommit.set(gitCommitProvider)
86+
gitUrl.set(gitUrlProvider)
87+
releaseNotes.set(releaseNotesProvider)
88+
89+
doFirst {
90+
def outputFile = apkFile.getOrNull()?.asFile
91+
if (outputFile == null || !outputFile.exists()) {
92+
throw new GradleException("Could not find a build artifact. (Make sure to run assemble${variantNameCapitalized} task first)")
93+
}
14594
}
95+
}
14696

147-
def execResponse = new JsonSlurperClassic().parseText(os.toString())
148-
149-
if (execResponse instanceof HashMap && execResponse.size() > 0) {
150-
if (execResponse.containsKey("success") && execResponse["success"] == "ok") {
151-
def publicUrl = execResponse["public_link"]
152-
ok(publicUrl)
153-
} else if (execResponse.containsKey("detail") && execResponse["detail"] == "Not found.") {
154-
throw new GradleException('Could not updraft to the given url. Please recheck that.')
155-
} else {
156-
throw new GradleException(os.toString())
97+
// Registers a task for every available build variant / flavor
98+
project.tasks.register("updraftBundle${variantNameCapitalized}", UpdraftTask) {
99+
outputFile.set(aabFile)
100+
isBundle.set(true)
101+
basePath.set(projectBasePath)
102+
currentVariantName.set(variantName)
103+
urls.set(uploadUrls)
104+
gitBranch.set(gitBranchProvider)
105+
gitTags.set(gitTagsProvider)
106+
gitCommit.set(gitCommitProvider)
107+
gitUrl.set(gitUrlProvider)
108+
releaseNotes.set(releaseNotesProvider)
109+
110+
doFirst {
111+
def outputFile = aabFile.getOrNull()?.asFile
112+
if (outputFile == null || !outputFile.exists()) {
113+
throw new GradleException("Could not find a build artifact. (Make sure to run bundle${variantNameCapitalized} task first)")
157114
}
158-
} else {
159-
println(execResponse)
160-
ok(null)
161115
}
162116
}
163117
}
@@ -198,22 +152,4 @@ class UpdraftPlugin implements Plugin<Project> {
198152
}
199153
}
200154
}
201-
202-
private static void ok(String publicUrl) {
203-
println()
204-
println("--------------------------------------")
205-
println("Your App was successfully updrafted!")
206-
if (publicUrl != null) {
207-
println("Get it here -> $publicUrl")
208-
}
209-
println("--------------------------------------")
210-
}
211-
212-
private static String createCurlParam(String text, String name) {
213-
if (text.isBlank() || text.isEmpty()) {
214-
""
215-
} else {
216-
"-F ${name}=${text} "
217-
}
218-
}
219155
}

0 commit comments

Comments
 (0)