|
| 1 | +name: Modoboa contacts plugin |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + release: |
| 9 | + branches: [ master ] |
| 10 | + |
| 11 | +env: |
| 12 | + POSTGRES_HOST: localhost |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + services: |
| 18 | + postgres: |
| 19 | + image: postgres:11 |
| 20 | + env: |
| 21 | + POSTGRES_USER: postgres |
| 22 | + POSTGRES_PASSWORD: postgres |
| 23 | + POSTGRES_DB: postgres |
| 24 | + ports: |
| 25 | + # will assign a random free host port |
| 26 | + - 5432/tcp |
| 27 | + # needed because the postgres container does not provide a healthcheck |
| 28 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 29 | + mysql: |
| 30 | + image: mysql:8.0 |
| 31 | + env: |
| 32 | + MYSQL_ROOT_PASSWORD: root |
| 33 | + MYSQL_USER: modoboa |
| 34 | + MYSQL_PASSWORD: modoboa |
| 35 | + MYSQL_DATABASE: modoboa |
| 36 | + ports: |
| 37 | + - 3306/tcp |
| 38 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 |
| 39 | + |
| 40 | + strategy: |
| 41 | + matrix: |
| 42 | + database: ['postgres', 'mysql'] |
| 43 | + python-version: [3.7, 3.8, 3.9] |
| 44 | + fail-fast: false |
| 45 | + |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v2 |
| 48 | + - name: Set up Python ${{ matrix.python-version }} |
| 49 | + uses: actions/setup-python@v2 |
| 50 | + with: |
| 51 | + python-version: ${{ matrix.python-version }} |
| 52 | + - name: Install dependencies |
| 53 | + run: | |
| 54 | + sudo apt-get update -y && sudo apt-get install -y librrd-dev rrdtool |
| 55 | + python -m pip install --upgrade pip |
| 56 | + pip install -e git+https://github.com/modoboa/modoboa.git#egg=modoboa |
| 57 | + pip install -r requirements.txt |
| 58 | + pip install -r test-requirements.txt |
| 59 | + python setup.py develop |
| 60 | + - name: Install postgres requirements |
| 61 | + if: ${{ matrix.database == 'postgres' }} |
| 62 | + run: | |
| 63 | + pip install psycopg2-binary>=2.7.4 |
| 64 | + pip install coverage |
| 65 | + echo "DB=postgres" >> $GITHUB_ENV |
| 66 | + - name: Install mysql requirements |
| 67 | + if: ${{ matrix.database == 'mysql' }} |
| 68 | + run: | |
| 69 | + pip install 'mysqlclient<2.1.1' |
| 70 | + echo "DB=mysql" >> $GITHUB_ENV |
| 71 | + - name: Test with pytest |
| 72 | + if: ${{ matrix.python-version != '3.9' || matrix.database != 'postgres' }} |
| 73 | + run: | |
| 74 | + cd test_project |
| 75 | + python3 manage.py test modoboa_contacts |
| 76 | + env: |
| 77 | + # use localhost for the host here because we are running the job on the VM. |
| 78 | + # If we were running the job on in a container this would be postgres |
| 79 | + POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port |
| 80 | + MYSQL_HOST: 127.0.0.1 |
| 81 | + MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port |
| 82 | + MYSQL_USER: root |
| 83 | + |
| 84 | + - name: Test with pytest and coverage |
| 85 | + if: ${{ matrix.python-version == '3.9' && matrix.database == 'postgres' }} |
| 86 | + run: | |
| 87 | + cd test_project |
| 88 | + coverage run --source ../modoboa_contacts manage.py test modoboa_contacts |
| 89 | + env: |
| 90 | + # use localhost for the host here because we are running the job on the VM. |
| 91 | + # If we were running the job on in a container this would be postgres |
| 92 | + POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port |
| 93 | + MYSQL_HOST: 127.0.0.1 |
| 94 | + MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port |
| 95 | + MYSQL_USER: root |
| 96 | + - name: Upload coverage result |
| 97 | + if: ${{ matrix.python-version == '3.9' }} |
| 98 | + uses: actions/upload-artifact@v2 |
| 99 | + with: |
| 100 | + name: coverage-results |
| 101 | + path: test_project/.coverage |
| 102 | + |
| 103 | + coverage: |
| 104 | + needs: test |
| 105 | + runs-on: ubuntu-latest |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v2 |
| 108 | + - name: Set up Python 3.9 |
| 109 | + uses: actions/setup-python@v2 |
| 110 | + with: |
| 111 | + python-version: '3.9' |
| 112 | + - name: Install dependencies |
| 113 | + run: | |
| 114 | + pip install codecov |
| 115 | + - name: Download coverage results |
| 116 | + uses: actions/download-artifact@v2 |
| 117 | + with: |
| 118 | + name: coverage-results |
| 119 | + - name: Report coverage |
| 120 | + run: | |
| 121 | + coverage report |
| 122 | + codecov |
| 123 | +
|
| 124 | + release: |
| 125 | + needs: coverage |
| 126 | + runs-on: ubuntu-latest |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v2 |
| 129 | + with: |
| 130 | + fetch-depth: 0 |
| 131 | + - name: Set up Python 3.9 |
| 132 | + uses: actions/setup-python@v2 |
| 133 | + with: |
| 134 | + python-version: '3.9' |
| 135 | + - name: Build frontend |
| 136 | + shell: bash -l {0} |
| 137 | + run: | |
| 138 | + cd frontend |
| 139 | + nvm install 10.15 |
| 140 | + npm install |
| 141 | + npm run build |
| 142 | + cd .. |
| 143 | + - name: Build packages |
| 144 | + run: | |
| 145 | + sudo apt-get install librrd-dev rrdtool libssl-dev gettext |
| 146 | + python -m pip install --upgrade pip setuptools wheel |
| 147 | + pip install -r requirements.txt |
| 148 | + cd modoboa_contacts |
| 149 | + django-admin compilemessages |
| 150 | + cd .. |
| 151 | + python setup.py sdist bdist_wheel |
| 152 | + - name: Publish to Test PyPI |
| 153 | + if: endsWith(github.event.ref, '/master') |
| 154 | + uses: pypa/gh-action-pypi-publish@master |
| 155 | + with: |
| 156 | + user: __token__ |
| 157 | + password: ${{ secrets.test_pypi_password }} |
| 158 | + repository_url: https://test.pypi.org/legacy/ |
| 159 | + skip_existing: true |
| 160 | + - name: Publish distribution to PyPI |
| 161 | + if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' |
| 162 | + uses: pypa/gh-action-pypi-publish@master |
| 163 | + with: |
| 164 | + user: __token__ |
| 165 | + password: ${{ secrets.pypi_password }} |
| 166 | + skip_existing: true |
0 commit comments