Skip to content

Commit 6b96a4b

Browse files
authored
Merge pull request #804 from DroidKaigi/travis/auto_publish
Use Travis to publish an apk to alpha track
2 parents af22382 + c7bcd4f commit 6b96a4b

File tree

15 files changed

+350
-5
lines changed

15 files changed

+350
-5
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ matrix:
3636
- openssl aes-256-cbc -K $encrypted_1701aaafcc71_key -iv $encrypted_1701aaafcc71_iv
3737
-in .travis/android/release.zip.enc -out release.zip -d
3838
- "./.travis/android/before_install.bash"
39-
script: ".travis/android/run.bash"
39+
script:
40+
- ".travis/android/run.bash"
41+
- ".travis/android/release_to_alpha.bash"
4042
# - language: objective-c
4143
# os: osx
4244
# osx_image: xcode10.1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
die() {
6+
echo "$*" 1>&2
7+
exit 1
8+
}
9+
10+
source "$(dirname $0)/../bash.source"
11+
12+
source .release/bash.source
13+
14+
./gradlew promoteProduction -PeditId="$1"

.travis/android/release.zip.enc

1.81 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
if [[ -z "${TRAVIS_TAG:-}" ]]; then
6+
exit 0
7+
fi
8+
9+
die() {
10+
echo "$*" 1>&2
11+
exit 1
12+
}
13+
14+
source "$(dirname $0)/../bash.source"
15+
16+
source .release/bash.source
17+
18+
if [[ ! -d ".transart" ]]; then
19+
transart -f .travis/android/to_github.transart.yml download
20+
fi
21+
22+
./gradlew publishAlpha

build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import com.android.build.gradle.AppPlugin
22
import com.android.build.gradle.LibraryPlugin
33
import dependencies.Dep
4+
import dependencies.Packages
5+
import publish.DistributionTrack
6+
import publish.EditStatus
7+
import publish.PromoteApk
8+
import publish.UploadApk
49

510
apply from: file('gradle/dependencyGraph.gradle')
611

@@ -190,3 +195,44 @@ task dependencyReport {
190195
file << "}\n"
191196
}
192197
}
198+
199+
task publishAlpha {
200+
doLast {
201+
def uploadApk = new UploadApk(logger)
202+
203+
def apkFile = new File(System.getenv("UNIVERSAL_APK_PATH"))
204+
// FIXME more flexible
205+
def mappingFile = new File(rootProject.projectDir, ".transart/mapping.txt")
206+
207+
uploadApk.execute(
208+
Packages.name,
209+
rootProject.file(".release/service-account.json"),
210+
apkFile,
211+
mappingFile,
212+
DistributionTrack.Alpha.INSTANCE,
213+
"New Alpha Release",
214+
EditStatus.Completed.INSTANCE,
215+
[
216+
"en-US": rootProject.file("publish/release-notes/en-US/default.txt"),
217+
"ja-JP": rootProject.file("publish/release-notes/ja-JP/default.txt")
218+
]
219+
)
220+
}
221+
}
222+
223+
task promoteProduction {
224+
doLast {
225+
def promoteApk = new PromoteApk(logger)
226+
def editId = project.property("editId")
227+
228+
if (!editId) {
229+
throw new GradleScriptException("editId must be privided")
230+
}
231+
232+
promoteApk.execute(
233+
Packages.name,
234+
rootProject.file(".release/service-account.json"),
235+
editId
236+
)
237+
}
238+
}

buildSrc/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath("com.google.apis:google-api-services-androidpublisher:v3-rev46-1.25.0")
7+
classpath("com.google.api-client:google-api-client:1.28.0")
8+
}
9+
}
10+
111
plugins {
212
`kotlin-dsl`
313
}
414
repositories {
515
jcenter()
616
}
17+
18+
dependencies {
19+
implementation("com.google.guava:guava:26.0-jre")
20+
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev46-1.25.0") {
21+
exclude(group = "com.google.guava", module = "guava")
22+
}
23+
implementation("com.google.api-client:google-api-client:1.28.0") {
24+
exclude(group = "com.google.guava", module = "guava")
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dependencies
2+
3+
object Packages {
4+
const val name = "io.github.droidkaigi.confsched2019"
5+
const val debugNameSuffix = ".debug"
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package publish
2+
3+
sealed class DistributionTrack {
4+
abstract val name: String
5+
6+
object Internal : DistributionTrack() {
7+
override val name: String = "internal"
8+
}
9+
10+
object Alpha : DistributionTrack() {
11+
override val name: String = "alpha"
12+
}
13+
14+
object Beta : DistributionTrack() {
15+
override val name: String = "beta"
16+
}
17+
18+
object Production : DistributionTrack() {
19+
override val name: String = "production"
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package publish
2+
3+
sealed class EditStatus {
4+
abstract val status: String
5+
6+
object InProgress : EditStatus() {
7+
override val status: String = "inProgress"
8+
}
9+
10+
object Draft : EditStatus() {
11+
override val status: String = "draft"
12+
}
13+
14+
object Completed : EditStatus() {
15+
override val status: String = "completed"
16+
}
17+
18+
object Halted : EditStatus() {
19+
override val status: String = "halted"
20+
}
21+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package publish
2+
3+
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
4+
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
5+
import com.google.api.client.json.jackson2.JacksonFactory
6+
import com.google.api.services.androidpublisher.AndroidPublisher
7+
import com.google.api.services.androidpublisher.AndroidPublisherScopes
8+
import java.io.File
9+
10+
fun androidPublisher(packageName: String, serviceAccountJson: File): AndroidPublisher {
11+
val credential = serviceAccountJson.asCredential()
12+
13+
return AndroidPublisher.Builder(
14+
GoogleNetHttpTransport.newTrustedTransport(),
15+
JacksonFactory.getDefaultInstance(),
16+
credential
17+
)
18+
.setApplicationName(packageName)
19+
.build()
20+
}
21+
22+
fun File.asCredential(): GoogleCredential {
23+
if (!exists()) {
24+
error("$this does not exist")
25+
}
26+
27+
return inputStream().use { credentialStream ->
28+
GoogleCredential.fromStream(credentialStream)
29+
.createScoped(
30+
listOf(AndroidPublisherScopes.ANDROIDPUBLISHER)
31+
)
32+
}
33+
}
34+
35+
fun AndroidPublisher.Edits.runInTransaction(
36+
packageName: String,
37+
editId: String = insert(packageName, null).execute().id,
38+
action: (editId: String) -> Unit = {},
39+
errorHandler: (error: Throwable) -> Unit = {}
40+
) {
41+
try {
42+
action(editId)
43+
44+
commit(packageName, editId).execute()
45+
} catch (th: Throwable) {
46+
errorHandler(th)
47+
}
48+
}
49+

0 commit comments

Comments
 (0)