Continuous Integration Testing Tool ‐ Github Actions - JUCSE49-Mavericks/Smart-Class-Routine-Management-System GitHub Wiki

GitHub Actions CI Setup for JavaScript Project

Author: Trisha Sarkar

What is GitHub Actions?

GitHub Actions is an automation tool integrated with GitHub that allows you to build, test, and deploy code automatically based on events like pushes or pull requests. It is perfect for setting up Continuous Integration (CI) and Continuous Deployment (CD) pipelines.

What is Continuous Integration (CI)?

Continuous Integration (CI) is a software development practice where code changes are automatically tested and integrated into the shared codebase frequently. This ensures that errors or conflicts are caught early.

Installation

Prerequisites

  • Node.js: Ensure you have Node.js installed. You can download it from here.

Navigate to your project directory using the terminal.

Install npm dependencies (specified in your package.json file):

Install mocha-chai for testing

Project Structure

Your project should have the following structure:

  • module1.test.mjs: Contains tests for the features and functions of module1.mjs.
  • module2.test.mjs: Contains tests for the features and functions of module2.mjs.
  • module3.test.mjs: Contains tests for the features and functions of module3.mjs.
  • package.json: Project's package configuration file.
  • .github/workflows/ci.yml: The GitHub Actions CI configuration file.

2. Create Module Files

You need to create three JavaScript module files: module1.js, module2.js, and module3.js.

module1.js

module2.js

module3.js

3. Set up tests for each module

Next, create the test files in the tests/ directory to ensure each module works correctly using Jest.

tests/module1.test.mjs

tests/module2.test.mjs

tests/module3.test.mjs

4. Configure package.json file

Make sure your package.json contains the necessary scripts to run each module's tests individually as well as collectively.

5. Set Up GitHub Actions for CI

Create the GitHub Actions configuration file to set up continuous integration. The file is located at .github/workflows/ci.yml.

6. Testing CI Success

1. Run test for module1:

2. Run test for module2:

3. Run test for module3:

1. Run all tests:

CI Testing

Once you've pushed your changes to the main branch, GitHub Actions will automatically run the tests. You can view the results in the Actions tab of your GitHub repository.

Why Github Actions?

Advantages of Github Actions

1. Tightly integrated with GitHub: Easy setup and workflow creation within the GitHub ecosystem.

2. No external tools needed: Unlike CircleCI or Semaphore, you don’t need to rely on third-party CI tools.

3. Free for public repositories: GitHub Actions offers generous free-tier minutes for open-source projects.

4. Parallel workflows: Supports running multiple jobs (like tests) simultaneously.


Disadvantages of GitHub Actions

  • Limited Free Minutes for Private Repositories: GitHub Actions provides only 2,000 minutes/month for private repositories, which may not be sufficient for projects with heavy CI/CD usage.

  • Complexity for Advanced Workflows: Managing complex workflows with multiple jobs and conditional logic can become challenging, especially without detailed documentation.

  • Lack of Advanced Analytics: Compared to CI platforms like CircleCI, GitHub Actions does not provide detailed build insights or performance analytics.

  • Slower Support Response: Official GitHub support can be slow, making it harder to resolve issues quickly compared to CI platforms with dedicated support teams.

  • Learning Curve for YAML Configurations: YAML-based workflow files, though flexible, can be hard to set up for beginners, especially for advanced configurations.


CI/CD Tools Comparison: GitHub Actions vs CircleCI vs Semaphore

Below is a comparison table outlining the key differences between GitHub Actions, CircleCI, and Semaphore based on various factors such as pricing, ease of use, integration, and more.

Feature GitHub Actions CircleCI Semaphore
Integration Built-in with GitHub, seamless integration with GitHub repositories and PRs Integrates with GitHub and Bitbucket Integrates with GitHub
Free-Tier (Public Repos) Unlimited usage for public repositories Unlimited builds for open-source repositories Unlimited for open-source projects
Free-Tier (Private Repos) 2,000 minutes per month (combined across jobs) 2,500 credits per week for free-tier 3,000 minutes per month for free-tier
Paid Plans $0.008 per minute after free-tier minutes used Paid based on credits; custom plans available Paid based on minutes used; custom plans
Ease of Use Simple for basic workflows, more complex for advanced workflows Easy to use for both simple and advanced pipelines Simple setup for parallel and sequential workflows
Workflow Complexity Can get complex for advanced multi-job workflows Good for complex workflows with detailed documentation Easy to manage complex workflows with clear documentation
Documentation Good for basic workflows, lacks details for advanced cases Extensive documentation and tutorials available Clear documentation, especially for advanced setups
Parallelism Supports parallel jobs with custom workflows Supports parallel jobs and builds across multiple containers Excellent parallelism support with clear scaling options
Speed Fast for simple builds, can slow down with complex workflows Generally fast, especially with container caching Very fast and optimized for parallel jobs
Customization High level of customization with YAML workflows Highly customizable with workflow visualizer Highly customizable with intuitive YAML syntax
Docker Support Full Docker support Full Docker support Full Docker support
Third-Party Integrations Integrates with popular third-party apps via GitHub Marketplace Supports many integrations via API and orbs Limited third-party integrations
Analytics and Insights Basic insights with no in-depth analytics Detailed analytics, build time, and performance insights Good insights and performance data
Community and Support Large GitHub community, but support can be slow Extensive community support and faster response times Smaller community but dedicated support
Best For Developers using GitHub for both code and CI/CD Teams looking for robust, scalable CI/CD options Teams seeking fast, parallel, and highly customizable pipelines

Key Takeaways:

  • GitHub Actions is best suited for developers already using GitHub who want seamless CI/CD integration. It offers a good free-tier for public repositories but has limitations for private repos.
  • CircleCI is ideal for teams that need scalability and detailed analytics for complex workflows, with great support for Docker and parallel builds.
  • Semaphore excels in fast build times and is highly optimized for parallelism, making it a good choice for teams with complex, performance-focused CI/CD pipelines.