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! ๐
AppReleaseAutomation
Source code:๐๏ธ 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:
identify_environment
1.1. ๐ - ๐ Trigger: Fires off whenever thereโs a push to the
dev
ormain
branches. - ๐ฏ Purpose: Identifies whether youโre deploying to a
dev
orprod
environment based on the branch. - ๐ง Output: Sets the environment variable
ENVIRONMENT
to eitherdev
orprod
, guiding all subsequent steps.
build_deploy
1.2. ๐ ๏ธ - ๐ 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, whileProd
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.
setup.yml
2.1. ๐ ๏ธ - โ๏ธ 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.
build_deploy.yml
2.2. ๐ฆ - โ๏ธ 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:
Fastfile
Configuration
3.1. ๐ - Platform: Android ๐ฑ
- Lanes:
- ๐๏ธ
build
: Builds the app fordev
orprod
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
- ๐ Navigate to Your Projectโs Root Directory:
cd path/to/your/android/project
- ๐ Install Fastlane:
sudo gem install fastlane -NV
- ๐ง Initialize Fastlane:
fastlane init
Step 2๏ธโฃ: Install the Firebase Plugin
- ๐ฆ Add the Firebase App Distribution Plugin:
bundle exec fastlane add_plugin firebase_app_distribution
- โฌ๏ธ 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
ormain
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! ๐๐