Skip to content

Commit fe37a30

Browse files
smuldrofalvai
andauthored
Add dry_run option to validate without committing (#172)
* Add dry_run option to validate without committing * Add E2E test * Fix indent * Fix parallel testing issues? * Fix conflicting versionName across tests * Increment version code to not conflict with another test * Define track --------- Co-authored-by: Olivér Falvai <ofalvai@gmail.com>
1 parent c341208 commit fe37a30

File tree

5 files changed

+105
-27
lines changed

5 files changed

+105
-27
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ Upload your Android app to Google Play.
99

1010
The Step uploads your Android app to Google Play. It works with both APK and AAB files.
1111

12-
Please note that in order to successfully use this Step, you must [upload your first APK or AAB file manually](https://support.google.com/googleplay/android-developer/answer/9859152?hl=en&visit_id=637407764704794872-3953166533&rd=1), using Google's own web interface!
13-
Once you uploaded one APK or AAB of your app to Google Play manually, you can use our Step for all subsequent versions.
12+
Please note that in order to successfully use this Step, you must [upload your first APK or AAB file manually](https://support.google.com/googleplay/android-developer/answer/9859152?hl=en&visit_id=637407764704794872-3953166533&rd=1), using Google's own web interface!
13+
Once you uploaded one APK or AAB of your app to Google Play manually, you can use our Step for all subsequent versions.
1414

1515
### Configuring the Step
1616

1717
The Step uses Google's API so before attempting to use the Step, you need to [Set up Google API access](https://devcenter.bitrise.io/deploy/android-deploy/deploying-android-apps/#setting-up-google-play-api-access). This includes:
1818
- [Linking your Google Developer Console to an API project](https://developers.google.com/android-publisher/getting_started#linking_your_api_project).
1919
- [Setting up API access using a service account](https://developers.google.com/android-publisher/getting_started#using_a_service_account).
20-
- Granting the necessary access rights to the service account.
21-
- Upload the service account JSON key to Bitrise and store it in a [Secret Env Var](https://devcenter.bitrise.io/builds/env-vars-secret-env-vars/).
20+
- Granting the necessary access rights to the service account.
21+
- Upload the service account JSON key to Bitrise and store it in a [Secret Env Var](https://devcenter.bitrise.io/builds/env-vars-secret-env-vars/).
2222

2323
Due to the way the Google Play Publisher API works, you have to grant at least the following permissions to that service account:
2424
- Edit store listing, pricing & distribution
@@ -30,25 +30,25 @@ Read the full process in our [Deploying Android apps guide](https://devcenter.bi
3030

3131
To deploy your app with the Step:
3232

33-
1. In the **Service Account JSON key file path**, add the Secret that stores your service account JSON key.
34-
1. In the **App file path** input, set the path to your APK and/or AAB files. You can add multiple paths here, separated with a newline.
33+
1. In the **Service Account JSON key file path**, add the Secret that stores your service account JSON key.
34+
1. In the **App file path** input, set the path to your APK and/or AAB files. You can add multiple paths here, separated with a newline.
3535
In most cases, the default values work well unless you changed the output variable of the Step that build your APK or AAB.
36-
1. In the **Package name** input, set the package name of your app.
36+
1. In the **Package name** input, set the package name of your app.
3737
1. In the **Track** input, add the track to which you want to assign the app. This can be any of the built-in tracks or a custom track of your own.
3838

39-
### Troubleshooting
39+
### Troubleshooting
4040

4141
If the Step fails, check the following:
42-
- If it's an authentication error, check that your Secret points to the correct file (and that a file is uploaded at all).
42+
- If it's an authentication error, check that your Secret points to the correct file (and that a file is uploaded at all).
4343
- Make sure your service account has the necessary access rights.
44-
- Check that there's no typo in the package name and that you selected an existing track for the app.
44+
- Check that there's no typo in the package name and that you selected an existing track for the app.
4545

46-
### Useful links
46+
### Useful links
4747

4848
- [Google Play Developer API - Getting Started](https://developers.google.com/android-publisher/getting_started)
4949
- [Deploying Android apps](https://devcenter.bitrise.io/deploy/android-deploy/deploying-android-apps/)
5050

51-
### Related Steps
51+
### Related Steps
5252

5353
- [TestFairy Deploy Android](https://www.bitrise.io/integrations/steps/testfairy-deploy-android)
5454
- [AppCenter Android Deploy](https://www.bitrise.io/integrations/steps/appcenter-deploy-android)
@@ -104,12 +104,13 @@ steps:
104104
| `mapping_file` | The `mapping.txt` file provides a translation between the original and obfuscated class, method, and field names. Uploading a mapping file is not required when deploying an AAB as the app bundle contains the mapping file itself. In case of deploying [multiple artifacts](https://developer.android.com/google/play/publishing/multiple-apks.html), you can specify multiple mapping.txt files as a newline (`\n`) or pipe (`\|`) separated list. The order of mapping files should match the list of APK or AAB files in the `app_path` input. | | `$BITRISE_MAPPING_PATH` |
105105
| `retry_without_sending_to_review` | If set to `true` and the initial change request fails, the changes will not be reviewed until they are manually sent for review from the Google Play Console UI. If set to `false`, the step fails if the changes can't be automatically sent to review. | required | `false` |
106106
| `ack_bundle_installation_warning` | 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). | required | `false` |
107+
| `dry_run` | If set to `true` then the changes will not be committed to create a real release in the Play Console. Use this flag to validate your configuration without triggering a new review. See the [API reference](https://developers.google.com/android-publisher/api-ref/rest/v3/edits/validate). | | `false` |
107108
</details>
108109

109110
<details>
110111
<summary>Outputs</summary>
111112

112-
| Key | Description |
113+
| Key | Description |
113114
|------------------|----------------------------------------------------|
114115
| `FAILURE_REASON` | Reason the upload to Google Play failed, if it did |
115116

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Configs struct {
2626
Status string `env:"status"`
2727
RetryWithoutSendingToReview bool `env:"retry_without_sending_to_review,opt[true,false]"`
2828
AckBundleInstallationWarning bool `env:"ack_bundle_installation_warning,opt[true,false]"`
29+
DryRun bool `env:"dry_run,opt[true,false]"`
2930
IsDebugLog bool `env:"verbose_log,opt[true,false]"`
3031
}
3132

e2e/bitrise.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,62 @@ workflows:
169169
- user_fraction: ""
170170
- retry_without_sending_to_review: true
171171
- verbose_log: true
172+
test_dry_run:
173+
envs:
174+
- TEST_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk22.git
175+
- BRANCH: master
176+
177+
- BITRISEIO_ANDROID_KEYSTORE_URL: $SIMPLESAMPLE_ANDROID_KEYSTORE_URL
178+
- BITRISEIO_ANDROID_KEYSTORE_PASSWORD: $SIMPLESAMPLE_ANDROID_KEYSTORE_PASSWORD
179+
- BITRISEIO_ANDROID_KEYSTORE_ALIAS: $SIMPLESAMPLE_ANDROID_KEY_ALIAS
180+
- BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD: $SIMPLESAMPLE_ANDROID_KEY_PASSWORD
181+
182+
- PACKAGE_NAME: com.bitrise_io.sample_apps_android_simple_google_play_deploy
183+
- SERVICE_ACCOUNT_KEY_URL: $GOOGLE_PLAY_SERVICE_ACCOUNT_KEY_URL
184+
- TRACK: internal
185+
before_run:
186+
- _setup
187+
steps:
188+
- set-java-version:
189+
inputs:
190+
- set_java_version: "17"
191+
- script:
192+
title: Set $VERSION_CODE higher than previously submitted
193+
inputs:
194+
- content: |-
195+
set -ex
196+
197+
envman add --key VERSION_CODE --value $(( $BITRISE_BUILD_NUMBER + 1 ))
198+
- change-android-versioncode-and-versionname:
199+
inputs:
200+
- build_gradle_path: ./app/build.gradle
201+
- new_version_code: $VERSION_CODE
202+
- new_version_name: 0.2.5-dryrun
203+
- gradle-runner:
204+
inputs:
205+
- gradle_task: assembleRelease
206+
- gradlew_path: ./gradlew
207+
- sign-apk:
208+
inputs:
209+
- android_app: $BITRISE_APK_PATH_LIST
210+
- use_apk_signer: true
211+
- path::./:
212+
title: Execute step
213+
# Limit running this test to only one stack to avoid parallel testing issues
214+
# Running E2E tests on all stacks in parallel would cause conflicting deployments in Google Play to the same app
215+
run_if: |-
216+
{{ or (enveq "IS_LATEST_STACK_UBUNTU" "true") (not .IsCI) }}
217+
inputs:
218+
- service_account_json_key_path: $SERVICE_ACCOUNT_KEY_URL
219+
- package_name: $PACKAGE_NAME
220+
- app_path: $BITRISE_SIGNED_APK_PATH
221+
- dry_run: true
222+
- track: $TRACK
223+
- mapping_file: ""
224+
- user_fraction: ""
225+
- retry_without_sending_to_review: true
226+
- verbose_log: true
227+
172228
_setup:
173229
steps:
174230
- script:

main.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ func main() {
177177
}
178178
log.Donef("Authenticated client created")
179179

180-
errorString := executeEdit(service, configs, false)
180+
errorString := executeEdit(service, configs, false, configs.DryRun)
181181
if errorString == "" {
182182
return
183183
}
184184
if strings.Contains(errorString, changesNotSentForReviewMessage) {
185185
if configs.RetryWithoutSendingToReview {
186186
log.Warnf(errorString)
187187
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.")
188-
errorString = executeEdit(service, configs, true)
188+
errorString = executeEdit(service, configs, true, false)
189189
if errorString == "" {
190190
return
191191
}
@@ -200,7 +200,7 @@ func main() {
200200
failf(errorString)
201201
}
202202

203-
func executeEdit(service *androidpublisher.Service, configs Configs, changesNotSentForReview bool) (errorString string) {
203+
func executeEdit(service *androidpublisher.Service, configs Configs, changesNotSentForReview bool, dryRun bool) (errorString string) {
204204
editsService := androidpublisher.NewEditsService(service)
205205
//
206206
// Create insert edit
@@ -245,15 +245,27 @@ func executeEdit(service *androidpublisher.Service, configs Configs, changesNotS
245245
}
246246
log.Donef("Track updated")
247247

248-
//
249-
// Commit edit
250-
fmt.Println()
251-
log.Infof("Committing edit")
252-
editsCommitCall := editsService.Commit(configs.PackageName, appEdit.Id)
253-
editsCommitCall.ChangesNotSentForReview(changesNotSentForReview)
254-
if _, err := editsCommitCall.Do(); err != nil {
255-
return fmt.Sprintf("Failed to commit edit, error: %s", err)
248+
if dryRun {
249+
//
250+
// Validate edit
251+
fmt.Println()
252+
log.Infof("Dry run: validating edit without committing")
253+
validateEditCall := editsService.Validate(configs.PackageName, appEdit.Id)
254+
if _, err := validateEditCall.Do(); err != nil {
255+
return fmt.Sprintf("Failed to validate edit, error: %s", err)
256+
}
257+
log.Donef("Edit validated")
258+
} else {
259+
//
260+
// Commit edit
261+
fmt.Println()
262+
log.Infof("Committing edit")
263+
editsCommitCall := editsService.Commit(configs.PackageName, appEdit.Id)
264+
editsCommitCall.ChangesNotSentForReview(changesNotSentForReview)
265+
if _, err := editsCommitCall.Do(); err != nil {
266+
return fmt.Sprintf("Failed to commit edit, error: %s", err)
267+
}
268+
log.Donef("Edit committed")
256269
}
257-
log.Donef("Edit committed")
258270
return ""
259271
}

step.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ inputs:
176176
value_options:
177177
- "true"
178178
- "false"
179-
180179
- ack_bundle_installation_warning: "false"
181180
opts:
182181
title: Acknowledge Bundle Installation Warning
@@ -187,7 +186,16 @@ inputs:
187186
value_options:
188187
- "true"
189188
- "false"
190-
189+
- dry_run: "false"
190+
opts:
191+
title: Dry Run
192+
description: |-
193+
If set to `true` then the changes will not be committed to create a real release in the Play
194+
Console. Use this flag to validate your configuration without triggering a new review.
195+
is_required: false
196+
value_options:
197+
- "true"
198+
- "false"
191199
- verbose_log: "false"
192200
opts:
193201
title: Enable verbose logging

0 commit comments

Comments
 (0)