Skip to content

4. CI CD Setup with GitHub Actions

Tamer Hamad Faour edited this page Nov 25, 2024 · 1 revision

Continuous Integration and Deployment (CI/CD) with GitHub Actions

Introduction

This guide explains how to set up Continuous Integration and Deployment (CI/CD) for your project using GitHub Actions. CI/CD ensures that your code is tested and deployed automatically, streamlining your development workflow.

GitHub Actions for Continuous Integration

The project leverages GitHub Actions to automate testing and deployment tasks.

Workflow File

The .github/workflows/main.yml file defines the CI/CD pipeline:

  • Build Docker container: Ensures a consistent runtime environment.
  • Run tests using pytest: Validates code functionality with automated tests.
  • Deploy to production: Automatically deploys to production if all tests pass successfully.

Example GitHub Action Workflow:

name: CI Workflow

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      - name: Install dependencies
        run: |
          pip install -r requirements.txt

      - name: Run Tests
        run: |
          pytest
Clone this wiki locally