Skip to content

Commit

Permalink
TOOL-2120 Add aab support (#42)
Browse files Browse the repository at this point in the history
* add support for android bundle artifacts aab

* fixup! add support for android bundle artifacts aab

* Fix output check logic, typo fix

* Remove dead code

* Adding e2e test for Android bundle generation.

Co-authored-by: Juan Ignacio Donoso <jidonoso@gmail.com>
  • Loading branch information
lpusok and blackjid committed May 28, 2020
1 parent c50d992 commit 4e18940
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 13 deletions.
20 changes: 18 additions & 2 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ workflows:
cordova platform rm ios
cordova platform add ios
cordova platform remove android
cordova platform add android@7.X.X
cordova platform add android@8.X.X
envman unset --key ANDROID_NDK_HOME
- yarn:
Expand All @@ -95,7 +95,6 @@ workflows:
- path::./:
title: Cordova archive
inputs:
- options: --buildFlag="-UseModernBuildSystem=0"
- target: emulator
# - cordova_version: latest
- run_cordova_prepare: ${RUN_PREPARE_IN_ARCHIVE}
Expand All @@ -120,6 +119,23 @@ workflows:
echo "Does not exist: apk file's path"
exit 1
fi
- path::./:
title: Cordova archive android bubdle
inputs:
- platform: android
- options: -- --packageType="bundle"
- target: emulator
- cordova_version:
- run_cordova_prepare: ${RUN_PREPARE_IN_ARCHIVE}
- script:
title: Output test
inputs:
- content: |
#!/usr/bin/env bash
if [[ ! -e "$BITRISE_AAB_PATH" ]]; then
echo "Does not exist: aab file's path"
exit 1
fi
- change-workdir:
title: Change back to original working directory
inputs:
Expand Down
29 changes: 22 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
dsymZipPathEnvKey = "BITRISE_DSYM_PATH"

apkPathEnvKey = "BITRISE_APK_PATH"
aabPathEnvKey = "BITRISE_AAB_PATH"
)

type config struct {
Expand Down Expand Up @@ -145,10 +146,12 @@ func findArtifact(rootDir, ext string, buildStart time.Time) ([]string, error) {
return matches, nil
}

func checkBuildProducts(apks []string, apps []string, ipas []string, platforms []string, target string) error {
func checkBuildProducts(apks []string, aabs []string, apps []string, ipas []string, platforms []string, target string) error {
// if android in platforms
if len(apks) == 0 && sliceutil.IsStringInSlice("android", platforms) {
return errors.New("No apk generated")
if sliceutil.IsStringInSlice("android", platforms) {
if len(apks) == 0 && len(aabs) == 0 {
return errors.New("no apk or aab generated")
}
}
// if ios in platforms
if sliceutil.IsStringInSlice("ios", platforms) {
Expand Down Expand Up @@ -208,8 +211,6 @@ func main() {
if configs.CordovaVersion != "" {
log.Printf("\n")
log.Infof("Updating cordova version to: %s", configs.CordovaVersion)
packageName := "cordova"
packageName += "@" + configs.CordovaVersion

packageManager, err := jsdependency.DetectTool(workDir)
if err != nil {
Expand Down Expand Up @@ -361,11 +362,12 @@ func main() {
}
}

var apks []string
var apks, aabs []string
androidOutputDirExist := false
// examples for apk paths:
// PROJECT_ROOT/platforms/android/app/build/outputs/apk/debug/app-debug.apk
// PROJECT_ROOT/platforms/android/build/outputs/apk/debug/app-debug.apk
// PROJECT_ROOT/platforms/android/build/outputs/bundle/release/app.aab
androidOutputDir := filepath.Join(workDir, "platforms", "android")
if exist, err := pathutil.IsDirExists(androidOutputDir); err != nil {
fail("Failed to check if dir (%s) exist, error: %s", androidOutputDir, err)
Expand All @@ -387,14 +389,27 @@ func main() {
log.Donef("The apk path is now available in the Environment Variable: %s (value: %s)", apkPathEnvKey, exportedPth)
}
}

aabs, err = findArtifact(androidOutputDir, "aab", compileStart)
if err != nil {
fail("Failed to find aab in dir (%s), error: %s", androidOutputDir, err)
}

if len(aabs) > 0 {
if exportedPth, err := moveAndExportOutputs(aabs, configs.DeployDir, aabPathEnvKey, false); err != nil {
fail("Failed to export aabs, error: %s", err)
} else {
log.Donef("The aab path is now available in the Environment Variable: %s (value: %s)", aabPathEnvKey, exportedPth)
}
}
}

if !iosOutputDirExist && !androidOutputDirExist {
log.Warnf("No ios nor android platform's output dir exist")
fail("No output generated")
}

if err := checkBuildProducts(apks, apps, ipas, platforms, configs.Target); err != nil {
if err := checkBuildProducts(apks, aabs, apps, ipas, platforms, configs.Target); err != nil {
fail("Build outputs missing: %s", err)
}

Expand Down
50 changes: 47 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "testing"
func Test_checkBuildProducts(t *testing.T) {
type args struct {
apks []string
aabs []string
apps []string
ipas []string
platforms []string
Expand All @@ -21,6 +22,7 @@ func Test_checkBuildProducts(t *testing.T) {
[]string{},
[]string{},
[]string{},
[]string{},
[]string{"ios", "android"},
"emulator",
},
Expand All @@ -29,6 +31,7 @@ func Test_checkBuildProducts(t *testing.T) {
{
"No android FAIL, ios generated",
args{
[]string{},
[]string{},
[]string{"/path.app"},
[]string{},
Expand All @@ -38,19 +41,33 @@ func Test_checkBuildProducts(t *testing.T) {
true,
},
{
"No ios FAIL, android generated",
"No ios FAIL, android apk generated",
args{
[]string{"/path.apk"},
[]string{},
[]string{},
[]string{},
[]string{"ios", "android"},
"emulator",
},
true,
},
{
"No ios FAIL, android aab generated",
args{
[]string{},
[]string{"/path.aab"},
[]string{},
[]string{},
[]string{"ios", "android"},
"device",
},
true,
},
{
"ios emulator target OK",
args{
[]string{},
[]string{},
[]string{"/path.app"},
[]string{},
Expand All @@ -62,6 +79,7 @@ func Test_checkBuildProducts(t *testing.T) {
{
"ios emulator target, ipa generated FAIL",
args{
[]string{},
[]string{},
[]string{},
[]string{"/path.apk"},
Expand All @@ -73,6 +91,7 @@ func Test_checkBuildProducts(t *testing.T) {
{
"ios device target, app generated FAIL",
args{
[]string{},
[]string{},
[]string{"/app_path.app"},
[]string{},
Expand All @@ -81,21 +100,46 @@ func Test_checkBuildProducts(t *testing.T) {
},
true,
},
{
"Android aab only, OK",
args{
[]string{"/path.apk"},
[]string{},
[]string{},
[]string{"/path.ipa"},
[]string{"ios", "android"},
"device",
},
false,
},
{
"ios, android OK",
args{
[]string{"/path.apk"},
[]string{},
[]string{},
[]string{"/path.ipa"},
[]string{"ios", "android"},
"device",
},
false,
},
{
"ios, android OK",
args{
[]string{},
[]string{"/path.aab"},
[]string{},
[]string{"/path.ipa"},
[]string{"ios, android"},
[]string{"ios", "android"},
"device",
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := checkBuildProducts(tt.args.apks, tt.args.apps, tt.args.ipas, tt.args.platforms, tt.args.target); (err != nil) != tt.wantErr {
if err := checkBuildProducts(tt.args.apks, tt.args.aabs, tt.args.apps, tt.args.ipas, tt.args.platforms, tt.args.target); (err != nil) != tt.wantErr {
t.Errorf("checkBuildProducts() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
7 changes: 6 additions & 1 deletion step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ inputs:
description: |-
Use this input to specify custom options, to append to the end of the cordova-cli build command.
Cordova does not yet support the new build system made default in XCode 10 (https://github.com/apache/cordova-ios/issues/407).
Add `-- --packageType="bundle"` to build an Android bundle (aab). (https://github.com/apache/cordova-android/pull/764)
The new Xcode build system is now supported in cordova-ios@5.0.0 (https://github.com/apache/cordova-ios/issues/407).
To use the legacy build system add `--buildFlag="-UseModernBuildSystem=0"` to the options string.
Example:
Expand Down Expand Up @@ -136,3 +138,6 @@ outputs:
- BITRISE_APK_PATH: ""
opts:
title: The created android .apk file's path
- BITRISE_AAB_PATH: ""
opts:
title: The created android .aab file's path

0 comments on commit 4e18940

Please sign in to comment.