Giter Club home page Giter Club logo

week1-devops's Introduction

Week 1 - Project

Goal

To Establish a Robust and Reliable Development process by settting version control using Git, implementing comprehensive Unit Tests, and setting up effective workflows to ensure that only properly tested code is merged from other branches into the Master branch.

Requirements


Link to setup Python 3.9 - https://www.python.org/downloads/

Link to setup Git the first time - https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

Use a Editor of your choice

Link to get pip3 - https://pip.pypa.io/en/stable/installation/

Step 1 - Get the inital start code onto your system

Git clone initial code from this Github Repo - https://github.com/vj-m/week1-devops/tree/initial_starter_code

git clone [email protected]:vj-m/week1-devops.git

Step 2 - Add Unit Tests

def test_add():
    assert add(1,1) == 2

def test_sub():
    assert sub(1,1) == 0

def test_mul():
    assert mul(1,1) == 1

def test_div():
    assert div(2,1) == 2

Step 3 - Create a workflow

1.) Create a directory called .github/workflows within the directory containing .git 2.) And create a workflow ‘YAML’ file, let's call it ci_cd_wf.yml 3.) Git add and push changes (This automatically invokes the Git actions and sets up the CI/CD Pipeline which on push to the master branch)

name : test

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on : ubuntu-latest

    steps:
      - name: Check out repo code
        uses: actions/checkout@v3

      - name: Setup Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.x"

      - name: Install Dependencies
        run: |
          python -m pip install -r requirements.txt
      - name: Run tests
        run: |
          python -m pytest calculator.py

Step 4 - Check our Gitflow with a new branch


1.) Create a new feature branch to check a case where the push to master or PR fails by making a purposeful mistake in the code to fail a test

2.) Create a new feature branch called test

def test_add():
    assert add(1,1) == 0


We have changed the test_add method to assert a False

3.) Git add, push and commit

Step 5 - Fix all the errors to make a successful build


1.) Change back the test_add function

2.) Add, commit, and push the new changes to the master branch again

Optional


1.) Added pytest-cov to generate
The edited workflow YAML generates an XML coverage report using pytest-cov. You can access and download the report from the GitHub Actions workflow run page under the "coverage-report" artifact. For more interactive and graphical visualization, additional tools or online services can be used with the generated XML report.

.github/workflows/ci-cd.yml:

name: test

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - "*"

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Check out repo code
        uses: actions/checkout@v3

      - name: Setup Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.x"

      - name: Install Dependencies
        run: |
          python -m pip install -r requirements.txt

      - name: Run tests
        run: |
          python -m pytest -v tests

      - name: Install pytest-cov
        run: |
          python -m pip install pytest-cov

      - name: Generate coverage report
        run: |
          python -m pytest --cov=calculator --cov-report=xml:cov.xml

      - name: Upload coverage report
        uses: actions/upload-artifact@v2
        with:
          name: coverage-report
          path: cov.xml

week1-devops's People

Contributors

dmxocean avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.