diff --git a/main.go b/main.go index dd93715..969a3df 100644 --- a/main.go +++ b/main.go @@ -38,21 +38,55 @@ type ConfigsModel struct { JarsignerOptions string } +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) { + list = strings.TrimSpace(list) + if len(list) == 0 { + return nil + } + + 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 +} + func createConfigsModelFromEnvs() ConfigsModel { - return ConfigsModel{ - BuildArtifactPath: os.Getenv("apk_path"), + cfg := ConfigsModel{ + BuildArtifactPath: os.Getenv("android_app"), KeystoreURL: os.Getenv("keystore_url"), KeystorePassword: os.Getenv("keystore_password"), KeystoreAlias: os.Getenv("keystore_alias"), PrivateKeyPassword: os.Getenv("private_key_password"), JarsignerOptions: os.Getenv("jarsigner_options"), } + + if val := os.Getenv("apk_path"); val != "" { + log.Warnf("step input 'APK file path' (apk_path) is deprecated and will be removed on 20 August 2019, use 'APK or App Bundle file path' (android_app) instead!") + cfg.BuildArtifactPath = val + } + + return cfg } func (configs ConfigsModel) print() { fmt.Println() log.Infof("Configs:") - log.Printf(" - ApkPath: %s", configs.BuildArtifactPath) + log.Printf(" - BuildArtifactPath: %s", configs.BuildArtifactPath) log.Printf(" - KeystoreURL: %s", secureInput(configs.KeystoreURL)) log.Printf(" - KeystorePassword: %s", secureInput(configs.KeystorePassword)) log.Printf(" - KeystoreAlias: %s", configs.KeystoreAlias) @@ -64,15 +98,15 @@ func (configs ConfigsModel) print() { func (configs ConfigsModel) validate() error { // required if configs.BuildArtifactPath == "" { - return errors.New("no ApkPath parameter specified") + return errors.New("no BuildArtifactPath parameter specified") } - buildArtifactPaths := strings.Split(configs.BuildArtifactPath, "|") + buildArtifactPaths := parseAppList(configs.BuildArtifactPath) for _, buildArtifactPath := range buildArtifactPaths { if exist, err := pathutil.IsPathExists(buildArtifactPath); err != nil { - return fmt.Errorf("failed to check if ApkPath exist at: %s, error: %s", buildArtifactPath, err) + return fmt.Errorf("failed to check if BuildArtifactPath exist at: %s, error: %s", buildArtifactPath, err) } else if !exist { - return fmt.Errorf("ApkPath not exist at: %s", buildArtifactPath) + return fmt.Errorf("BuildArtifactPath not exist at: %s", buildArtifactPath) } } @@ -342,8 +376,9 @@ func main() { // --- // Sign build artifacts - buildArtifactPaths := strings.Split(configs.BuildArtifactPath, "|") - signedBuildArtifactPaths := make([]string, len(buildArtifactPaths)) + buildArtifactPaths := parseAppList(configs.BuildArtifactPath) + signedAPKPaths := make([]string, 0) + signedAABPaths := make([]string, 0) log.Infof("signing %d Build Artifacts", len(buildArtifactPaths)) fmt.Println() @@ -395,23 +430,41 @@ func main() { log.Infof("Zipalign Build Artifact") signedArtifactName := fmt.Sprintf("%s-bitrise-signed%s", buildArtifactBasename, artifactExt) - signedBuildArtifactPaths[i] = filepath.Join(buildArtifactDir, signedArtifactName) - if err := zipalignBuildArtifact(zipalign, unalignedBuildArtifactPth, signedBuildArtifactPaths[i]); err != nil { + fullPath := filepath.Join(buildArtifactDir, signedArtifactName) + + if artifactExt == ".aab" { + signedAABPaths = append(signedAABPaths, fullPath) + } else { + signedAPKPaths = append(signedAPKPaths, fullPath) + } + + if err := zipalignBuildArtifact(zipalign, unalignedBuildArtifactPth, fullPath); err != nil { failf("Failed to zipalign Build Artifact, error: %s", err) } fmt.Println() // --- } - signedBuildArtifactPth := strings.Join(signedBuildArtifactPaths, "|") + joinedAPKOutputPaths := strings.Join(signedAPKPaths, "|") + joinedAABOutputPaths := strings.Join(signedAABPaths, "|") + + if err := tools.ExportEnvironmentWithEnvman("BITRISE_SIGNED_APK_PATH", joinedAPKOutputPaths); err != nil { + log.Warnf("Failed to export Build Artifact, error: %s", err) + } + log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_SIGNED_APK_PATH (value: %s)", joinedAPKOutputPaths) + + if err := tools.ExportEnvironmentWithEnvman("BITRISE_APK_PATH", joinedAPKOutputPaths); err != nil { + log.Warnf("Failed to export Build Artifact, error: %s", err) + } + log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_APK_PATH (value: %s)", joinedAPKOutputPaths) - if err := tools.ExportEnvironmentWithEnvman("BITRISE_SIGNED_APK_PATH", signedBuildArtifactPth); err != nil { + if err := tools.ExportEnvironmentWithEnvman("BITRISE_SIGNED_AAB_PATH", joinedAABOutputPaths); err != nil { log.Warnf("Failed to export Build Artifact, error: %s", err) } - log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_SIGNED_APK_PATH (value: %s)", signedBuildArtifactPth) + log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_SIGNED_AAB_PATH (value: %s)", joinedAABOutputPaths) - if err := tools.ExportEnvironmentWithEnvman("BITRISE_APK_PATH", signedBuildArtifactPth); err != nil { + if err := tools.ExportEnvironmentWithEnvman("BITRISE_AAB_PATH", joinedAABOutputPaths); err != nil { log.Warnf("Failed to export Build Artifact, error: %s", err) } - log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_APK_PATH (value: %s)", signedBuildArtifactPth) + log.Donef("The Signed Build Artifact path is now available in the Environment Variable: BITRISE_AAB_PATH (value: %s)", joinedAABOutputPaths) } diff --git a/step.yml b/step.yml index 2af7c15..1875824 100644 --- a/step.yml +++ b/step.yml @@ -1,5 +1,5 @@ -title: "Sign APK" -summary: Sign APK +title: "Android Sign" +summary: Android Sign description: With this step, you can digitally sign your app's APK file in your workflow. All you have to do is upload your keystore file in the Code signing tab of the Workflow Editor. @@ -30,9 +30,31 @@ toolkit: go: package_name: github.com/bitrise-steplib/steps-sign-apk inputs: - - apk_path: "$BITRISE_APK_PATH" + - apk_path: opts: - title: "Build artifact path." + title: "[DEPRECATED] Build artifact path." + category: Deprecated + summary: "`Android App Bundle (.aab)` or `Android Aplication Package (.apk)`. Deprecated, use `android_app` instead." + description: |- + __This input is deprecated and will be removed on 20 August 2019, use `App file path` input instead!__ + + Path(s) to the build artifact file to sign (`.aab` or `.apk`). + + You can provide multiple build artifact file paths separated by `|` character. + + Deprecated, use `android_app` instead. + + 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/app.aab` + - `/path/to/my/app1.aab|/path/to/my/app2.apk|/path/to/my/app3.aab` + is_required: true + - android_app: "$BITRISE_APK_PATH\n$BITRISE_AAB_PATH" + opts: + title: "App file path." summary: "`Android App Bundle (.aab)` or `Android Aplication Package (.apk)`" description: |- Path(s) to the build artifact file to sign (`.aab` or `.apk`). @@ -87,7 +109,29 @@ inputs: outputs: - BITRISE_SIGNED_APK_PATH: opts: - title: "Bitrise signed build artifact path" + title: "Path of the signed APK" + summary: "Path of the signed APK" + description: |- + This output will include the path(s) of the signed APK(s). + If multiple APKs are provided for signing the output paths are separated with `|` character, for example, `app-armeabi-v7a-debug.apk|app-mips-debug.apk|app-x86-debug.apk` - BITRISE_APK_PATH: opts: - title: "Bitrise signed build artifact path" + title: "Path of the signed APK" + summary: "Path of the signed APK" + description: |- + This output will include the path(s) of the signed APK(s). + If multiple APKs are provided for signing the output paths are separated with `|` character, for example, `app-armeabi-v7a-debug.apk|app-mips-debug.apk|app-x86-debug.apk` +- BITRISE_SIGNED_AAB_PATH: + opts: + title: "Path of the signed AAB" + summary: "Path of the signed AAB" + description: |- + This output will include the path(s) of the signed AAB(s). + If multiple AABs are provided for signing the output paths are separated with `|` character, for example, `app-armeabi-v7a-debug.aab|app-mips-debug.aab|app-x86-debug.aab` +- BITRISE_AAB_PATH: + opts: + title: "Path of the signed AAB" + summary: "Path of the signed AAB" + description: |- + This output will include the path(s) of the signed AAB(s). + If multiple AABs are provided for signing the output paths are separated with `|` character, for example, `app-armeabi-v7a-debug.aab|app-mips-debug.aab|app-x86-debug.aab`