What is CI/CD?
CI: Continuous Integration
CD: Continuous Delivery or Deployment
CI/CD enhances the software development life cycle:
Continuous Integration: Developers merge code frequently to a central repository.
Continuous Delivery: A review step occurs before deployment.
Continuous Deployment: Automates deployment directly after integration.
Key Concepts Discussed
Software Development Workflow
Development → Testing → Deployment.
CI/CD ensures automation, validation, and efficiency.
CI/CD Workflow Breakdown
Event Trigger: A push, pull request, or manual event initiates the workflow.
Jobs: Tasks like code build, test, and deployment.
Environment: Uses runners (Ubuntu, Windows, or macOS) to execute workflows.
Steps: Detailed commands executed sequentially.
Artifacts: Generated build files (e.g., APK).
Creating a CI/CD Pipeline Using GitHub Actions
Step-by-step process for Android projects:
Setup GitHub Repository: Push Android project code to a repository.
Define Workflow Directory:
.github/workflows/
Create Workflow File: Use
.yml
format to define commands and jobs.
Writing the Workflow (YAML File)
Define events:
- Trigger on
push
andpull_request
for themaster
branch.
- Trigger on
Jobs:
Environment: Ubuntu runner.
Steps:
Checkout the latest code using GitHub Actions.
Set up the Java Development Kit (JDK) environment.
Build the project using Gradle (
./gradlew build
).Upload the generated APK as an artifact.
Error Handling and Debugging
Debugging missing paths for APK files.
Correct setup for Java version (Java 17).
Ensuring proper artifact upload paths.
Final Verification
Successful CI/CD pipeline execution in GitHub Actions.
Downloading the generated APK for testing or release.
Refer below code snap to implement CI/CD in you’re projects:
codename: AndroidBuild
on:
pull_request:
branches: [ master ]
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4.1.0
- name: Set Up Java JDK
uses: actions/setup-java@v3.13.0
with:
java-version: '17'
distribution: 'adopt'
- name: Grant Execute Permission for Gradlew
run: chmod +x ./gradlew
- name: Clean and Build with Gradle
run: ./gradlew clean build
- name: Upload Build Artifact
uses: actions/upload-artifact@v3.1.3
with:
name: AndroidDemo.apk
path: app/build/outputs/apk/debug/app-debug.apk