May 8, 2023
  • All
  • Product
  • Appflow
  • GitHub Actions
  • Ionic Cloud CLI
  • Tutorials

Automatically deploy to Google Play Store with GitHub Actions and the Ionic Cloud CLI

Cecelia Martinez

Developer Advocate

Faster and more frequent releases, better visibility, and the reduction of bottlenecks and knowledge silos are just some of the reasons to start automating your deployments to the Google Play Store with GitHub Actions.

However, getting your deployments set up in a CI/CD environment can bring its own set of headaches. In particular, managing your signing credentials, build stack, and build environment variables can be complex and require extensive DevOps expertise. Provisioning Mac hardware for iOS builds can make mistakes and inefficient runs expensive.

Fortunately, Appflow is here to make it easier with the Ionic Cloud CLI. Appflow is known for its easy-to-use dashboard for building out automated workflows. For developers and teams that need to integrate with an existing CI/CD provider – but still want to leverage Appflow for cloud native builds and app store deployments – the Ionic Cloud CLI is the perfect solution.

In this post, we’ll walk through how to set up a GitHub Actions workflow using the Ionic CLI to build and deploy a release build of an Android app to a Google Play Store internal testing track. You can view the completed workflow files at this repo.

Let’s get started!

Ionic Cloud CLI setup

The first step is setting up your Ionic Cloud CLI personal access token. You can generate a personal access token from Personal Settings > Personal Access Tokens in the Appflow dashboard. 

Note: A Scale or Enterprise plan is required to use the Ionic Cloud CLI. If you don’t currently have access, contact us to get started.

Once the token is generated, save it as a GitHub secret under Settings > Secrets and Variables > Actions for your project repository. In our example, we’ll save it as IONIC_TOKEN to reference in our GitHub Actions workflow.

GitHub Actions Workflow setup

Create a workflow file named deploy.yml under .github/workflows in your project. You can also create a new workflow file right in GitHub under Actions > New Workflow if you prefer to work in GitHub’s file editor.
Add the following to the workflow file:

name: Android Deploy to Play Store

      - 'main'

    runs-on: ubuntu-latest
      IONIC_TOKEN: ${{ secrets.IONIC_TOKEN }}
      APP_ID: '161d2d34'
      SIGNING_CERT: 'production'
      DESTINATION: 'Google Play Internal'

Here we’re doing the following:

  • Giving the workflow file a name of “Android Deploy to Play Store”. 
  • Setting the workflow to trigger on new pushes to the main branch
  • Creating a Android-Deploy job that uses a ubuntu-latest machine

Note: Using the Ionic Cloud CLI for native builds uses the Appflow runner for the build process – not your GitHub Actions runner. This means you can use Appflow for iOS builds without needing to provision a Mac machine yourself! 

We’re also setting a few environment variables that we’ll use for our native build and deploy to Google Play store.

  • The IONIC_TOKEN, which uses the GitHub Secret we set up with the personal access token
  • The APP_ID, which refers to the Appflow App ID
  • The SIGNING_CERT, which refers to the name of the signing certificate uploaded to Appflow to use for the build
  • The DESTINATION, which refers to the destination name you’ve set up in Appflow

Signing certificates and destination names are case sensitive and you’ll need to use quotes if you have spaces. You can find the App ID, signing certificate, and destination names in the Appflow Dashboard. 

Check out the documentation on setting up signing certificates and destinations in Appflow if you haven’t already set them up.

Native Builds

Now let’s set up our Ionic Cloud CLI to handle our native Android build. Add the following steps to your workflow file:

    - name: Install Ionic Cloud CLI
      run: curl -sL | bash   
    - name: Build AAB and Save Android Build ID
      id: android_build
      run: |
        ANDROID_BUILD_ID=$(ionic-cloud build android release --app-id=$APP_ID --commit=$GITHUB_SHA --signing-cert=$SIGNING_CERT  --aab-name=app.aab --json --token=$IONIC_TOKEN | jq -r ".buildId")
    - name: Upload AAB
      uses: actions/upload-artifact@v3
        name: Signed AAB
        path: ./app.aab

The first step is installing the Ionic Cloud CLI. This should take less than a second and have no impact on your build time. 

In the next step, we’re using the ionic-cloud build android command to generate a native binary. This step has an id set to android_build. This is so we can use the output from this step later in our workflow. We’re passing the following flags to this command:

  • release designates the build type
  • --app-id designates the Appflow app ID, which we’re setting using our environment variable
  • --commit designates the commit SHA to use for the build, using the built-in $GITHUB_SHA environment variable for the push that triggered the workflow
  • --signing-cert designates the signing certificate uploaded in Appflow to use for the build, also set using our environment variable
  • --aab-name designates to download the generated .aab binary and gives it the specified name
  • --json sets the command output as json format
  • --token passes through your Appflow personal access token, also set using our environment variable

You may have noticed there is no code checkout step. This is because Appflow is connected to your Git repo and checks out the code for you on our own runners. This makes your workflow even faster, using less GitHub Actions machine time.

The next part of the command uses the jq utility (built in automatically on GitHub Linux runners) to grab the .buildId property output by the Ionic Cloud CLI. The ANDROID_BUILD_ID=$() syntax wrapped around the command then saves the build ID as a temporary variable.

The next line sets this value to the output for this step, using GitHub Action’s built-in $GITHUB_OUTPUT variable.

Finally, the last step uses the upload-artifact GitHub Action to save the .aab binary in GitHub Actions. This is optional – the binary is also available to download for your entire team from the build log in Appflow.

Ionic Cloud CLI Docs

In the native build command, we’re passing multiple flags and also using the output from the command. There are many options provided by the Ionic Cloud CLI, and a new documentation architecture makes it easier to identify which flags and output values to use in your own workflow.

Included in the docs update are collapsible output tables of all the values you can leverage for your workflow. Depending on the command, this could include the build ID, build status, or even details such as what environment variables were used.

There are also more examples to illustrate expected output in both text and JSON formats so you can design a workflow that makes sense for your team.

Example command output in JSON and Text formats (drag slider to compare)

Other enhancements include breadcrumbs to easily navigate pages in the docs, as well as a new search function to find what you’re looking for fast.

Deploy to Google Play Store

Because we were able to easily identify and save the output Android build ID, we can now pass that directly into our deploy command. Add the following step to your workflow file:

- name: Deploy to Play Store
      run: ionic-cloud deploy android --app-id=$APP_ID --build-id=${{ steps.android_build.outputs.ANDROID_BUILD_ID }} --destination="$DESTINATION" --token=$IONIC_TOKEN

In this step, we’re using the ionic-cloud deploy android command, passing in the build-id using the output from the previous step with the ID of android_build. We’re also using the $DESTINATION and $IONIC_TOKEN environment variables to authenticate our Appflow account and designate the correct Google Play Store Destination.

We now have a completed workflow file that will run on any push to the main branch!

After the successful run, the .aab file is accessible in GitHub Actions or the Appflow dashboard. The Dashboard also shows the build log for visibility and debugging.

And, we can see that the newest version of our app has been automatically uploaded to the Google Play Store and is ready to release to our internal testers!

You can view the completed workflow file on GitHub here.

Next steps

Thanks to the Ionic Cloud CLI, we have a completely automated workflow for our native builds and deploys. 

Note: The example repo also auto-increments the Android build ID using the build number for Appflow using Trapeze. Check out an example here.

This is just one example of how the Ionic Cloud CLI and Appflow can help you integrate mobile deployments into your existing CI/CD infrastructure. To learn more about the Ionic Cloud CLI and request access, contact our team today.

Cecelia Martinez

Developer Advocate