From fea8f1b2ffc99fa76857a56cbb91421ca2d8d1d3 Mon Sep 17 00:00:00 2001 From: vj-m Date: Tue, 18 Apr 2023 23:53:11 -0400 Subject: [PATCH 01/11] induce a failed test --- .github/workflows/ci_cd_wf.yml | 3 --- calculator.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml index 9e95f402..184b9b32 100644 --- a/.github/workflows/ci_cd_wf.yml +++ b/.github/workflows/ci_cd_wf.yml @@ -4,9 +4,6 @@ on: push: branches: - main - pull_request_target: - branches: - - main jobs: test: diff --git a/calculator.py b/calculator.py index fbcead9c..9a3d2746 100644 --- a/calculator.py +++ b/calculator.py @@ -16,7 +16,7 @@ def div(a,b): return (a/b) def test_add(): - assert add(1,1) == 2 + assert add(1,1) == 0 def test_sub(): assert sub(1,1) == 0 From c9befb9c6af5be8396d6c511d4f533e28ccd6d29 Mon Sep 17 00:00:00 2001 From: vj-m Date: Wed, 19 Apr 2023 00:00:02 -0400 Subject: [PATCH 02/11] clean final code --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 9a3d2746..fbcead9c 100644 --- a/calculator.py +++ b/calculator.py @@ -16,7 +16,7 @@ def div(a,b): return (a/b) def test_add(): - assert add(1,1) == 0 + assert add(1,1) == 2 def test_sub(): assert sub(1,1) == 0 From 09838f6876bf05dacc047a630150bed28a18d051 Mon Sep 17 00:00:00 2001 From: VeeJ <108243657+vj-m@users.noreply.github.com> Date: Mon, 8 May 2023 15:42:58 -0400 Subject: [PATCH 03/11] Update README.md --- README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 174488da..740a9995 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,91 @@ -# 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 + +
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 git@github.com: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
+ +### 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 - +
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.
+
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.
+ +### 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. From ae3141c7ca07b335307560a252f5f9d128764ff0 Mon Sep 17 00:00:00 2001 From: VeeJ <108243657+vj-m@users.noreply.github.com> Date: Mon, 8 May 2023 16:01:00 -0400 Subject: [PATCH 04/11] Update README.md (#5) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 740a9995..b6f5799d 100644 --- a/README.md +++ b/README.md @@ -89,3 +89,10 @@ def test_add():
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.
### 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 +
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 +
From 59e6f8ab0b447ac98e6d4269a06c5bce93e7c052 Mon Sep 17 00:00:00 2001 From: Yudhiesh Ravindranath Date: Mon, 29 May 2023 01:46:21 +0800 Subject: [PATCH 05/11] Update base repository (#7) --- .github/workflows/ci_cd_wf.yml | 6 +-- .gitignore | 88 ++++++++++++++++++++++++++++++++++ calculator.py | 32 +++++-------- tests/test_calculator.py | 17 +++++++ 4 files changed, 120 insertions(+), 23 deletions(-) create mode 100644 .gitignore create mode 100644 tests/test_calculator.py diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml index 184b9b32..aada2bac 100644 --- a/.github/workflows/ci_cd_wf.yml +++ b/.github/workflows/ci_cd_wf.yml @@ -1,4 +1,4 @@ -name : test +name: test on: push: @@ -7,7 +7,7 @@ on: jobs: test: - runs-on : ubuntu-latest + runs-on: ubuntu-latest steps: - name: Check out repo code @@ -23,4 +23,4 @@ jobs: python -m pip install -r requirements.txt - name: Run tests run: | - python -m pytest calculator.py \ No newline at end of file + python -m pytest tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f092b1b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,88 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# 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/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# DotEnv configuration +.env + +# Database +*.db +*.rdb + +# Pycharm +.idea + +# VS Code +.vscode/ + +# Spyder +.spyproject/ + +# Jupyter NB Checkpoints +.ipynb_checkpoints/ + + +# Mac OS-specific storage files +.DS_Store + +# vim +*.swp +*.swo + +# Mypy cache +.mypy_cache/ + diff --git a/calculator.py b/calculator.py index fbcead9c..feefb4e3 100644 --- a/calculator.py +++ b/calculator.py @@ -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)) \ No newline at end of file + 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)) diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 00000000..efdc7a33 --- /dev/null +++ b/tests/test_calculator.py @@ -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 From f3552dfecc337a4340dc1aecebdf01e4902d1ac2 Mon Sep 17 00:00:00 2001 From: Yudhiesh Ravindranath Date: Mon, 5 Jun 2023 13:23:02 +0800 Subject: [PATCH 06/11] Finalise repository for course launch (#8) * remove workflows * remove tests * update gitignore --- .github/workflows/ci_cd_wf.yml | 26 -------- .gitignore | 115 +++++++++++++++++++++++++++------ tests/test_calculator.py | 17 ----- 3 files changed, 94 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/ci_cd_wf.yml diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml deleted file mode 100644 index aada2bac..00000000 --- a/.github/workflows/ci_cd_wf.yml +++ /dev/null @@ -1,26 +0,0 @@ -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 tests diff --git a/.gitignore b/.gitignore index f092b1b4..b1cb1601 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,13 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] +*$py.class # C extensions *.so # Distribution / packaging .Python -env/ build/ develop-eggs/ dist/ @@ -19,9 +19,12 @@ 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 @@ -36,12 +39,17 @@ 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 @@ -49,40 +57,105 @@ coverage.xml # 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/ -# DotEnv configuration +# 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/ -# Database -*.db -*.rdb - -# Pycharm -.idea +# Spyder project settings +.spyderproject +.spyproject -# VS Code -.vscode/ +# Rope project settings +.ropeproject -# Spyder -.spyproject/ +# mkdocs documentation +/site -# Jupyter NB Checkpoints -.ipynb_checkpoints/ +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json +# Pyre type checker +.pyre/ -# Mac OS-specific storage files -.DS_Store +# pytype static type analyzer +.pytype/ -# vim -*.swp -*.swo +# Cython debug symbols +cython_debug/ -# Mypy cache -.mypy_cache/ +# 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/ diff --git a/tests/test_calculator.py b/tests/test_calculator.py index efdc7a33..e69de29b 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,17 +0,0 @@ -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 From 437e222407b326c01d8a4ba20d7ff385ea69d281 Mon Sep 17 00:00:00 2001 From: Taiwo Olori <101744737+OloriT@users.noreply.github.com> Date: Sat, 18 Nov 2023 06:34:25 +0000 Subject: [PATCH 07/11] changed test_add to fail --- .github/workflows/ci_cd_wf.yml | 29 +++++++++++++++++++++++++++++ tests/test_calculator.py | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/ci_cd_wf.yml diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml new file mode 100644 index 00000000..8ca03d4c --- /dev/null +++ b/.github/workflows/ci_cd_wf.yml @@ -0,0 +1,29 @@ +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 \ No newline at end of file diff --git a/tests/test_calculator.py b/tests/test_calculator.py index e69de29b..1a7ee7fb 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -0,0 +1,17 @@ +from calculator import add, div, mul, sub + + +def test_add(): + assert add(1, 1) == 0 + + +def test_sub(): + assert sub(1, 1) == 0 + + +def test_mul(): + assert mul(1, 1) == 1 + + +def test_div(): + assert div(2, 1) == 2 \ No newline at end of file From 2aaeaf451e2849bec0419df2f3d1fdc97326507d Mon Sep 17 00:00:00 2001 From: Taiwo Olori <101744737+OloriT@users.noreply.github.com> Date: Sat, 18 Nov 2023 07:43:36 +0100 Subject: [PATCH 08/11] Update test_calculator.py --- tests/test_calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 1a7ee7fb..efdc7a33 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -2,7 +2,7 @@ def test_add(): - assert add(1, 1) == 0 + assert add(1, 1) == 2 def test_sub(): @@ -14,4 +14,4 @@ def test_mul(): def test_div(): - assert div(2, 1) == 2 \ No newline at end of file + assert div(2, 1) == 2 From 13e158a8efd7f7e23a2c6817954b0067c9d5bb36 Mon Sep 17 00:00:00 2001 From: Taiwo Olori <101744737+OloriT@users.noreply.github.com> Date: Sat, 18 Nov 2023 06:55:32 +0000 Subject: [PATCH 09/11] pytest code coverage badge and full report --- .github/workflows/ci_cd_wf.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml index 8ca03d4c..4221e69e 100644 --- a/.github/workflows/ci_cd_wf.yml +++ b/.github/workflows/ci_cd_wf.yml @@ -26,4 +26,7 @@ jobs: python -m pip install -r requirements.txt - name: Run tests run: | - python -m pytest -v tests \ No newline at end of file + python -m pytest -v tests + - name: Pytest Coverage Comment + uses: MishaKav/pytest-coverage-comment@v1.1.49 + \ No newline at end of file From 4c921e1abf27e43b96d1f887dc50404802064950 Mon Sep 17 00:00:00 2001 From: Taiwo Olori <101744737+OloriT@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:37:30 +0000 Subject: [PATCH 10/11] Added coverage files --- .github/workflows/ci_cd_wf.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml index 4221e69e..44615e3c 100644 --- a/.github/workflows/ci_cd_wf.yml +++ b/.github/workflows/ci_cd_wf.yml @@ -27,6 +27,18 @@ jobs: - name: Run tests run: | python -m pytest -v tests - - name: Pytest Coverage Comment + + - name: Install Py-test Cov Reports + run: | + python -m pip install pytest-cov + + - name: Install pytest-cov for report uses: MishaKav/pytest-coverage-comment@v1.1.49 + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml + + - name: Build coverage file + run: | + pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests/ | tee pytest-coverage.txt \ No newline at end of file From afb315f071837cfa35b52cf43484b4d324ca0a8e Mon Sep 17 00:00:00 2001 From: Taiwo Olori <101744737+OloriT@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:59:02 +0000 Subject: [PATCH 11/11] made change to test_calculator --- tests/test_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 1a7ee7fb..aeae4a4d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -2,7 +2,7 @@ def test_add(): - assert add(1, 1) == 0 + assert add(1, 1) == 2 def test_sub():