diff --git a/bitrise.yml b/bitrise.yml index 0586dea0..c35429f7 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -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: @@ -131,6 +131,7 @@ workflows: - package_name: $PACKAGE_NAME - apk_path: $BITRISE_SIGNED_APK_PATH - track: $TRACK + - mapping_file: "" dep-update: steps: diff --git a/config.go b/config.go index a4845eb6..fbb5f795 100644 --- a/config.go +++ b/config.go @@ -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 @@ -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 diff --git a/config_test.go b/config_test.go new file mode 100644 index 00000000..add0e31f --- /dev/null +++ b/config_test.go @@ -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) + } + }) + } +} diff --git a/step.yml b/step.yml index df7d3642..2b22a302 100644 --- a/step.yml +++ b/step.yml @@ -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. @@ -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.