Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
expansion file upload and custom track names (#41)
* ndk fix

* debugging

* convert value options list for track input to a custom editable field

* added option to upload obb files

* fix of expansion file upload

* PR fixes
  • Loading branch information
trapacska committed Aug 1, 2018
1 parent 0ea8ba8 commit 9f3352d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
10 changes: 10 additions & 0 deletions bitrise.yml
Expand Up @@ -36,6 +36,16 @@ workflows:
#!/usr/bin/env bash
set -ex
rm -rf ./_tmp
if [ ! -d "$ANDROID_HOME/ndk-bundle/toolchains/mips64el-linux-android-4.9" ]
then
curl "https://dl.google.com/android/repository/android-ndk-r16b-darwin-x86_64.zip" -o /tmp/ndk.zip
rm -rf $ANDROID_HOME/ndk-bundle
unzip -q /tmp/ndk.zip -d $ANDROID_HOME/
mv $ANDROID_HOME/android-ndk-r16b $ANDROID_HOME/ndk-bundle
rm -rf /tmp/ndk.zip
envman add --key "ANDROID_NDK_HOME" --value "$ANDROID_HOME/ndk-bundle"
fi
- change-workdir:
title: Switch working dir to test/_tmp dir
run_if: true
Expand Down
39 changes: 39 additions & 0 deletions main.go
Expand Up @@ -42,6 +42,7 @@ type ConfigsModel struct {
JSONKeyPath string
PackageName string
ApkPath string
ExpansionfilePath string
Track string
UserFraction string
WhatsnewsDir string
Expand All @@ -54,6 +55,7 @@ func createConfigsModelFromEnvs() ConfigsModel {
JSONKeyPath: os.Getenv("service_account_json_key_path"),
PackageName: os.Getenv("package_name"),
ApkPath: os.Getenv("apk_path"),
ExpansionfilePath: os.Getenv("expansionfile_path"),
Track: os.Getenv("track"),
UserFraction: os.Getenv("user_fraction"),
WhatsnewsDir: os.Getenv("whatsnews_dir"),
Expand Down Expand Up @@ -114,6 +116,7 @@ func (configs ConfigsModel) print() {
log.Printf("- JSONKeyPath: %s", secureInput(configs.JSONKeyPath))
log.Printf("- PackageName: %s", configs.PackageName)
log.Printf("- ApkPath: %s", configs.ApkPath)
log.Printf("- ExpansionfilePath: %s", configs.ExpansionfilePath)
log.Printf("- Track: %s", configs.Track)
log.Printf("- UserFraction: %s", configs.UserFraction)
log.Printf("- WhatsnewsDir: %s", configs.WhatsnewsDir)
Expand Down Expand Up @@ -383,6 +386,14 @@ func main() {
versionCodes := []int64{}
apkPaths := strings.Split(configs.ApkPath, "|")

// "main:/file/path/1.obb|patch:/file/path/2.obb"
expansionfileUpload := strings.TrimSpace(configs.ExpansionfilePath) != ""
expansionfilePaths := strings.Split(configs.ExpansionfilePath, "|")

if expansionfileUpload && (len(apkPaths) != len(expansionfilePaths)) {
failf("Mismatching number of APKs(%d) and Expansionfiles(%d)", len(apkPaths), len(expansionfilePaths))
}

for i, apkPath := range apkPaths {
versionCode := int64(0)
apkFile, err := os.Open(apkPath)
Expand Down Expand Up @@ -417,6 +428,34 @@ func main() {
log.Printf(" uploaded apk version: %d", apk.VersionCode)
versionCodes = append(versionCodes, apk.VersionCode)
versionCode = apk.VersionCode

if expansionfileUpload {
// "main:/file/path/1.obb"
cleanExpfilePath := strings.TrimSpace(expansionfilePaths[i])
if !strings.HasPrefix(cleanExpfilePath, "main:") && !strings.HasPrefix(cleanExpfilePath, "patch:") {
failf("Invalid expansion file config: %s", expansionfilePaths[i])
}

// [0]: "main" [1]:"/file/path/1.obb"
expansionfilePathSplit := strings.Split(cleanExpfilePath, ":")

// "main"
expfileType := strings.TrimSpace(expansionfilePathSplit[0])

// "/file/path/1.obb"
expfilePth := strings.TrimSpace(strings.Join(expansionfilePathSplit[1:], ""))

expansionFile, err := os.Open(expfilePth)
if err != nil {
failf("Failed to read expansion file (%s), error: %s", expansionFile, err)
}
editsExpansionfilesService := androidpublisher.NewEditsExpansionfilesService(service)
editsExpansionfilesCall := editsExpansionfilesService.Upload(configs.PackageName, appEdit.Id, versionCode, expfileType)
editsExpansionfilesCall.Media(expansionFile, googleapi.ContentType("application/vnd.android.package-archive"))
if _, err := editsExpansionfilesCall.Do(); err != nil {
failf("Failed to upload expansion file, error: %s", err)
}
}
}

// Upload mapping.txt
Expand Down
30 changes: 22 additions & 8 deletions step.yml
Expand Up @@ -74,23 +74,37 @@ inputs:
You can provide multiple APK paths separated by `|` character.
Format emxamples:
Format examples:
- `/path/to/my/app.apk`
- `/path/to/my/app1.apk|/path/to/my/app2.apk|/path/to/my/app3.apk`
- `/path/to/my/bundle.aab`
is_required: true
- expansionfile_path: ""
opts:
title: Expansion file Path
description: |-
Path to the expansion file.
Leave empty or provide exactly the same number of paths as in apk_path, separated by `|` character and start each path with the expansion file's type
separated by a `:`. (main, patch)
Format examples:
- `main:/path/to/my/app.obb`
- `patch:/path/to/my/app1.obb|main:/path/to/my/app2.obb|main:/path/to/my/app3.obb`
- track: alpha
opts:
title: Track
summary: The track in which you want to assign the uploaded APK(s).
description: |-
Track to assign the APK(s).
value_options:
- internal
- alpha
- beta
- rollout
- production
The track in which you want to assign the uploaded APK(s).
Can be one of the built-in tracks: internal, alpha, beta, rollout, production.
Or you can set your custom track name as well.
For example: `pre-release`, or any of your closed track you added in Google Play Developer Console.
is_required: true
- user_fraction: "0.5"
opts:
Expand Down

0 comments on commit 9f3352d

Please sign in to comment.