|
| 1 | +# Python Django |
| 2 | +# Test a Django project on multiple versions of Python. |
| 3 | +# Add steps that analyze code, save build artifacts, deploy, and more: |
| 4 | +# https://docs.microsoft.com/azure/devops/pipelines/languages/python |
| 5 | + |
| 6 | +trigger: |
| 7 | +- master |
| 8 | + |
| 9 | +pool: |
| 10 | + vmImage: 'ubuntu-latest' |
| 11 | +strategy: |
| 12 | + matrix: |
| 13 | + Python38: |
| 14 | + PYTHON_VERSION: '3.8' |
| 15 | + maxParallel: 3 |
| 16 | + |
| 17 | +steps: |
| 18 | +- task: UsePythonVersion@0 |
| 19 | + inputs: |
| 20 | + versionSpec: '$(PYTHON_VERSION)' |
| 21 | + architecture: 'x64' |
| 22 | + |
| 23 | +- task: PythonScript@0 |
| 24 | + displayName: 'Export project path' |
| 25 | + inputs: |
| 26 | + scriptSource: 'inline' |
| 27 | + script: | |
| 28 | + """Search all subdirectories for `manage.py`.""" |
| 29 | + from glob import iglob |
| 30 | + from os import path |
| 31 | + # Python >= 3.5 |
| 32 | + manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None) |
| 33 | + if not manage_py: |
| 34 | + raise SystemExit('Could not find a Django project') |
| 35 | + project_location = path.dirname(path.abspath(manage_py)) |
| 36 | + print('Found Django project in', project_location) |
| 37 | + print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location)) |
| 38 | +
|
| 39 | +- script: | |
| 40 | + python -m pip install --upgrade pip setuptools wheel pipenv |
| 41 | + python -m pipenv lock -r > requirements.txt |
| 42 | + python -m pipenv lock --dev -r > dev_requirements.txt |
| 43 | + pip install -r requirements.txt |
| 44 | + pip install -r dev_requirements.txt |
| 45 | + pip install unittest-xml-reporting |
| 46 | + displayName: 'Install prerequisites' |
| 47 | + |
| 48 | +- script: | |
| 49 | + psql -c "CREATE DATABASE donor_reporting_portal;" -U postgres |
| 50 | + displayName: 'Create DB' |
| 51 | + |
| 52 | +- script: | |
| 53 | + pushd '$(projectRoot)' |
| 54 | + tox |
| 55 | + displayName: 'Run tests' |
| 56 | + |
| 57 | +- task: PublishTestResults@2 |
| 58 | + inputs: |
| 59 | + testResultsFiles: "**/TEST-*.xml" |
| 60 | + testRunTitle: 'Python $(PYTHON_VERSION)' |
| 61 | + condition: succeededOrFailed() |
0 commit comments