Skip to content

4 Continuous Integration (CI)

CarlosSouza87 edited this page Jun 5, 2023 · 1 revision

☄️ Continuous Integration (CI)

⚙️ Continuous integration is the practice of automating the integration of code changes from multiple contributors into a single software project. It’s a primary DevOps best practice, allowing developers to frequently merge code changes into a central repository where builds and tests then run. Automated tools are used to assert the new code’s correctness before integration. A source code version control system is the crux of the CI process. The version control system is also supplemented with other checks like automated code quality tests, syntax style review tools, and more.

We configure our CI (Continuous Integration) based on our project requirements using GitHub Actions, a native tool of GitHub. We have set up two CI workflows, one for the front-end and another for the back-end, ensuring that certain steps are validated before merging the code.

CI Front-End

Our CI file

name: Vue.js CI

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: npm install
      - name: Build
        run: npm run build
      - name: Test
        run: npm run test  
  

The "Vue.js CI" workflow is triggered on both push events to any branch and pull requests targeting the "main" branch. It consists of a single job named "build" that runs on an Ubuntu operating system.

The job includes the following steps:

"Checkout code": This step checks out the source code from the repository. "Install dependencies": This step installs the project dependencies using npm. "Build": This step builds the Vue.js project using the specified build command (npm run build). "Test": This step runs the tests for the Vue.js project using the specified test command (npm run test). By configuring these steps, the CI workflow ensures that the code is built successfully and passes the defined tests during the CI process.

CI Back-End

Our CI file

name: Python application

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'

permissions:
  contents: read

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python 3.10
        uses: actions/setup-python@v3
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: Lint with flake8
        run: |
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
          flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
      - name: Sort imports with isort
        run: |
          isort .
      - name: Test with pytest
        run: |
          pytest
  

The "Python application" workflow is triggered on both push events to any branch and pull requests targeting any branch. It grants read permissions to access the contents of the repository. The workflow includes a single job named "build" that runs on an Ubuntu operating system.

The job consists of the following steps:

"Checkout": This step checks out the source code from the repository. "Set up Python 3.10": This step sets up the Python environment and installs Python version 3.10. "Install dependencies": This step upgrades pip and installs the project dependencies listed in the requirements.txt file. "Lint with flake8": This step performs linting on the source code using flake8 and displays statistics and source code issues. "Sort imports with isort": This step sorts imports in the source code using isort. "Test with pytest": This step is left incomplete. You would need to add the command(s) to run your tests with pytest in this section. By configuring these steps, the CI workflow sets up the Python environment, installs dependencies, performs linting, sorts imports, and is intended to run tests using pytest. This helps ensure the quality and correctness of the Python application during the CI process.

Both CI configurations utilize GitHub Actions as the CI/CD tool, allowing for automation and validation of key steps in the development process. By incorporating these CI workflows into the project, developers can ensure that changes are tested, validated, and meet the necessary requirements before merging them into the main codebase. This improves the overall reliability and stability of the software being developed.

Clone this wiki locally