# https://aka.ms/yaml jobs: - job: test displayName: 'Test & Lint' pool: vmImage: ubuntu-16.04 variables: PIP_CACHE_DIR: .cache/pip steps: - task: UsePythonVersion@0 displayName: 'Set Python Version' inputs: versionSpec: '3.7.x' addToPath: true - script: | pip install pipenv pipenv install --dev --system pip install flake8-formatter-junit-xml displayName: 'Install Project Environment' - script: flake8 --format junit-xml --output-file TEST-lint.xml displayName: 'Run Linter' - script: | curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' sudo apt-get update -y sudo apt-get install -y postgresql-11 displayName: 'Install PostgreSQL' - script: | echo "$USER_CREATE_COMMAND;" > pgscript.sql echo "CREATE DATABASE pysite OWNER pysite;" >> pgscript.sql sudo su postgres -c "psql < pgscript.sql" env: USER_CREATE_COMMAND: CREATE USER pysite WITH PASSWORD 'pysite' CREATEDB displayName: 'Setup Database' - script: | python3 manage.py makemigrations --check python3 manage.py migrate coverage run \ --branch \ manage.py test \ --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner \ --no-input env: CI: azure DATABASE_URL: postgres://pysite:pysite@localhost/pysite displayName: 'Run Tests' - script: coverage report displayName: 'Show Coverage Results' - task: PublishTestResults@2 condition: succeededOrFailed() displayName: 'Publish Test & Linting Results' inputs: testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Site Test Results' - job: build displayName: 'Build & Push Container' dependsOn: test condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) steps: - task: Docker@2 displayName: 'Build & Push Container' inputs: containerRegistry: 'DockerHubV2' repository: 'pythondiscord/site' command: 'buildAndPush' Dockerfile: 'docker/app/Dockerfile' buildContext: '.' tags: 'latest'