Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #71

Open
wants to merge 9 commits into
base: test
Choose a base branch
from
Open

Test #71

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions .github/workflows/ci_cd_wf.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name : test
on:
push:
branches:
- main
pull_request_target:
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
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
161 changes: 161 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

100 changes: 98 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,98 @@
# week1-devops
All Code and Files for Intro to DevOps Week 1 Project
# 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

<br> Link to setup Python 3.9 - https://www.python.org/downloads/ </br>
<br> Link to setup Git the first time - https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup </br>
<br> Use a Editor of your choice </br>
<br> Link to get pip3 - https://pip.pypa.io/en/stable/installation/ </br>

## 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
<br> 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 </br>
<br> 2.) Create a new feature branch called test </br>

```
def test_add():
assert add(1,1) == 0
```
<br> We have changed the test_add method to assert a False </br>
<br> 3.) Git add, push and commit </br>

## Step 5 - Fix all the errors to make a successful build
<br> 1.) Change back the test_add function </br>
<br> 2.) Add, commit, and push the new changes to the master branch again </br>

### As the first week of the project comes to a close, it's important to reflect on the progress made so far.

## Future Scope Recommendations -
<br> Now that the initial code is in place, it's time to focus on improving its quality. One way to do this is to add more checks such as linters, code coverage, and code quality checks. </br>
<br> Another recommended step is to add 'runs on' actions like a pull request. This allows for a more streamlined workflow and can help ensure that the code changes are thoroughly tested before being merged into the main branch. </br>

### As you move forward into Week 2 of the project, keep these next steps in mind. By continually improving the quality of your code, you'll be setting yourself up for success in the long run.

## Appendix
<br> This repository has three branches -
### 'main' branch contains the file code for the project
### 'initial_starter_code' contains the inital code to start with
### 'test' - The state of the project with a wrong test added for reference - this is supposed to fail the merge to master process in our workflow
</br>
32 changes: 12 additions & 20 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
# Demo Calculator App For Week 1 Project
# Addition Method
def add(a, b):
return (a + b)
return a + b


# Subtract Method
def sub(a, b):
return (a - b)
return a - b


# Multiplication
def mul(a, b):
return (a * b)

# Division
def div(a,b):
return (a/b)

def test_add():
assert add(1,1) == 2
return a * b

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

def test_mul():
assert mul(1,1) == 1
# Division
def div(a, b):
return a / b

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

if __name__ == "__main__":
# Declare variable and set default values
a = 4
b = 2
print('Sum of ' + str(a) + ' and ' + str(b) + ' is ', add(a, b))
print('Difference of ' + str(a) + ' and ' + str(b) + ' is ', sub(a, b))
print('Product of ' + str(a) + ' and ' + str(b) + ' is ', mul(a, b))
print('Division of ' + str(a) + ' and ' + str(b) + ' is ', div(a, b))
print("Sum of " + str(a) + " and " + str(b) + " is ", add(a, b))
print("Difference of " + str(a) + " and " + str(b) + " is ", sub(a, b))
print("Product of " + str(a) + " and " + str(b) + " is ", mul(a, b))
print("Division of " + str(a) + " and " + str(b) + " is ", div(a, b))
17 changes: 17 additions & 0 deletions tests/test_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from calculator import add, div, mul, sub


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