Skip to content

Commit

Permalink
Add ack_bundle_installation_warning step input (#124)
Browse files Browse the repository at this point in the history
* Acknowledge App Bundle Installation Warning

* Add ack_bundle_installation_warning input in step.yml

* Add AckBundleInstallationWarning to Config

* Pass AckBundleInstallationWarning to uploadAppBundle

* Update input description

* Generalize error message

* Add specialized error message when bundle installation warning occurs

* Return nil instead of pointer to zero value

* Return nil instead of pointer to zero value
  • Loading branch information
Bence1001 authored Sep 2, 2021
1 parent c51c3c6 commit 8b3a631
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
25 changes: 13 additions & 12 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import (

// Configs stores the step's inputs
type Configs struct {
JSONKeyPath stepconf.Secret `env:"service_account_json_key_path,required"`
PackageName string `env:"package_name,required"`
AppPath string `env:"app_path,required"`
ExpansionfilePath string `env:"expansionfile_path"`
Track string `env:"track,required"`
UserFraction float64 `env:"user_fraction,range]0.0..1.0["`
UpdatePriority int `env:"update_priority,range[0..5]"`
WhatsnewsDir string `env:"whatsnews_dir"`
MappingFile string `env:"mapping_file"`
ReleaseName string `env:"release_name"`
Status string `env:"status"`
RetryWithoutSendingToReview bool `env:"retry_without_sending_to_review,opt[true,false]"`
JSONKeyPath stepconf.Secret `env:"service_account_json_key_path,required"`
PackageName string `env:"package_name,required"`
AppPath string `env:"app_path,required"`
ExpansionfilePath string `env:"expansionfile_path"`
Track string `env:"track,required"`
UserFraction float64 `env:"user_fraction,range]0.0..1.0["`
UpdatePriority int `env:"update_priority,range[0..5]"`
WhatsnewsDir string `env:"whatsnews_dir"`
MappingFile string `env:"mapping_file"`
ReleaseName string `env:"release_name"`
Status string `env:"status"`
RetryWithoutSendingToReview bool `env:"retry_without_sending_to_review,opt[true,false]"`
AckBundleInstallationWarning bool `env:"ack_bundle_installation_warning,opt[true,false]"`
}

// validate validates the Configs.
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func uploadApplications(configs Configs, service *androidpublisher.Service, appE
}

if strings.ToLower(filepath.Ext(appPath)) == ".aab" {
bundle, err := uploadAppBundle(service, configs.PackageName, appEdit.Id, appFile)
bundle, err := uploadAppBundle(service, configs.PackageName, appEdit.Id, appFile, configs.AckBundleInstallationWarning)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func executeEdit(service *androidpublisher.Service, configs Configs, changesNotS
log.Infof("Upload apks or app bundles")
versionCodes, err := uploadApplications(configs, service, appEdit)
if err != nil {
return fmt.Sprintf("Failed to upload APKs: %v", err)
return fmt.Sprintf("Failed to upload application(s): %v", err)
}
log.Donef("Applications uploaded")

Expand Down
14 changes: 11 additions & 3 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
releaseStatusHalted = "halted"
)

const bundleInstallationWarning = "Error 403: The installation of the app bundle may be too large " +
"and trigger user warning on some devices, and this needs to be explicitly acknowledged in the request."

// uploadExpansionFiles uploads the expansion files for given applications, like .obb files.
func uploadExpansionFiles(service *androidpublisher.Service, expFileEntry string, packageName string, appEditID string, versionCode int64) error {
cleanExpFileConfigEntry := strings.TrimSpace(expFileEntry)
Expand Down Expand Up @@ -92,16 +95,21 @@ func uploadMappingFile(service *androidpublisher.Service, configs Configs, appEd
}

// uploadAppBundle uploads aab files to Google Play. Returns the uploaded bundle itself or an error.
func uploadAppBundle(service *androidpublisher.Service, packageName string, appEditID string, appFile *os.File) (*androidpublisher.Bundle, error) {
func uploadAppBundle(service *androidpublisher.Service, packageName string, appEditID string, appFile *os.File, ackBundleInstallationWarning bool) (*androidpublisher.Bundle, error) {
log.Debugf("Uploading file %v with package name '%v', AppEditId '%v", appFile, packageName, appEditID)
editsBundlesService := androidpublisher.NewEditsBundlesService(service)

editsBundlesUploadCall := editsBundlesService.Upload(packageName, appEditID)
editsBundlesUploadCall.Media(appFile, googleapi.ContentType("application/octet-stream"))
editsBundlesUploadCall.AckBundleInstallationWarning(ackBundleInstallationWarning)

bundle, err := editsBundlesUploadCall.Do()
if err != nil {
return &androidpublisher.Bundle{}, fmt.Errorf("failed to upload app bundle, error: %s", err)
msg := fmt.Sprintf("failed to upload app bundle, error: %s", err)
if strings.Contains(err.Error(), bundleInstallationWarning) {
msg = fmt.Sprintf("%s\nTo acknowledge this warning, set the Acknowledge Bundle Installation Warning (ack_bundle_installation_warning) input to true.", msg)
}
return nil, fmt.Errorf(msg)
}
log.Infof("Uploaded app bundle version: %d", bundle.VersionCode)
return bundle, nil
Expand All @@ -117,7 +125,7 @@ func uploadAppApk(service *androidpublisher.Service, packageName string, appEdit

apk, err := editsApksUploadCall.Do()
if err != nil {
return &androidpublisher.Apk{}, fmt.Errorf("failed to upload apk, error: %s", err)
return nil, fmt.Errorf("failed to upload apk, error: %s", err)
}
log.Infof("Uploaded apk version: %d", apk.VersionCode)
return apk, nil
Expand Down
11 changes: 11 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,14 @@ inputs:
value_options:
- "true"
- "false"

- ack_bundle_installation_warning: "false"
opts:
title: Acknowledge Bundle Installation Warning
description: |-
Must be set to `true` if the App Bundle installation may trigger a warning on user devices
(for example, if installation size may be over a threshold, typically 100 MB).
is_required: true
value_options:
- "true"
- "false"

0 comments on commit 8b3a631

Please sign in to comment.