From 4b4c1b48fd06a45326f462626ee7408d464b68cb Mon Sep 17 00:00:00 2001 From: FranzDalitz <72563759+FranzDalitz@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:56:23 +0200 Subject: [PATCH 1/4] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..d04ef0409 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,87 @@ +# Python to Linux Web App on Azure +# Build your Python project and deploy it to Azure as a Linux Web App. +# Change python version to one thats appropriate for your application. +# https://docs.microsoft.com/azure/devops/pipelines/languages/python + +trigger: +- main + +variables: + # Azure Resource Manager connection created during pipeline creation + azureServiceConnectionId: '26f4f10a-1131-4bcf-84c7-c4ee7edd5f66' + + # Web app name + webAppName: 'ftcc-devops-app' + + # Agent VM image name + vmImageName: 'ubuntu-latest' + + # Environment name + environmentName: 'ftcc-devops-app' + + # Project root folder. Point to the folder containing manage.py file. + projectRoot: $(System.DefaultWorkingDirectory) + + # Python version: 3.7 + pythonVersion: '3.7' + +stages: +- stage: Build + displayName: Build stage + jobs: + - job: BuildJob + pool: + vmImage: $(vmImageName) + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(pythonVersion)' + displayName: 'Use Python $(pythonVersion)' + + - script: | + python -m venv antenv + source antenv/bin/activate + python -m pip install --upgrade pip + pip install setup + pip install -r requirements.txt + workingDirectory: $(projectRoot) + displayName: "Install requirements" + + - task: ArchiveFiles@2 + displayName: 'Archive files' + inputs: + rootFolderOrFile: '$(projectRoot)' + includeRootFolder: false + archiveType: zip + archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + replaceExistingArchive: true + + - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + displayName: 'Upload package' + artifact: drop + +- stage: Deploy + displayName: 'Deploy Web App' + dependsOn: Build + condition: succeeded() + jobs: + - deployment: DeploymentJob + pool: + vmImage: $(vmImageName) + environment: $(environmentName) + strategy: + runOnce: + deploy: + steps: + + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(pythonVersion)' + displayName: 'Use Python version' + + - task: AzureWebApp@1 + displayName: 'Deploy Azure Web App : 'ftcc-devops-app' + inputs: + azureSubscription: $(azureServiceConnectionId) + appName: $(webAppName) + package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip \ No newline at end of file From 53a8372f1908f89fc5fbead4fc56f9ca4cffd669 Mon Sep 17 00:00:00 2001 From: FranzDalitz <72563759+FranzDalitz@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:58:17 +0200 Subject: [PATCH 2/4] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d04ef0409..62a99151d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -80,7 +80,7 @@ stages: displayName: 'Use Python version' - task: AzureWebApp@1 - displayName: 'Deploy Azure Web App : 'ftcc-devops-app' + displayName: 'Deploy Azure Web App : ftcc-devops-app' inputs: azureSubscription: $(azureServiceConnectionId) appName: $(webAppName) From 84c2305d167f728a4d9e10dfb02fef25c1147262 Mon Sep 17 00:00:00 2001 From: Franz Dalitz <80651545+Franz-Dalitz@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:13:57 +0200 Subject: [PATCH 3/4] das funktioniert safe 100% --- azure-pipelines.yml | 13 +++++++++++++ tests/test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/test.py diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 62a99151d..fa8961efd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -47,6 +47,19 @@ stages: workingDirectory: $(projectRoot) displayName: "Install requirements" + - script: | + python -m pip install --upgrade pip + pip install setup + pip install -r requirements.txt + pip install --upgrade flask werkzeug + python -m unittest discover -s tests -p 'test.py' + workingDirectory: $(projectRoot) + displayName: 'Execute test case' + + - task: PublishTestResults@2 + displayName: 'Publish test results' + testResultsFiles: '**/TEST-*.xml' + - task: ArchiveFiles@2 displayName: 'Archive files' inputs: diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 000000000..1773e1c3d --- /dev/null +++ b/tests/test.py @@ -0,0 +1,28 @@ +import unittest +import xml.etree.ElementTree as ET +import os +import sys +from flask import Flask +from flask.testing import FlaskClient + +# Add the parent directory to sys.path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +from app import app + +class MyTestClass(unittest.TestCase): + def test_method1(self): + with app.test_client() as client: + response = client.get('/') + print(response.status_code) + xml_file_path = 'TEST-result.xml' + root = ET.Element('testsuites') + tree = ET.ElementTree(root) + testsuite_elem = ET.SubElement(root, 'testsuite', {'tests': '1'}) + testcase_elem = ET.SubElement(testsuite_elem, 'testcase', {'classname': + 'website_accessibility', 'name': 'Website is accessible'}) + success_elem = ET.SubElement(testcase_elem, 'success') + success_elem.text = 'Website is accessible.' + tree.write(xml_file_path) + print(f"XML file '{xml_file_path}' has been generated.") + self.assertEqual(response.status_code, 200) From 062a001027c59838746f9c135125949c19047fd0 Mon Sep 17 00:00:00 2001 From: Franz Dalitz <80651545+Franz-Dalitz@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:16:20 +0200 Subject: [PATCH 4/4] gut --- azure-pipelines.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index fa8961efd..1cc5f6d6c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,7 +58,8 @@ stages: - task: PublishTestResults@2 displayName: 'Publish test results' - testResultsFiles: '**/TEST-*.xml' + inputs: + testResultsFiles: '**/TEST-*.xml' - task: ArchiveFiles@2 displayName: 'Archive files'