Setting up a continuous integration and delivery (CI/CD) pipeline is crucial for scaling your development and release process as your team grows. As your Android app's popularity increases, you'll need to automate the build and deployment process to ensure consistency, reliability, and quality. In this article, we'll guide you through setting up a CI/CD pipeline using fastlane and GitHub Actions in just 30 minutes.

Why GitHub Actions?

GitHub Actions has become a popular choice for CI/CD providers since its launch in 2018. One of the key benefits is its seamless integration with GitHub, making it easy to manage your version control tool alongside your CI/CD interface. Additionally, the GitHub Marketplace offers a wide range of community-built actions that simplify workflow setup.

Setting Up Your CI/CD Pipeline

To get started, you'll need to install fastlane and set up your Fastfile. Then, configure your secrets in GitHub's encrypted secrets and create a basic GitHub Actions workflow YAML file. Finally, run your build!

Install fastlane and Set Up Your Fastfile

Fastlane is a Ruby library designed to automate common mobile development tasks. You can use it to configure custom "lanes" that bundle actions that perform tasks you'd normally do using Xcode or xcodebuild. For this tutorial, we'll focus on just a few core actions.

Install fastlane using one of the recommended methods, such as running brew install fastlane from your main app project directory. Then, run fastlane init and enter your package name when prompted. You can skip past any other prompts.

You'll end up with a fastlane directory containing a Fastfile, an Appfile, and a Gemfile and Gemfile.lock if they didn't already exist in your project.

Next, install a plugin that we'll use to automate version code increments. Run the following command from your app's root directory:

This will install the fastlane-plugin-increment_version_code plugin that we'll use in a custom lane from our Fastfile. It will also create a Pluginfile file in your fastlane directory and update your Gemfile.

Modify Your Fastfile

Open up your Fastfile and take a look at what actions have already been added to it by default. You'll notice that the Fastfile includes three lanes: test, beta, and deploy. Delete the beta lane (we won't be uploading to Firebase in this tutorial) and modify the deploy lane as shown:

The extra parameters passed to the gradle action will allow us to build a signed release .aab, while the upload_to_play_store action will use an Android service account key to authenticate with the Google Play Developer API and upload our signed build to the Play Console's internal track. We also added a new fetch_and_increment_build_number action that will fetch the latest version code from the Play Console and increment it locally using the plugin action.

Storing Your Secrets in GitHub Encrypted Secrets

To authenticate with the Google Play Developer API, we'll need a service account key. Store this sensitive information securely in repository secrets, making it automatically accessible to your GitHub Actions workflows and Fastfile when needed.

In this article, we've covered one way you can autogenerate a complete build & deploy pipeline built on GitHub Actions and fastlane using a free tool. With step-by-step tutorials and clear instructions, we hope to make your team's transition to a smooth CI/CD pipeline seamless and pain-free.