MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

A Detailed Guide to CI/CD with GitHub Actions

Continuous Integration (CI) and Continuous Deployment (CD) are modern software development practices that automate the process of integrating code changes, running tests, and deploying applications. With the rise of automation in the development process, CI/CD pipelines have become a crucial part of modern DevOps workflows.

GitHub Actions is a feature in GitHub that enables you to automate your software development workflows directly from your GitHub repository. It allows you to create CI/CD pipelines and automate tasks like running tests, deploying to production, and managing code releases. In this blog, we’ll explore how to set up and use GitHub Actions for CI/CD, focusing on automating tasks such as building packages for Laravel and Android apps.

What is CI/CD?

CI/CD stands for Continuous Integration and Continuous Deployment (or Delivery). Here’s a brief breakdown of the two processes:

  • Continuous Integration (CI): This process involves regularly merging code changes into the main branch of a repository. CI ensures that new code integrates smoothly with the existing codebase by automatically running tests, checks, and builds.
  • Continuous Deployment (CD): Once code passes the CI phase, it is automatically deployed to a production environment. This process ensures that the latest code changes are always available to users, reducing the time between development and release.

Why Use GitHub Actions for CI/CD?

GitHub Actions offers a seamless way to automate CI/CD pipelines within your GitHub repository. It’s tightly integrated with the GitHub ecosystem, making it easier to set up and manage. Here are some key benefits:

  • Free for public repositories: GitHub Actions provides free CI/CD for public repositories with a generous limit for private repositories.
  • Custom workflows: GitHub Actions allows you to create custom workflows tailored to your needs, such as running tests on every commit or automatically deploying to production after every successful merge.
  • Easy configuration: The workflows are defined in YAML files, which are easy to configure and read.
  • Integration with other services: You can integrate GitHub Actions with other services such as Docker, Kubernetes, and cloud platforms like AWS, Azure, or Google Cloud.

Setting Up GitHub Actions for CI/CD

To get started with GitHub Actions, you’ll need a GitHub repository with a basic project structure. Let’s walk through how you can set up CI/CD pipelines for both a Laravel project (for backend development) and an Android app (for mobile app development).

1. Setting Up CI/CD for a Laravel Project

Laravel is a popular PHP framework, and using GitHub Actions for CI/CD with Laravel allows you to automate testing, linting, and deployment.

Step 1: Create a GitHub Actions Workflow File

In your Laravel project, create a .github/workflows/ci.yml file. This file will contain the workflow for CI/CD.

name: Laravel CI/CD Workflow

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      
    - name: Set up PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        
    - name: Install dependencies
      run: |
        composer install --no-progress --prefer-dist

    - name: Run tests
      run: |
        ./vendor/bin/phpunit

    - name: Deploy to production
      if: success() # Deploys if tests pass
      run: |
        echo "Deploying to production..."
        # Add your deployment scripts here
Step 2: Add Secrets for Deployment

If you are deploying to a server or cloud service, you may need to set up secrets in GitHub for credentials such as API keys, SSH keys, etc. Go to your repository’s Settings > Secrets and add any necessary secrets (e.g., DEPLOY_KEY).

Step 3: Test the Workflow

Once the workflow file is set up, GitHub Actions will automatically trigger it on every push or pull request to the main branch. You can view the results in the Actions tab of your GitHub repository.

2. Setting Up CI/CD for an Android Project

For Android projects, you can use GitHub Actions to automate tasks like building APKs or AABs (Android App Bundles), running tests, and uploading to the Play Store or a testing platform.

Step 1: Create a GitHub Actions Workflow for Android

In your Android project, create a .github/workflows/android.yml file. This file will define your CI/CD pipeline for Android.

name: Android CI/CD Workflow

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'

    - name: Set up Gradle
      uses: gradle/wrapper-validation-action@v1

    - name: Build the APK
      run: ./gradlew assembleRelease

    - name: Run tests
      run: ./gradlew test

    - name: Deploy to Google Play
      if: success()
      run: |
        echo "Deploying to Google Play..."
        # Add the deployment script to upload to Play Store (can use tools like fastlane)
Step 2: Use Fastlane for Deployment

You can automate Android app deployment using Fastlane, which integrates with GitHub Actions. Fastlane allows you to upload your APK or AAB to the Google Play Store directly from your CI/CD pipeline.

Install Fastlane on your system and add the necessary configurations to your workflow for automated deployment. You’ll need to set up secrets such as the KEYSTORE_PASSWORD and Google Play API credentials in the Secrets section of your GitHub repository.

Step 3: Test the Workflow

When you push changes to the main branch or open a pull request, GitHub Actions will trigger the workflow to build the APK, run the tests, and deploy the app to the Google Play Store if the tests pass.

3. Exploring the Benefits of GitHub Actions for CI/CD

Using GitHub Actions for CI/CD offers several key advantages:

  • Automation of Routine Tasks: CI/CD pipelines automate repetitive tasks such as building, testing, and deploying code, saving valuable developer time.
  • Faster Feedback: By automating tests, you get instant feedback about the health of your application, making it easier to identify issues before they reach production.
  • Seamless Integration: GitHub Actions integrates with other tools in the GitHub ecosystem and can be extended to work with external services, such as AWS, Azure, Docker, and Kubernetes.
  • Scalability: GitHub Actions supports both small and large projects, offering flexible scaling options.

4. Conclusion

GitHub Actions provides a powerful, flexible platform for automating your CI/CD pipelines directly from your GitHub repositories. Whether you’re working on a Laravel backend or an Android mobile app, GitHub Actions can streamline your development workflow by automating the building, testing, and deployment processes. By integrating GitHub Actions into your workflow, you can achieve faster releases, more stable code, and improved collaboration within your development team.

Start integrating GitHub Actions into your projects today and enjoy the benefits of automation!


Further Reading

Related Posts

Why You Need HashiCorp Terraform Training for Your Career

Terraform lets teams build and change cloud setups safely using code files. The HashiCorp Terraform training & certification program gives 15 hours of hands-on to master IaC basics for…

How to Become a Google Cloud Professional DevOps Engineer

Google Cloud grows fast as a top cloud choice, but mastering its DevOps needs real skills. The Google Cloud Professional Engineer training gives 50-60 hours of hands-on to build…

Start Your Journey with GitOps Essential Training Today

GitOps makes putting apps on Kubernetes simple and safe by using Git as the main guide. The GitOps Essential Training shows you how to set up auto deploys with…

Your Guide to Earning the FinOps Foundation Certification

Cloud spending can grow fast without good control, but smart management keeps costs in check. The FinOps Foundation Certification teaches simple ways to track, cut waste, and plan budgets…

Your Guide to ISTIO and Envoy Certification Training Success

Service meshes like Istio make handling traffic between apps easy and safe. The ISTIO Envoy Certification Training teaches you to control routing, security, and monitoring without changing your code.​…

Docker Certified Associate: Your Complete Guide to Success

Containers change how teams build and run apps smoothly across any setup. The Docker Certified Associate certification gives you the skills to handle Docker like a pro, fixing the…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x