diff --git a/.github/workflows/main_twvapasi-py.yml b/.github/workflows/main_twvapasi-py.yml new file mode 100644 index 000000000..8fc75d787 --- /dev/null +++ b/.github/workflows/main_twvapasi-py.yml @@ -0,0 +1,89 @@ +name: Build and deploy Python app to Azure Web App - twvapasi-py + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r test-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 + 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 + 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 }} diff --git a/requirements.txt b/requirements.txt index 2db5aeaff..8b95c612e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Flask==2.0.2 \ No newline at end of file +Flask==2.0.2 +werkzeug==2.0.3 diff --git a/test b/test new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test 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 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..cb327157c --- /dev/null +++ b/tests/test_success.py @@ -0,0 +1,3 @@ +def test_index(app, client): + res = client.get('/') + assert res.status_code == 200