diff --git a/README.md b/README.md index 5fc9e38..628d644 100644 --- a/README.md +++ b/README.md @@ -1,115 +1,121 @@ # Google play CLI -CLI tool for publish and management application in Google Play Console. +Transparent CLI tooling for managing Google Play Console. -Actually this library is CLI wrapper for [Google Play Java library](https://developers.google.com/android-publisher/api-ref) +## Table of Contents -List of all vailable commands in [wiki](https://github.com/Vacxe/google-play-cli/wiki/Google-Play-CLI) *WIP* +- [Introduction](#introduction) +- [Installation](#installation) + - [Homebrew](#homebrew) + - [Docker](#docker) + - [GitHub Actions](#github-action) +- [How to use CLI](#how-to-use-cli-directly) -### How to use -* Before at all you should obtain a `serviceAccount.json` +This library is transparent CLI wrapper for official [Google Play Java Library](https://developers.google.com/android-publisher/api-ref) - Goto: Google Play Console -> Developer Account -> Api access -> Service Accounts -> CREATE SERVICE ACCOUNT - Follow the instruction and grant the access for service accout -* Try simplest command - * ```google-play-cli --help``` - list of all commands - * ```google-play-cli apk list --config-file service_account.json --package-name ``` - -* Apk info extraction - - Install [Apk info extractor](https://github.com/Vacxe/apk-info-extractor) and JQ `apkinfoextractor | jq '.package'` - -* How to upload apk -Bash function can be copied to any .sh file and used as `uploadapk "path/to/my.apk" "path/to/service_account.json"` - -``` -function uploadapk(){ - path_to_apk=$1 - export PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE=$2 - - #If proxy needed - #PLAYSTORE_PROXY=192.168.0.1:3128 - - #Increase connection timeout - #PLAYSTORE_CONNECTION_TIMEOUT=PT6M - - apk_package=$(apkinfoextractor $path_to_apk | jq '.package') - export APP_PACKAGE_NAME=$apk_package - - apk_version_code=$(apkinfoextractor $path_to_apk | jq '.versionCode') +## Introduction - edit_id=$(google-play-cli edit create) - google-play-cli apk upload --edit-id $edit_id --apk $path_to_apk - google-play-cli tracks update --edit-id $edit_id --track "internal" --apk-version-code $apk_version_code - google-play-cli edit validate --edit-id $edit_id - google-play-cli edit commit --edit-id $edit_id +Previous libs what been used for application deployment contained disadvantages what blocked me from application delivery. As well, all libraries contains internal logic for uploading, but will be nice hot have some more **transparent** solution. +* [Gradle Triple-T Plugin](https://github.com/Triple-T/gradle-play-publisher) + * Integration with build system - Distribution should not be a part of build system. Its blocking us to create a reusable chains on CI. If project is huge, it will create a lot of overhead with evaluation project. + * Not flexible enough - suitable only for Apk/Bundle upload +* [r0adkll/sign-android-release](https://github.com/r0adkll/sign-android-release) + * Not flexible enough - suitable only for Apk/Bundle upload - unset APP_PACKAGE_NAME - unset PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE -} -``` +**Advantages of this project** + * Core: Transparent CLI wrapper for Official Google Play Console library + * Can be installed on host directly as CLI (via brew or binaries) or can be used via Docker or GitHub actions. You are able to test it locally before deployment. + * Docker: Transparent environment for CLI, as well JQ for easier Json response management in case of custom actions + * GitHub Action: Transparent wrapper for Docker, with amount of custom *templates* to simplify day to day actions like upload apk -On CI you can add service account json file as a secret to environment variable +## Installation -`` -PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT -`` - -# How to install - -## Homebrew +### Homebrew ``` brew tap vacxe/tap brew install vacxe/tap/googleplaycli ``` -## [Docker](https://github.com/Vacxe/google-play-cli-kt/pkgs/container/google-play-cli) +### [Docker](https://github.com/Vacxe/google-play-cli-kt/pkgs/container/google-play-cli) ``` ghcr.io/vacxe/google-play-cli: ``` -## [GitHub Action](https://github.com/marketplace/actions/google-play-console) +### [GitHub Action](https://github.com/marketplace/actions/google-play-console) -*Note: replace `@master` with latest version for stable behaviour or leave it for last updates* +[GitHub Action](https://github.com/marketplace/actions/google-play-console) `vacxe/google-play-cli-kt` is transparent wrapper over [Docker](https://github.com/Vacxe/google-play-cli-kt/pkgs/container/google-play-cli) `google-play-cli-kt`, what contains transparent CLI warapper for [Google Play Java Library](https://developers.google.com/android-publisher/api-ref). It can provide for you possibility to write any custom scripts in depends on you needs or use one of **[Available templates](#github-action/README.md)**. -Bundle upload example +*Example of APK uploading template:* ```yaml - - uses: vacxe/google-play-cli-kt@master - with: - template: bundles-upload - service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} - version-code: ${{ github.run_number }} # You may need to know version code - package-name: - path-to-bundle: - track: internal - status: draft +- uses: vacxe/google-play-cli-kt@master + with: + template: apk-upload + service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} + version-code: ${{ github.run_number }} + package-name: + path-to-apk: + track: internal + status: draft ``` -APK upload example -```yaml - - uses: vacxe/google-play-cli-kt@master - with: - template: apk-upload - service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} - version-code: ${{ github.run_number }} # You may need to know version code - package-name: - path-to-apk: - track: internal - status: draft +## How to use CLI directly +* Before you started you should obtain a `serviceAccount.json` + + Goto: Google Play Console -> Developer Account -> Api access -> Service Accounts -> CREATE SERVICE ACCOUNT + Follow the instruction and grant the access for service account +* Try basic command + * ```google-play-cli --help``` - list of all commands + * ```google-play-cli apk list --config-file service_account.json --package-name ``` + +Example how to upload apk with step by step explanation: + +* Let configure few environment variables first, what will make our next CLI calls much easier +```shell +# If proxy needed +#PLAYSTORE_PROXY=192.168.0.1:3128 + +# Increase connection timeout +#PLAYSTORE_CONNECTION_TIMEOUT=PT6M + +export PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE="/path/to/service_account.json" +# Or set a plain text +#export PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT="CONTENT OF JSON" +export APP_PACKAGE_NAME="com.my.package" ``` -Custom script example +Exporting is not required, but if you will not decide to do it you may need to add for each command +* `--config-file "/path/to/service_account.json"` + * or `--config-content "CONTENT OF JSON"` +* `--package-name "com.my.package"` -```yaml - - uses: vacxe/google-play-cli-kt@master - with: - custom-script: "Any direct calls for google-play-cli" +*Tip: On CI you can add service account json file as a secret to environment variable* + +--- + +* First of all you may need to create **edit_id** +```shell +edit_id=$(google-play-cli edit create) +``` +* With existing `edit_id` you can do any modifications in Play Console, let's upload APK +```shell +google-play-cli apk upload --edit-id $edit_id --apk "path/to/my.apk" +``` +* APK been uploaded, we need to assign it to `track`. Let choice `internal` track and status will be `draft`, as well we need to know version code (for example `42`) +```shell +google-play-cli tracks update --edit-id $edit_id --track "internal" --status "draft" --version-code "42" +``` +* As a non-required step you can validate your edit at any time +```shell +google-play-cli edit validate --edit-id $edit_id +``` +* And as last step - commit your changes +```shell +google-play-cli edit commit --edit-id $edit_id ``` -`````` +## License -License ------- Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/github-action/Dockerfile b/github-action/Dockerfile index 6a84542..1a3311a 100644 --- a/github-action/Dockerfile +++ b/github-action/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/vacxe/google-play-cli:0.4.2 +FROM ghcr.io/vacxe/google-play-cli:0.4.3 COPY entrypoint.sh /entrypoint.sh COPY templates /templates diff --git a/github-action/README.md b/github-action/README.md new file mode 100644 index 0000000..86208ae --- /dev/null +++ b/github-action/README.md @@ -0,0 +1,97 @@ +# Google play CLI (GitHub Actions) + +## Requirements +Any GitHub Action `vacxe/google-play-cli-kt` required two parameters to be set + * `service-account-json` - Plain text Service Account JSON, can be stored and provided via `secrets` + + *Example: `service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }}`* + * `package-name` - package name for target application + + *Example: `com.my.application`* + +## Custom Script +[GitHub Action](https://github.com/marketplace/actions/google-play-console) `vacxe/google-play-cli-kt` is transparent wrapper over [Docker](https://github.com/Vacxe/google-play-cli-kt/pkgs/container/google-play-cli) `google-play-cli-kt`, what contains transparent CLI warapper for [Google Play Java Library](https://developers.google.com/android-publisher/api-ref). It can provide for you possibility to write any custom scripts in depends on you needs. + +*Example: Request all bundles* + +```yaml + - uses: vacxe/google-play-cli-kt@master + with: + service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} + package-name: my.package.name + custom-script: 'google-play-cli bundles list | jq' +``` + +However, most of the cases is actually repeatable for many projects. You can take a look on *Templates* or **contribute** to it. + +## Templates + +- [Apk](#apk) + - [Upload](#upload) +- [Bundles](#bundles) + - [Upload](#upload-1) +- [Deobfuscation Files](#deobfuscation-files) + - [Upload](#upload-2) + +*Note: replace `@master` with latest version for stable behaviour or leave it for last updates* + +## Apk +### Upload +* `path-to-apk` - Path to APK file +* `version-code` - Integer version code of Apk +* `track` - Target track +* `changes-not-sent-for-review` - Do not send changes for review +* `status` - The status of a release +* `user-fraction` - Fraction of users who are eligible to receive the release. 0 < fraction < 1. To be set, release status must be "inProgress" or "halted". + +*Example:* +```yaml +- uses: vacxe/google-play-cli-kt@master + with: + template: apk-upload + service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} + package-name: + version-code: ${{ github.run_number }} + path-to-apk: + track: internal + status: draft +``` + +## Bundles +### Upload +* `path-to-bundle` - Path to Bundle file +* `version-code` - Integer version code of Bundle +* `track` - Target track +* `changes-not-sent-for-review` - Do not send changes for review +* `status` - The status of a release +* `user-fraction` - Fraction of users who are eligible to receive the release. 0 < fraction < 1. To be set, release status must be "inProgress" or "halted". + +*Example:* +```yaml +- uses: vacxe/google-play-cli-kt@master + with: + template: bundles-upload + service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} + package-name: + version-code: ${{ github.run_number }} + path-to-bundle: + track: internal + status: draft +``` + +## Deobfuscation Files +### Upload +* `path-to-mapping` - Path to Mapping file +* `version-code` - Integer version code of assigned Apk or Bundle +* `changes-not-sent-for-review` - Do not send changes for review + +*Example:* +```yaml +- uses: vacxe/google-play-cli-kt@master + with: + template: deobfuscation-files-upload + service-account-json: ${{ secrets.SERVICE_ACCOUNT_JSON }} + package-name: + path-to-mapping: + version-code: ${{ github.run_number }} +``` \ No newline at end of file diff --git a/github-action/templates/apk-upload.sh b/github-action/templates/apk-upload.sh index 4822a25..8810752 100644 --- a/github-action/templates/apk-upload.sh +++ b/github-action/templates/apk-upload.sh @@ -23,7 +23,7 @@ echo "Edit id created: $EDIT_ID" echo "Upload APK..." google-play-cli apk upload --edit-id "$EDIT_ID" --apk "$PATH_TO_APK" echo "Update track..." -google-play-cli tracks update --edit-id "$EDIT_ID" --apk-version-code "$VERSION_CODE" --track "$TRACK" \ +google-play-cli tracks update --edit-id "$EDIT_ID" --version-code "$VERSION_CODE" --track "$TRACK" \ ${USER_FRACTION:+ --user-fraction "$USER_FRACTION"} \ ${STATUS:+ --status "$STATUS"} echo "Validate..." diff --git a/github-action/templates/bundles-upload.sh b/github-action/templates/bundles-upload.sh index 534248a..cd3d4be 100644 --- a/github-action/templates/bundles-upload.sh +++ b/github-action/templates/bundles-upload.sh @@ -23,7 +23,7 @@ echo "Edit id created: $EDIT_ID" echo "Upload Bundle..." google-play-cli bundles upload --edit-id "$EDIT_ID" --bundle "$PATH_TO_BUNDLE" echo "Update track..." -google-play-cli tracks update --edit-id "$EDIT_ID" --apk-version-code "$VERSION_CODE" --track "$TRACK" \ +google-play-cli tracks update --edit-id "$EDIT_ID" --version-code "$VERSION_CODE" --track "$TRACK" \ ${USER_FRACTION:+ --user-fraction "$USER_FRACTION"} \ ${STATUS:+ --status "$STATUS"} echo "Validate..." diff --git a/github-action/templates/deobfuscation-files-upload.sh b/github-action/templates/deobfuscation-files-upload.sh index 5d9e8a1..a835238 100644 --- a/github-action/templates/deobfuscation-files-upload.sh +++ b/github-action/templates/deobfuscation-files-upload.sh @@ -15,7 +15,7 @@ echo "---" EDIT_ID=$(google-play-cli edit create) echo "Edit id created: $EDIT_ID" echo "Upload deobfuscation files..." -google-play-cli deobfuscation-files upload --edit-id "$EDIT_ID" --deobfuscation "$PATH_TO_MAPPING" --apk-version-code "$VERSION_CODE" +google-play-cli deobfuscation-files upload --edit-id "$EDIT_ID" --deobfuscation "$PATH_TO_MAPPING" --version-code "$VERSION_CODE" echo "Validate..." google-play-cli edit validate --edit-id "$EDIT_ID" || true # Ignore until changes-not-sent-for-review will be added as parameter echo "Commit..." diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt index 852a82b..14ebac2 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt @@ -66,10 +66,10 @@ object Commands { .file() .required() - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose deobfuscation file is being uploaded." + help = "The version code Apk/Bundle whose deobfuscation file is being uploaded." ) .int().required() @@ -85,7 +85,7 @@ object Commands { DeobfuscationfilesUploadModel( packageName, editId, - apkVersionCode, + versionCode, deobfuscation, deobfuscationFileType, parameters @@ -228,10 +228,10 @@ object Commands { name = "get", actionDescription = "Fetches the Expansion File configuration for the APK specified" ) { - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose Expansion File configuration is being read or modified" + help = "The version code of the Apk/Bundle whose Expansion File configuration is being read or modified" ).int().required() private val expansionFileType: String by option("--expansion-file-type", "-t").choice("main", "patch") .default("main") @@ -240,7 +240,7 @@ object Commands { ExpansionFilesGetModel( packageName, editId, - apkVersionCode, + versionCode, expansionFileType, parameters ) @@ -251,10 +251,10 @@ object Commands { name = "patch", actionDescription = "Updates the APK's Expansion File configuration to reference another APK's Expansion Files. To add a new Expansion File use the Upload method" ) { - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose Expansion File configuration is being read or modified" + help = "The version code of the Apk/Bundle whose Expansion File configuration is being read or modified" ).int().required() private val expansionFileType: String by option("--expansion-file-type", "-t").choice("main", "patch") .default("main") @@ -265,7 +265,7 @@ object Commands { ExpansionFilesPatchModel( packageName, editId, - apkVersionCode, + versionCode, expansionFileType, referencesVersion, fileSize, @@ -278,10 +278,10 @@ object Commands { name = "update", actionDescription = "Updates the APK's Expansion File configuration to reference another APK's Expansion Files. To add a new Expansion File use the Upload method" ) { - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose Expansion File configuration is being read or modified" + help = "The version code of the Apk/Bundle whose Expansion File configuration is being read or modified" ).int().required() private val expansionFileType: String by option("--expansion-file-type", "-t").choice("main", "patch") .default("main") @@ -292,7 +292,7 @@ object Commands { ExpansionFilesUpdateModel( packageName, editId, - apkVersionCode, + versionCode, expansionFileType, referencesVersion, fileSize, @@ -305,10 +305,10 @@ object Commands { name = "upload", actionDescription = "Uploads and attaches a new Expansion File to the APK specified" ) { - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose Expansion File configuration is being read or modified" + help = "The version code of the Apk/Bundle whose Expansion File configuration is being read or modified" ).int().required() private val expansionFileType: String by option("--expansion-file-type", "-t").choice("main", "patch") .default("main") @@ -319,7 +319,7 @@ object Commands { ExpansionFilesUploadModel( packageName, editId, - apkVersionCode, + versionCode, expansionFileType, expansionFile, parameters @@ -604,10 +604,10 @@ object Commands { actionDescription = "Updates the track configuration for the specified track type" ) { private val track: String by option("--track", "-t").required() - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose will be promoted to the track" + help = "The version code of the Apk/Bundle whose will be promoted to the track" ).int().required() private val userFraction: Double? by option( "--user-fraction", @@ -627,7 +627,7 @@ object Commands { packageName, editId, track, - apkVersionCode, + versionCode, userFraction, status, parameters @@ -640,10 +640,10 @@ object Commands { actionDescription = "Updates the track configuration for the specified track type" ) { private val track: String by option("--track", "-t").required() - val apkVersionCode: Int by option( - "--apk-version-code", + private val versionCode: Int by option( + "--version-code", "-v", - help = "The version code of the APK whose will be promoted to the track" + help = "The version code of the Apk/Bundle whose will be promoted to the track" ).int().required() private val userFraction: Double? by option( "--user-fraction", @@ -662,7 +662,7 @@ object Commands { packageName, editId, track, - apkVersionCode, + versionCode, userFraction, status, parameters diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt index c02a1f9..cb46a96 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt @@ -86,7 +86,7 @@ fun main(args: Array) { addCmd { object : CliktCommand(name = "version", help = "Library version code") { override fun run() { - println("0.4.2") + println("0.4.3") } } }