Skip to content

Commit

Permalink
input deprecation & handle pipe and newline separated app lists (#52)
Browse files Browse the repository at this point in the history
* input deprecation & handle pipe and newline separated app lists

* PR fix

* clear mapping file

* PR fix

* test update

* app parsing fix and tests

* app path split fix
  • Loading branch information
godrei authored May 23, 2019
1 parent 393a287 commit 9ecdcda
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 10 deletions.
7 changes: 4 additions & 3 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ workflows:
inputs:
- build_gradle_path: ./app/build.gradle
- new_version_code: $BITRISE_BUILD_NUMBER
- android-build:
- gradle-runner:
inputs:
- gradle_task: bundleRelease
- gradlew_path: ./gradlew
- sign-apk:
inputs:
- apk_path: $BITRISE_APK_PATH
- apk_path: $BITRISE_AAB_PATH
- path::./:
title: Step Test
inputs:
- service_account_json_key_path: $BITRISEIO_JSON_KEY_URL
- package_name: $PACKAGE_NAME
- app_path: $BITRISE_SIGNED_APK_PATH
## - app_path: $BITRISE_APK_PATH\n$BITRISE_AAB_PATH
- track: $TRACK

apk_deploy_test:
Expand Down Expand Up @@ -131,6 +131,7 @@ workflows:
- package_name: $PACKAGE_NAME
- apk_path: $BITRISE_SIGNED_APK_PATH
- track: $TRACK
- mapping_file: ""

dep-update:
steps:
Expand Down
27 changes: 21 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,28 @@ func parseAPKList(list string) []string {
return strings.Split(list, "|")
}

func splitElements(list []string, sep string) (s []string) {
for _, e := range list {
s = append(s, strings.Split(e, sep)...)
}
return
}

func parseAppList(list string) (apps []string) {
for _, app := range strings.Split(list, "\n") {
apps = append(apps, strings.TrimSpace(app))
list = strings.TrimSpace(list)
if len(list) == 0 {
return nil
}
if len(apps) == 0 {
for _, app := range strings.Split(list, "|") {
apps = append(apps, strings.TrimSpace(app))

s := []string{list}
for _, sep := range []string{"\n", `\n`, "|"} {
s = splitElements(s, sep)
}

for _, app := range s {
app = strings.TrimSpace(app)
if len(app) > 0 {
apps = append(apps, app)
}
}
return
Expand Down Expand Up @@ -131,7 +146,7 @@ func (c Configs) appPaths() ([]string, []string) {
}

if len(aabs) > 0 {
return aabs[:0], warnings
return aabs[:1], warnings
}

return apks, warnings
Expand Down
118 changes: 118 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"reflect"
"testing"
)

func Test_parseAppList(t *testing.T) {
tests := []struct {
name string
list string
wantApps []string
}{
{
name: "empty app list",
list: "",
wantApps: nil,
},
{
name: "newline separated list",
list: "app.apk\napp.aab\n \n",
wantApps: []string{"app.apk", "app.aab"},
},
{
name: "pipe separated list",
list: "|app.apk|app.aab|",
wantApps: []string{"app.apk", "app.aab"},
},
{
name: "pipe and newline separated list",
list: "\napp1.apk|app2.apk\napp.aab|",
wantApps: []string{"app1.apk", "app2.apk", "app.aab"},
},
{
name: "pipe and newline separated list",
list: "/bitrise/deploy/app-bitrise-signed.aab\n/bitrise/deploy/app.aab",
wantApps: []string{"/bitrise/deploy/app-bitrise-signed.aab", "/bitrise/deploy/app.aab"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotApps := parseAppList(tt.list); !reflect.DeepEqual(gotApps, tt.wantApps) {
t.Errorf("parseAppList() = %v, want %v", gotApps, tt.wantApps)
}
})
}
}

func TestConfigs_appPaths(t *testing.T) {
tests := []struct {
name string
config Configs
wantApps []string
wantWarnings []string
}{
{
name: "empty test",
config: Configs{
AppPath: "",
ApkPath: "",
},
wantApps: nil,
wantWarnings: nil,
},
{
name: "prefers aab",
config: Configs{
AppPath: "app.apk|app.aab",
},
wantApps: []string{"app.aab"},
wantWarnings: []string{"Both .aab and .apk files provided, using the .aab file(s): app.aab"},
},
{
name: "uses deprecated input (ApkPath) if set",
config: Configs{
AppPath: "app.aab",
ApkPath: "app.apk",
},
wantApps: []string{"app.apk"},
wantWarnings: []string{"step input 'APK file path' (apk_path) is deprecated and will be removed on 20 August 2019, use 'APK or App Bundle file path' (app_path) instead!"},
},
{
name: "uses first aab",
config: Configs{
AppPath: "app.aab\napp1.aab",
},
wantApps: []string{"app.aab"},
wantWarnings: []string{"More than 1 .aab files provided, using the first: app.aab"},
},
{
name: "unknown extension",
config: Configs{
AppPath: "mapping.txt",
},
wantApps: nil,
wantWarnings: []string{"unknown app path extension in path: mapping.txt, supported extensions: .apk, .aab"},
},
{
name: "newline (\n) as a character",
config: Configs{
AppPath: `/bitrise/deploy/app-bitrise-signed.aab\n/bitrise/deploy/app.aab`,
},
wantApps: []string{"/bitrise/deploy/app-bitrise-signed.aab"},
wantWarnings: []string{"More than 1 .aab files provided, using the first: /bitrise/deploy/app-bitrise-signed.aab"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotApps, gotWarnings := tt.config.appPaths()
if !reflect.DeepEqual(gotApps, tt.wantApps) {
t.Errorf("Configs.appPaths() gotApps = %v, want %v", gotApps, tt.wantApps)
}
if !reflect.DeepEqual(gotWarnings, tt.wantWarnings) {
t.Errorf("Configs.appPaths() gotWarnings = %v, want %v", gotWarnings, tt.wantWarnings)
}
})
}
}
4 changes: 3 additions & 1 deletion step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ inputs:
is_required: true
- app_path: $BITRISE_APK_PATH\n$BITRISE_AAB_PATH
opts:
title: App file path.
title: App file path
description: |-
Path to the App Bundle or APK file(s) to deploy.
Expand Down Expand Up @@ -171,6 +171,8 @@ inputs:
opts:
title: APK file path
description: |-
__This input is deprecated and will be removed on 20 August 2019, use `App file path` input instead!__
Path to the APK to deploy.
You can provide multiple APK paths separated by `|` character.
Expand Down

0 comments on commit 9ecdcda

Please sign in to comment.