aboutsummaryrefslogtreecommitdiffstats
path: root/azure-pipelines.yml
blob: 9ca2b812281260432ee5cb26c0aa6837ec70c150 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# https://aka.ms/yaml

jobs:
- job: python_lint
  displayName: 'Lint Job'
  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: python3 -m pip install pipenv && pipenv install --dev --system && python3 -m pip install flake8-formatter-junit-xml
    displayName: 'Install Project Environment'

  - script: python3 -m flake8 --format junit-xml --output-file test-lint.xml
    displayName: 'Run Linter'

  - task: PublishTestResults@2
    condition: succeededOrFailed()
    inputs:
      testResultsFiles: '**/test-*.xml'
      testRunTitle: 'Site-Django Lint Results'

- job: coverage_test
  displayName: 'Test Job'
  dependsOn: python_lint
  pool:
    vmImage: ubuntu-16.04

  steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.7.x'
        architecture: x64

    - 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 -m pip install pipenv && pipenv install --dev --system
      displayName: 'Install Project Environment'

    - script: |
        python 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 Test'

    - script: coverage report
      displayName: 'Show Coverage Results'

    - task: PublishTestResults@2
      inputs:
        testResultsFiles: "**/TEST-*.xml"
        testRunTitle: 'Site-Django Test Results'

- job: docker
  displayName: 'Build & Push Job'
  dependsOn: coverage_test
  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
  pool:
    vmImage: ubuntu-16.04

  steps:
    - task: Docker@1
      displayName: Login to Docker Hub

      inputs:
        containerregistrytype: 'Container Registry'
        dockerRegistryEndpoint: 'DockerHub'
        command: 'login'

    - script: |
        docker build -t pythondiscord/django:latest -f docker/app/Dockerfile .
        docker push pythondiscord/django:latest
      displayName: 'Build & Push Docker Image'