Skip to content

Commit

Permalink
Introduce input to be able to send edit requests without automaticall…
Browse files Browse the repository at this point in the history
…y sending it for review (#120)

* Set do not send changes to review option to true

* Go mod update

* Patch Google API code

* remove monokeypatch

* Retry committing changes if it fails with the need of changesNotSentForReview

* Introduced new input to be able to automatically retry
* Updated Dependencies

* Fix `yaml` indentation

* Add retry to our test case

* Remove validation step

* Add the flag to the other e2e test too

* Updated input description

Co-authored-by: Mate Herber <[email protected]>
  • Loading branch information
lpusok and Mate Herber authored Aug 11, 2021
1 parent c4bd521 commit 342d263
Show file tree
Hide file tree
Showing 263 changed files with 12,764 additions and 13,696 deletions.
2 changes: 2 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ workflows:
- track: $TRACK
- mapping_file: ""
- user_fraction: ""
- retry_without_sending_to_review : true

# This is needed to test the possible shadowing of releases, it should run after apk_deploy_test_1
apk_deploy_test_2:
Expand All @@ -228,6 +229,7 @@ workflows:
- track: $TRACK
- mapping_file: ""
- user_fraction: ""
- retry_without_sending_to_review : true

dep-update:
steps:
Expand Down
23 changes: 12 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ 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"`
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]"`
}

// validate validates the Configs.
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ module github.com/bitrise-steplib/steps-google-play-deploy
go 1.16

require (
github.com/bitrise-io/go-steputils v0.0.0-20201016102104-03ae3a6ded35
github.com/bitrise-io/go-utils v0.0.0-20210316133228-449620935158
github.com/golang/protobuf v1.5.1 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 // indirect
golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e // indirect
google.golang.org/api v0.42.0
google.golang.org/genproto v0.0.0-20210317182105-75c7a8546eb9 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
cloud.google.com/go v0.90.0 // indirect
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1
github.com/bitrise-io/go-utils v0.0.0-20210713111255-08be784d45d0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
google.golang.org/api v0.52.0
google.golang.org/genproto v0.0.0-20210809142519-0135a39c2737 // indirect
)
143 changes: 115 additions & 28 deletions go.sum

Large diffs are not rendered by default.

45 changes: 29 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"google.golang.org/api/option"
)

const changesNotSentForReviewMessage = "Changes cannot be sent for review automatically. Please set the query parameter changesNotSentForReview to true"

func failf(format string, v ...interface{}) {
log.Errorf(format, v...)
os.Exit(1)
Expand Down Expand Up @@ -155,15 +157,35 @@ func main() {
}
log.Donef("Authenticated client created")

errorString := executeEdit(service, configs, false)
if errorString == "" {
return
}
if strings.Contains(errorString, changesNotSentForReviewMessage) {
if configs.RetryWithoutSendingToReview {
log.Warnf(errorString)
log.Warnf("Trying to commit edit with setting changesNotSentForReview to true. Please make sure to send the changes to review from Google Play Console UI.")
errorString = executeEdit(service, configs, true)
if errorString == "" {
return
}
} else {
log.Warnf("Sending the edit to review failed. Please change \"Retry changes without sending to review\" input to true if you wish to send the changes with the changesNotSentForReview flag. Please note that in that case the review has to be manually initiated from Google Play Console UI")
}
}
failf(errorString)
}

func executeEdit(service *androidpublisher.Service, configs Configs, changesNotSentForReview bool) (errorString string) {
editsService := androidpublisher.NewEditsService(service)
//
// Create insert edit
fmt.Println()
log.Infof("Create new edit")
editsService := androidpublisher.NewEditsService(service)
editsInsertCall := editsService.Insert(configs.PackageName, &androidpublisher.AppEdit{})
appEdit, err := editsInsertCall.Do()
if err != nil {
failf("Failed to perform edit insert call, error: %s", err)
return fmt.Sprintf("Failed to perform edit insert call, error: %s", err)
}
log.Printf(" editID: %s", appEdit.Id)
log.Donef("Edit insert created")
Expand All @@ -174,7 +196,7 @@ func main() {
log.Infof("Upload apks or app bundles")
versionCodes, err := uploadApplications(configs, service, appEdit)
if err != nil {
failf("Failed to upload APKs: %v", err)
return fmt.Sprintf("Failed to upload APKs: %v", err)
}
log.Donef("Applications uploaded")

Expand All @@ -183,28 +205,19 @@ func main() {
log.Infof("Update track")
versionCodeSlice := versionCodeMapToSlice(versionCodes)
if err := updateTracks(configs, service, appEdit, versionCodeSlice); err != nil {
failf("Failed to update track, reason: %v", err)
return fmt.Sprintf("Failed to update track, reason: %v", err)
}
log.Donef("Track updated")

//
// Validate edit
fmt.Println()
log.Infof("Validating edit")
editsValidateCall := editsService.Validate(configs.PackageName, appEdit.Id)
if _, err := editsValidateCall.Do(); err != nil {
failf("Failed to validate edit, error: %s", err)
}
log.Donef("Edit is valid")

//
// Commit edit
fmt.Println()
log.Infof("Committing edit")
editsCommitCall := editsService.Commit(configs.PackageName, appEdit.Id)
editsCommitCall.ChangesNotSentForReview(changesNotSentForReview)
if _, err := editsCommitCall.Do(); err != nil {
failf("Failed to commit edit, error: %s", err)
return fmt.Sprintf("Failed to commit edit, error: %s", err)
}

log.Donef("Edit committed")
return ""
}
Loading

0 comments on commit 342d263

Please sign in to comment.