Using Appflow CLI with GitHub actions
Appflow CLI is available to our enterprise customers only. Please contact us for more information.
Introduction
You can utilize Live Updates, Native Builds, and Deploy to App Stores from the Appflow CLI inside a GitHub Actions workflow.
This example will walk you through setting up a workflow in GitHub Actions that takes your latest commit, performs an Android Release build, saves the .aab
to GitHub Actions as an artifact, and then pushes it directly to the Play Store Console to an Internal Testing Track.
Requirements
For this example, we've already done the following in our Appflow dashboard:
- Set up a Personal Access Token
- Connected our GitHub Repo to an Appflow app
- Created a Signing Credential for Android and added to Appflow with the name "production"
- Added an Play Store Destination as "Google Play Internal"
Setup Personal Access Token as GitHub Secret
Navigate to Settings > Secrets and Variables > Actions in your project repository in GitHub and click 'New repository secret'.
Save your personal access token from the Appflow dashboard as a new secret named 'IONIC_TOKEN'.
Creating the Workflow
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.
Full .yml Workflow File
name: Android Deploy to Play Store
on:
push:
branches:
- 'main'
jobs:
Android-Deploy:
runs-on: ubuntu-latest
env:
IONIC_TOKEN: ${{ secrets.IONIC_TOKEN }}
APP_ID: 'AppId123'
SIGNING_CERT: 'production'
DESTINATION: 'Google Play Internal'
steps:
- name: Install Appflow CLI
run: curl -sL https://ionic.io/get-appflow-cli | bash
- name: Build AAB and Save Android Build ID
id: android_build
run: |
ANDROID_BUILD_ID=$(appflow 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")
echo "ANDROID_BUILD_ID=$ANDROID_BUILD_ID" >> $GITHUB_OUTPUT
- name: Upload AAB
uses: actions/upload-artifact@v3
with:
name: Signed AAB
path: ./app.aab
- name: Deploy to Play Store
run: appflow deploy android --app-id=$APP_ID --build-id=${{ steps.android_build.outputs.ANDROID_BUILD_ID }} --destination="$DESTINATION" --token=$IONIC_TOKEN
Initial Setup
Let's walk through the workflow file step-by-step.
name: Android Deploy to Play Store
on:
push:
branches:
- 'main'
jobs:
Android-Deploy:
runs-on: ubuntu-latest
First we give the workflow a name, and designate the trigger. In this example, the workflow will trigger on every push to the main
branch.
We're then defining a job called 'Android-Deploy' that runs on ubuntu-latest
. This is an Android build, but even for iOS builds, Mac hardware is not needed. Appflow manages the runner and build stack for your cloud native builds.
env:
IONIC_TOKEN: ${{ secrets.IONIC_TOKEN }}
APP_ID: 'AppId123'
SIGNING_CERT: 'production'
DESTINATION: 'Google Play Internal'
In this next section, we're defining some GitHub Actions environment variables, including the IONIC_TOKEN
that we added as a GitHub Secret. We're also setting APP_ID
, SIGNING_CERT
, and DESTINATION
variables to make it easier to update values being passed to commands in the workflow.
Installing the Appflow CLI
The first step in the job installs the CLI. This takes a second or less and gives us the commands needed to interact with Appflow.
steps:
- name: Install Appflow CLI
run: curl -sL https://ionic.io/get-appflow-cli | bash
Performing an Android Build
Next we'll define a step to perform our Android release build.
- name: Build AAB and Save Android Build ID
id: android_build
run: |
ANDROID_BUILD_ID=$(appflow 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")
echo "ANDROID_BUILD_ID=$ANDROID_BUILD_ID" >> $GITHUB_OUTPUT
Here we’re using the appflow 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
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
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
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 Appflow CLI. The ANDROID_BUILD_ID=$()
syntax wrapped around the command then saves the build ID as a temporary variable.
The last line of this step sets this value to the output for this step, using GitHub Action’s built-in $GITHUB_OUTPUT
variable.
- name: Upload AAB
uses: actions/upload-artifact@v3
with:
name: Signed AAB
path: ./app.aab
The next step uses the upload-artifact
GitHub Action to save the .aab
binary in GitHub Actions. This is optional – the binary is also available from the build log in Appflow.
Deploy to Google Play Store
In the last step of the workflow, we'll use the appflow deploy android
command, using the ANDROID_BUILD_ID
output from the android_build
step to deploy to our 'Google Play Internal' destination.
- name: Deploy to Play Store
run: appflow deploy android --app-id=$APP_ID --build-id=${{ steps.android_build.outputs.ANDROID_BUILD_ID }} --destination="$DESTINATION" --token=$IONIC_TOKEN
Run Workflow
Push the completed workflow file to your main branch to enable the GitHub Action. Now, whenever a new push is initiated to main, the workflow will run.
Next Steps
This was an example of an Android release build and deploy, but you can also use GitHub Action and the Appflow CLI for iOS builds and deploys, as well as live updates to Ionic/Capacitor and Portals apps.
See documentation for other commands or run appflow --help
to learn more about what functions are available in the Appflow CLI.