Continuous Integration Pipeline GitHub Actions - shanjida-alam/Smart-Living-Community GitHub Wiki
Continuous Integration for Smart Living Community Using GitHub Actions
1. Introduction
In the modern software development lifecycle, the ability to deliver high-quality software quickly and efficiently is essential. Continuous Integration (CI) plays a vital role in this process by automating the build and testing of applications after every code change. This report details the steps involved in setting up Continuous Integration for Smart Living Community (Which is a Java + XML project) using GitHub Actions and Gradle as the build tool.
2. Objective
The primary objectives of this report are:
To understand what Continuous Integration (CI) is and why it is needed.
To provide a step-by-step guide for setting up CI for the Smart Living Community project using GitHub Actions.
To troubleshoot common issues encountered during the CI setup process.
3. What is Continuous Integration?
Continuous Integration (CI) is a software development practice where developers frequently merge their code changes into a shared repository, preferably several times a day. Each integration is then automatically built and tested. The main goals of CI are to detect problems early, improve software quality, and reduce the time it takes to validate and release new software updates.
Fig 1: Continuous Integration Pipeling in GitHub Actions
4. Why Do We Need Continuous Integration?
Continuous Integration ensures that code changes introduced by multiple developers are tested and integrated seamlessly into the shared codebase. It minimizes the risk of integration issues by running automated tests every time code is committed.
An Example Scenario in development phase
Imagine a development team working on an Android application. Developer A pushes a feature to the repository, and without proper integration, Developer B's code could break Developer A's feature. With CI in place, the project is automatically built and tested for every code change, helping the team catch potential issues early. This automated approach helps in delivering better software faster.
5. What is a .yml File?
A .yml (YAML) file is a configuration file format used in many automation tools, including GitHub Actions. YAML stands for "YAML Ain't Markup Language," and it is a human-readable data serialization format that is often used to write configuration files. In the context of GitHub Actions, .yml files are used to define workflows, specifying the steps and actions to be performed in the automation process, such as building and testing applications.
YAML files rely on indentation to define structure, and the syntax is easy to read and write.
Fig 2: .yml File Workflow
6. Prerequisite
Before setting up Continuous Integration for the Smart Living Community project, make sure you have the following:
A GitHub repository containing the Smart Living Community Android project.
Basic understanding of GitHub, GitHub Actions, and Gradle.
Java Development Kit (JDK) version 17 or later.
7. Guide to setup CI with GitHub Actions
Step 1: Open Your GitHub Repository
Navigate to your GitHub repository for the Smart Living Community project.
Fig 3: Initial Github repo for the main branch
Step 2: Navigate to Actions Tab
Click on the Actions tab located at the top of the repository page.
Fig 4: Github Action Navigation
Step 3: Set Up a New Workflow
Inside the Actions tab, GitHub will suggest workflows based on project type. Now,
Search with "java with gradle" as shown in the screenshot and click Configure.
GitHub automatically creates a new workflow configuration .yaml file.
Fig 5: Setup Java with Gradle Config
Step 4: Review and Edit the Workflow YAML
The default Java with Gradle workflow might look like this:
name: Java CI with Gradleon:
push:
branches: [ "main" ]pull_request:
branches: [ "main" ]jobs:
build:
runs-on: ubuntu-latestpermissions:
contents: readsteps:
- uses: actions/checkout@v4
- name: Set up JDK 17uses: actions/setup-java@v4with:
java-version: '17'distribution: 'temurin'
- name: Ensure Gradle Wrapper is Executablerun: chmod +x ./gradlew
- name: Setup Gradleuses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582
- name: Build with Gradle Wrapperrun: ./gradlew builddependency-submission:
runs-on: ubuntu-latestpermissions:
contents: writesteps:
- uses: actions/checkout@v4
- name: Set up JDK 17uses: actions/setup-java@v4with:
java-version: '17'distribution: 'temurin'
- name: Generate and submit dependency graphuses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582
Review the workflow and make changes if necessary. The default configuration should be sufficient for most Java Gradle projects.
Fig 6: Workflow config (yml) Editor page
Step 5: Commit the Workflow
Once you're satisfied with the configuration, click Start commit.
Choose to either commit directly to the master branch or create a new branch and submit a pull request.
Fig 7: Commit the workflow config (yml) file and select new branch for it
Step 6: Verify the Workflow Execution
After committing, navigate back to the Actions tab. You should see the newly created workflow listed.
Fig 8: After hitting Propose Changes (Shown in Fig 7) button, you can navigate Actions to see newly created workflow list
Every time you push code or submit a pull request to the master branch, the workflow will be triggered.
Click on the workflow run to view the logs and see if the build was successful or if it failed.
Fig 9: Running the workflow for the jobs after merging the main branch
Step 7: View the Build Results
Once the workflow completes, you can review the build logs to check for success or failure. GitHub Actions provides detailed logs, which can help you troubleshoot any issues during the build process.
Fig 10: Build Summary after running and executing all jobs
8. Common Issue Fix: Permissions for Gradle Wrapper
In some cases, you may encounter a permissions issue with the Gradle wrapper (./gradlew: Permission denied). This is caused by missing executable permissions for the Gradle wrapper.
Typical Fix:
Modify your workflow file to add a step that ensures the Gradle wrapper has executable permissions:
- name: Ensure Gradle Wrapper is Executablerun: chmod +x ./gradlew
Add this step before running the build command in your workflow.
Fig 11: Add the selected line in .yml file
Fig 12: After adding the line shown in Fig 10, now click on Re-run all jobs as depicted
9. Conclusion
In this report, we covered Continuous Integration (CI) Pipeling basics and how to set it up using GitHub Actions for the Smart Living Community project. CI automates the process of building and testing your application, ensuring that integration issues are caught early, thus helping deliver higher-quality software faster. By following the step-by-step guide, you can now ensure that your Smart Living Community project is continuously built and tested with every code change.