Skip to content

Commit

Permalink
Rename input and step (#39)
Browse files Browse the repository at this point in the history
* rename input

* use apk_path if present

* rename step

* fix: compile error

* fix: use prior separator for compatibility

* fix: filter non empty paths

* fix: signed artifact not found

* fix: error when input value contains newline

* refactor: useless code after fix

* refactor: prepare next commit

* refactor: prepare next commit

* collect signed apks in separate var

* collect signed aabs in separate var

* default to original behavior

* export aabs to separate env var

* refactor: consistent naming

* properly deprecate input instead of removal

* go fmt

* fix: signed path slice lengths no longer known

* pr fix: use consistent deprecation warning

* pr fix: reuse tested app list parsing logic

* pr fix: simple if instead of switch

* pr fix: consistent input depraction

* fix: missing value after removing default

* refactor: useless code

* pr fix: missing dot from extension matching

* pr fix: clarify step output usages

* revert: accidentally change

* pr fix: consolidate step output defs

* pr fix: fixup wording
  • Loading branch information
lszucs authored and godrei committed May 31, 2019
1 parent 80363a9 commit 8b297cc
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 22 deletions.
85 changes: 69 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
56 changes: 50 additions & 6 deletions step.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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`).
Expand Down Expand Up @@ -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`

0 comments on commit 8b297cc

Please sign in to comment.