Android CI CD Pipeline with GitHub Actions and Fastlane - dhruvin207/android-common-utils GitHub Wiki

๐Ÿš€ Supercharge Your Android CI/CD Pipeline with GitHub Actions and Fastlane

This guide is your go-to resource for setting up a powerful CI/CD pipeline for your Android project using GitHub Actions and Fastlane. Weโ€™ll break down the GitHub Actions workflow, dive into Fastlane configuration, and provide clear, step-by-step instructions to get everything up and running. Let's automate and streamline your development process like a pro! ๐ŸŽ‰


Source code: AppReleaseAutomation


๐Ÿ—‚๏ธ Workflow Overview

1๏ธโƒฃ Understanding the GitHub Actions Workflow

GitHub Actions is a game-changer for automating your software development process. Hereโ€™s how to harness its power for your Android CI/CD pipeline:

1.1. ๐Ÿ” identify_environment

  • ๐Ÿ”” Trigger: Fires off whenever thereโ€™s a push to the dev or main branches.
  • ๐ŸŽฏ Purpose: Identifies whether youโ€™re deploying to a dev or prod environment based on the branch.
  • ๐Ÿ”ง Output: Sets the environment variable ENVIRONMENT to either dev or prod, guiding all subsequent steps.

1.2. ๐Ÿ› ๏ธ build_deploy

  • ๐Ÿ”— Depends On: Runs after the identify_environment job.
  • โš™๏ธ Purpose: Handles the critical build and deployment tasks.
  • ๐Ÿ” Steps:
    • ๐ŸŒ Environment Setup: Exports essential environment variables and secrets.
    • ๐Ÿ”ง System Preparation: Installs all necessary tools like Java, Ruby, Fastlane, and Firebase plugins.
    • ๐Ÿ—๏ธ Build & Deploy: Utilizes Fastlane to build your app and deploy it. Dev environments go to Firebase, while Prod goes to the Play Store.
    • ๐Ÿ›ก๏ธ Security Cleanup: Deletes sensitive files post-deployment to keep your pipeline secure.

2๏ธโƒฃ Exploring Composite Actions

Composite Actions are like mini workflows that you can reuse across multiple jobs, saving time and keeping your main workflow clean.

2.1. ๐Ÿ› ๏ธ setup.yml

  • โš™๏ธ Purpose: Prepares your environment by installing all necessary tools.
  • ๐Ÿ” Key Steps:
    • ๐Ÿ› ๏ธ Installing Java and Ruby.
    • ๐Ÿ“ฆ Downloading the latest bundletool.jar.
    • ๐Ÿš€ Updating Fastlane and installing Firebase distribution plugins.

2.2. ๐Ÿ“ฆ build_deploy.yml

  • โš™๏ธ Purpose: Manages the end-to-end build and deployment process.
  • ๐Ÿ” Key Steps:
    • ๐Ÿ› ๏ธ Building the app (APK or AAB) tailored to the environment.
    • ๐Ÿท๏ธ Extracting build metadata (e.g., package ID, version).
    • ๐Ÿš€ Deploying the app to Firebase for testing or to the Play Store for production.
    • ๐ŸŽ‰ Tagging the release on GitHub and storing relevant build artifacts.

3๏ธโƒฃ Configuring Fastlane for Android

Fastlane is your trusty assistant in automating repetitive tasks like building and releasing your app. Here's how to configure it for your pipeline:

3.1. ๐Ÿ“ Fastfile Configuration

  • Platform: Android ๐Ÿ“ฑ
  • Lanes:
    • ๐Ÿ—๏ธ build: Builds the app for dev or prod environments, applying the correct signing keys.
    • ๐Ÿš€ deploy: Deploys the built app either to Firebase for testing (dev) or to the Play Store for production (prod).

๐Ÿ› ๏ธ Step-by-Step Setup for Fastlane in Your Android Project

Step 1๏ธโƒฃ: Install Fastlane

  1. ๐Ÿ”„ Navigate to Your Projectโ€™s Root Directory:
    cd path/to/your/android/project
    
  2. ๐Ÿš€ Install Fastlane:
    sudo gem install fastlane -NV
    
  3. ๐Ÿ”ง Initialize Fastlane:
    fastlane init
    

Step 2๏ธโƒฃ: Install the Firebase Plugin

  1. ๐Ÿ“ฆ Add the Firebase App Distribution Plugin:
    bundle exec fastlane add_plugin firebase_app_distribution
    
  2. โฌ†๏ธ Update All Plugins:
    bundle exec fastlane update_plugins
    

Step 3๏ธโƒฃ: Edit Your Fastfile Configuration

Customize your Fastfile to include the build and deploy lanes that fit your project needs. You can replace or merge the configurations with your existing Fastfile setup.

Step 4๏ธโƒฃ: Setup GitHub Secrets

Ensure the following secrets are configured in your GitHub repository settings:

  • ๐Ÿ—๏ธ APP_KEYSTORE_PASSWORD_BASE64
  • ๐Ÿ—๏ธ APP_KEYSTORE_ALIAS_BASE64
  • ๐Ÿ—๏ธ APP_KEYSTORE_ALIAS_PASSWORD_BASE64
  • ๐Ÿ—๏ธ SERVICE_CREDENTIALS_CONTENT_BASE64
  • ๐Ÿ› ๏ธ APP_FIREBASE_APP_ID
  • ๐Ÿ› ๏ธ APP_FIREBASE_APP_TESTER_GROUP

Step 5๏ธโƒฃ: Trigger the Workflow

  • ๐Ÿš€ Push your changes to the dev or main branch to activate the workflow.
  • ๐Ÿ‘€ Monitor the progress under the GitHub Actions tab to ensure everything runs smoothly.

๐Ÿ“ Conclusion

By setting up this CI/CD pipeline, you're not only automating your build, test, and deployment processes but also ensuring consistency and reliability in your app delivery. This setup allows you to focus more on coding and less on deployment headaches, saving you time and reducing the risk of human error.

Donโ€™t hesitate to tweak the GitHub Actions and Fastlane configurations to better suit your projectโ€™s specific needs. Happy coding and deploying! ๐Ÿš€๐Ÿ˜Š