ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

Keeping track of staged rollouts with Android Bot

by Hello I'm Nik on Unsplash

Staged rollouts are a powerful way to release new app versions to your users. Staged rollouts allow developers to publish a new release to a fraction of their users, allowing them to quickly stop a rollout if any critical bugs are found and avoid dramatic impacts on app stability and performance.

Example of a rollout that started at 20% and was increased to 50%, before doing a full rollout

After we do a staged release we go back to our busy daily jobs, and more often than not, the staged rollout slips our minds and we forget about it. Only to realise days (or weeks…) later that the release we worked on so hard to release on time, is only rolled out to 20% of our users. Bummer! 😬

Enter Android Bot!

Android Bot is a Slack Bot that will be given the daily task of fetching the latest release information from the Google Play Store, and reminding us through Slack of any staged rollouts.

Fetching release information from Google Play Store

Google offers APIs that allow developers to perform publishing and app-management tasks through their API. It consists of two components: APIs for subscriptions and in-app-purchases, and APIs for publishing apps, and app-publish-management. Our Android Bot is going to use the latter component.

You can read more about it here, but in short: using these APIs you can publish new APKs to various tracks (alpha, beta, production), upload new app versions and retrieve information about your app releases. Google has made our life easy by creating a Google APIs Client Library for us (in Java and Python). We’re going to use the Python library to fetch the latest information about our app rollouts from the Google servers.

pipenv install google-api-python-clientpipenv install oauth2client

and create rollout_checker.py (make sure to change the package name to the package name of your app):

You will need to download a JSON file that contains a key tied to a service account that gives access to Google’s Developer API.

  1. Go to the IAM and admin console.
  2. Select the project you want to fetch release rollout information for.
  3. Click “Create service account” in the top and create a service account
  4. After the account has been created, find it in the list and click on the three circles all the way to the right. Select “Create key”.
  5. Select JSON and download the file.
  6. Rename this file to key.json and place it in the same directory as your rollout_checker.py script.
Google IAM and admin console

After you run the script, you should now see a list of tracks for this package name, along with their version codes, names, release notes, and — if you have any staged rolloutsuserFraction. This value corresponds to the rollout percentage for this current track (e.g. a 10% rollout would correspond to an userFraction of 0.1).

Note: you may see an error saying "The current user has insufficient permissions to perform the requested operation", indicating a permission problem for this service account. Make sure to add email address of the service account (e.g. test-test@your.package.name-iam.gserviceaccount.com) as administrator user to the Google Play Developer Console of your app.

For our Android Bot, we’re not really that interested in all of that release information, so let’s adjust our script a bit to only fetch information for our production track, and print information regarding userFraction.

There we go. This script now prints the rollout percentage of any staged rollouts you might have on production. Let’s feed this into Slack!

Posting reminders on Slack

Thankfully, the guys and girls at Slack have also contributed to making our life easy, and provided us with a Python library for integrating with Slack.

pipenv install slackclient

We need to create a Slack App to generate an API token that we can use in our script, that is able to access our organisation and send messages there.

  1. Create a Slack App.
  2. After the app has been created, click on it to view and adjust the app’s settings.
  3. Click on “Bot users” on the left under “Features” and set up the app as a bot, to allow it to interact with users.
  4. Click on “Install app” under “Settings”, and install the app. After the app is installed in your workspace, you should see the two tokens.
Slack API tokens for Android Bot

Back to our rollout_checker.py, let’s add the Slack client to our script and include the Bot User OAuth Access Token taken from our Slack Bot settings.

Make sure you change the channel name to whatever channel you would like to use for staged rollout reminders, and don’t forget to invite your bot to this channel! 😉

Last but not least

This script should be placed somewhere where it can run at a fixed interval (for example once a day). I set it up as a cronjob in one of our servers to run Monday to Friday at 10 in the morning.

You can customise your bot through the Slack app settings, give it a colour and icon, and adjust the Slack message to include more information about the release.

That’s it! If you like what you read, don’t forget to 👏!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Sammy Odenhoven

develops apps at MyWallSt | 🎧🎶 | is always thinking about food | 🇳🇱🇮🇪

Responses (2)

Write a response