From 00e1594c3a0c7bcdbc450c1bdb72569403019539 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav <12096062+userimack@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:12:24 +0530 Subject: [PATCH 1/7] Add or update the Azure App Service build and deployment workflow config --- .github/workflows/main_twvapasi-py.yml | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/main_twvapasi-py.yml diff --git a/.github/workflows/main_twvapasi-py.yml b/.github/workflows/main_twvapasi-py.yml new file mode 100644 index 000000000..52802f585 --- /dev/null +++ b/.github/workflows/main_twvapasi-py.yml @@ -0,0 +1,63 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions +# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions + +name: Build and deploy Python app to Azure Web App - twvapasi-py + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: '3.9' + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt + + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v2 + with: + name: python-app + path: | + . + !venv/ + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: python-app + path: . + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v2 + id: deploy-to-webapp + with: + app-name: 'twvapasi-py' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B84AAFCD02964E378C7F38797E04B16B }} From bca85fc2788b32a2c8a7c3e3861f4bec433174d3 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav Date: Thu, 23 Jun 2022 14:20:11 +0530 Subject: [PATCH 2/7] Add tests --- .github/workflows/main_twvapasi-py.yml | 19 ++++++++++++++----- requirements.txt | 4 +++- tests/conftest.py | 13 +++++++++++++ tests/test_success.py | 8 ++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/test_success.py diff --git a/.github/workflows/main_twvapasi-py.yml b/.github/workflows/main_twvapasi-py.yml index 52802f585..7732e71e4 100644 --- a/.github/workflows/main_twvapasi-py.yml +++ b/.github/workflows/main_twvapasi-py.yml @@ -26,18 +26,27 @@ jobs: run: | python -m venv venv source venv/bin/activate - + - name: Install dependencies run: pip install -r requirements.txt - + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) - + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + python -m pytest + - name: Upload artifact for deployment jobs uses: actions/upload-artifact@v2 with: name: python-app path: | - . + . !venv/ deploy: @@ -53,7 +62,7 @@ jobs: with: name: python-app path: . - + - name: 'Deploy to Azure Web App' uses: azure/webapps-deploy@v2 id: deploy-to-webapp diff --git a/requirements.txt b/requirements.txt index 2db5aeaff..7ee4b884b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -Flask==2.0.2 \ No newline at end of file +Flask==2.0.2 +flake8 +pytest diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..95bd62807 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +import pytest + +from app import app as flask_app + + +@pytest.fixture +def app(): + yield flask_app + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_success.py b/tests/test_success.py new file mode 100644 index 000000000..4473598d7 --- /dev/null +++ b/tests/test_success.py @@ -0,0 +1,8 @@ +import json + + +def test_index(app, client): + res = client.get('/') + assert res.status_code == 200 + # expected = {'hello': 'world'} + # assert expected == json.loads(res.get_data(as_text=True)) From ef54bbc7c43f4a9757dfa9d713b2a3a886d4f497 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav Date: Thu, 23 Jun 2022 14:23:17 +0530 Subject: [PATCH 3/7] Update actions workflow --- .github/workflows/main_twvapasi-py.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_twvapasi-py.yml b/.github/workflows/main_twvapasi-py.yml index 7732e71e4..9d2f239f4 100644 --- a/.github/workflows/main_twvapasi-py.yml +++ b/.github/workflows/main_twvapasi-py.yml @@ -34,9 +34,9 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | python -m pytest From b2b51fda7ff819f6b16aa00497839163d0d1dff9 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav Date: Thu, 23 Jun 2022 14:31:56 +0530 Subject: [PATCH 4/7] Add package version to resolve error --- requirements.txt | 2 ++ tests/test_success.py | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7ee4b884b..3bfd6c377 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Flask==2.0.2 +werkzeug==2.0.3 + flake8 pytest diff --git a/tests/test_success.py b/tests/test_success.py index 4473598d7..cb327157c 100644 --- a/tests/test_success.py +++ b/tests/test_success.py @@ -1,8 +1,3 @@ -import json - - def test_index(app, client): res = client.get('/') assert res.status_code == 200 - # expected = {'hello': 'world'} - # assert expected == json.loads(res.get_data(as_text=True)) From 5c846cf8e2adc676b61bfe95b9d99f4d388f6173 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav Date: Thu, 23 Jun 2022 14:50:07 +0530 Subject: [PATCH 5/7] Add test stage --- .github/workflows/main_twvapasi-py.yml | 31 ++++++++++++++++++++------ requirements.txt | 3 --- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main_twvapasi-py.yml b/.github/workflows/main_twvapasi-py.yml index 9d2f239f4..8fc75d787 100644 --- a/.github/workflows/main_twvapasi-py.yml +++ b/.github/workflows/main_twvapasi-py.yml @@ -1,7 +1,3 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy -# More GitHub Actions for Azure: https://github.com/Azure/actions -# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions - name: Build and deploy Python app to Azure Web App - twvapasi-py on: @@ -11,8 +7,11 @@ on: workflow_dispatch: jobs: - build: + test: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 @@ -20,7 +19,7 @@ jobs: - name: Set up Python version uses: actions/setup-python@v1 with: - python-version: '3.9' + python-version: ${{ matrix.python-version }} - name: Create and start virtual environment run: | @@ -28,7 +27,7 @@ jobs: source venv/bin/activate - name: Install dependencies - run: pip install -r requirements.txt + run: pip install -r test-requirements.txt # Optional: Add step to run tests here (PyTest, Django test suites, etc.) - name: Lint with flake8 @@ -40,6 +39,24 @@ jobs: - name: Test with pytest run: | python -m pytest + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: '3.9' + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt - name: Upload artifact for deployment jobs uses: actions/upload-artifact@v2 diff --git a/requirements.txt b/requirements.txt index 3bfd6c377..8b95c612e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,2 @@ Flask==2.0.2 werkzeug==2.0.3 - -flake8 -pytest From 7da9847d38c03a1dbaaaccda2a5249b404dbdf46 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav Date: Thu, 23 Jun 2022 14:51:27 +0530 Subject: [PATCH 6/7] Add test requirements --- test-requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..3bfd6c377 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,5 @@ +Flask==2.0.2 +werkzeug==2.0.3 + +flake8 +pytest From cf0bbe5b132a7e803e9c954e100acd21df6ef8d9 Mon Sep 17 00:00:00 2001 From: Mahendra Yadav <12096062+userimack@users.noreply.github.com> Date: Thu, 23 Jun 2022 17:02:38 +0530 Subject: [PATCH 7/7] Create test --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test