2020-08-18 11:08:40 +02:00
|
|
|
|
name: Backend CI
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
- pull_request
|
2021-02-24 08:32:44 +01:00
|
|
|
|
env:
|
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
|
REDIS_URL: 'redis://localhost'
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
jobs:
|
2021-01-22 15:36:30 +01:00
|
|
|
|
backend-code-quality:
|
2020-08-18 11:08:40 +02:00
|
|
|
|
name: Code quality checks
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:12
|
|
|
|
|
env:
|
|
|
|
|
POSTGRES_USER: postgres
|
|
|
|
|
POSTGRES_PASSWORD: postgres
|
|
|
|
|
POSTGRES_DB: postgres
|
|
|
|
|
ports: ['5432:5432']
|
|
|
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
|
|
|
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v1
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 1
|
|
|
|
|
|
2020-09-30 14:59:46 +02:00
|
|
|
|
- name: Set up Python 3.8
|
2020-10-26 11:11:02 +01:00
|
|
|
|
uses: actions/setup-python@v2
|
2020-08-18 11:08:40 +02:00
|
|
|
|
with:
|
2020-09-30 14:59:46 +02:00
|
|
|
|
python-version: 3.8
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
- uses: actions/cache@v1
|
|
|
|
|
with:
|
|
|
|
|
path: ~/.cache/pip
|
2020-11-10 10:17:48 +01:00
|
|
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
2020-08-18 11:08:40 +02:00
|
|
|
|
restore-keys: |
|
|
|
|
|
${{ runner.os }}-pip-
|
|
|
|
|
|
|
|
|
|
- name: Install Python dependencies with pip
|
|
|
|
|
run: |
|
|
|
|
|
python -m pip install -U pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
2020-11-10 10:17:48 +01:00
|
|
|
|
python -m pip install -r requirements-dev.txt
|
2020-08-18 11:08:40 +02:00
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
2020-11-02 15:55:20 +01:00
|
|
|
|
- name: Check formatting
|
2020-08-18 11:08:40 +02:00
|
|
|
|
run: |
|
2020-11-02 15:55:20 +01:00
|
|
|
|
black --check .
|
|
|
|
|
isort --check-only .
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
- name: Lint with flake8
|
|
|
|
|
run: |
|
|
|
|
|
# stop the build if there are Python syntax errors or undefined names
|
|
|
|
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
|
|
|
# exit-zero treats all errors as warnings
|
|
|
|
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
|
|
|
|
|
|
|
|
|
|
- name: Typecheck
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
2020-11-02 15:55:20 +01:00
|
|
|
|
mypy .
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
django:
|
2020-10-26 11:11:02 +01:00
|
|
|
|
name: Django tests – Py ${{ matrix.python-version }}
|
2020-08-18 11:08:40 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-30 17:17:58 +02:00
|
|
|
|
if: ${{ github.actor != 'posthog-contributions-bot[bot]' }}
|
2021-03-30 16:12:48 +02:00
|
|
|
|
|
2020-10-26 11:11:02 +01:00
|
|
|
|
strategy:
|
2020-10-28 16:11:45 +01:00
|
|
|
|
fail-fast: false
|
2020-10-26 11:11:02 +01:00
|
|
|
|
matrix:
|
|
|
|
|
python-version: ['3.7.8', '3.8.5', '3.9.0']
|
2020-08-18 11:08:40 +02:00
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:12
|
|
|
|
|
env:
|
|
|
|
|
POSTGRES_USER: postgres
|
|
|
|
|
POSTGRES_PASSWORD: postgres
|
|
|
|
|
POSTGRES_DB: postgres
|
|
|
|
|
ports: ['5432:5432']
|
|
|
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
2020-09-09 01:12:27 +02:00
|
|
|
|
clickhouse-server:
|
|
|
|
|
image: yandex/clickhouse-server
|
|
|
|
|
ports:
|
|
|
|
|
- '8123:8123'
|
|
|
|
|
- '9000:9000'
|
|
|
|
|
- '9440:9440'
|
|
|
|
|
- '9009:9009'
|
2020-08-18 11:08:40 +02:00
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v1
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 1
|
|
|
|
|
|
2020-10-26 11:11:02 +01:00
|
|
|
|
- name: Set up Python
|
|
|
|
|
uses: actions/setup-python@v2
|
2020-08-18 11:08:40 +02:00
|
|
|
|
with:
|
2020-10-26 11:11:02 +01:00
|
|
|
|
python-version: ${{ matrix.python-version }}
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
- uses: actions/cache@v1
|
|
|
|
|
with:
|
|
|
|
|
path: ~/.cache/pip
|
2020-10-28 18:02:11 +01:00
|
|
|
|
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}
|
2020-08-18 11:08:40 +02:00
|
|
|
|
restore-keys: |
|
2020-10-28 18:02:11 +01:00
|
|
|
|
${{ runner.os }}-pip-${{ matrix.python-version }}-
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
- name: Install requirements.txt dependencies with pip
|
|
|
|
|
run: |
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
2021-03-23 11:39:13 +01:00
|
|
|
|
python -m pip install freezegun fakeredis pytest pytest-mock pytest-django
|
2020-08-18 11:08:40 +02:00
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
|
|
- name: Check migrations
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: python manage.py makemigrations --check --dry-run
|
|
|
|
|
|
2020-09-09 01:12:27 +02:00
|
|
|
|
- name: Run posthog tests
|
2020-08-18 11:08:40 +02:00
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
|
|
|
|
mkdir -p frontend/dist
|
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
2021-02-24 08:32:44 +01:00
|
|
|
|
pytest posthog/
|
2020-09-09 06:00:37 +02:00
|
|
|
|
- name: Run EE tests
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
PRIMARY_DB: 'clickhouse'
|
|
|
|
|
CLICKHOUSE_HOST: 'localhost'
|
|
|
|
|
CLICKHOUSE_DATABASE: 'posthog_test'
|
|
|
|
|
CLICKHOUSE_SECURE: 'False'
|
|
|
|
|
CLICKHOUSE_VERIFY: 'False'
|
|
|
|
|
run: |
|
|
|
|
|
mkdir -p frontend/dist
|
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
2021-02-24 08:32:44 +01:00
|
|
|
|
pytest ee/
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
2020-11-10 08:47:57 +01:00
|
|
|
|
cloud:
|
|
|
|
|
name: Django tests – Cloud
|
2020-09-01 12:07:48 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-30 17:17:58 +02:00
|
|
|
|
if: ${{ github.actor != 'posthog-contributions-bot[bot]' }}
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:12
|
|
|
|
|
env:
|
|
|
|
|
POSTGRES_USER: postgres
|
|
|
|
|
POSTGRES_PASSWORD: postgres
|
|
|
|
|
POSTGRES_DB: postgres
|
|
|
|
|
ports: ['5432:5432']
|
|
|
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
2020-10-28 09:38:01 +01:00
|
|
|
|
clickhouse-server:
|
|
|
|
|
image: yandex/clickhouse-server
|
|
|
|
|
ports:
|
|
|
|
|
- '8123:8123'
|
|
|
|
|
- '9000:9000'
|
|
|
|
|
- '9440:9440'
|
|
|
|
|
- '9009:9009'
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
|
|
|
|
steps:
|
2021-02-24 23:20:05 +01:00
|
|
|
|
- name: Fetch posthog-cloud
|
2020-09-01 12:07:48 +02:00
|
|
|
|
run: |
|
2021-02-24 23:20:05 +01:00
|
|
|
|
curl -L https://github.com/posthog/posthog-cloud/tarball/master | tar --strip-components=1 -xz --
|
2020-09-01 12:07:48 +02:00
|
|
|
|
mkdir deploy/
|
|
|
|
|
|
2020-11-10 08:47:57 +01:00
|
|
|
|
- name: Checkout master
|
|
|
|
|
uses: actions/checkout@v2
|
2020-09-01 12:07:48 +02:00
|
|
|
|
with:
|
2020-11-10 08:47:57 +01:00
|
|
|
|
ref: 'master'
|
2020-09-01 12:07:48 +02:00
|
|
|
|
path: 'deploy/'
|
|
|
|
|
|
2021-02-24 23:20:05 +01:00
|
|
|
|
- name: Link posthog-cloud at master
|
2020-09-01 12:07:48 +02:00
|
|
|
|
run: |
|
|
|
|
|
cp -r multi_tenancy deploy/
|
|
|
|
|
cp -r messaging deploy/
|
|
|
|
|
cat multi_tenancy_settings.py >> deploy/posthog/settings.py
|
|
|
|
|
cat requirements.txt >> deploy/requirements.txt
|
|
|
|
|
|
2020-09-30 14:59:46 +02:00
|
|
|
|
- name: Set up Python 3.8
|
2020-09-01 12:07:48 +02:00
|
|
|
|
uses: actions/setup-python@v2
|
|
|
|
|
with:
|
2020-09-30 14:59:46 +02:00
|
|
|
|
python-version: 3.8
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
|
|
|
|
- name: Install requirements.txt dependencies with pip
|
|
|
|
|
run: |
|
|
|
|
|
cd deploy
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
2021-03-23 11:39:13 +01:00
|
|
|
|
python -m pip install freezegun fakeredis pytest pytest-mock pytest-django
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
2020-11-10 08:47:57 +01:00
|
|
|
|
# The 2-step migration process (first master, then current branch) verifies that it'll always
|
|
|
|
|
# be possible to migrate to the new version without problems in production
|
|
|
|
|
- name: Migrate initially at master, then remove master deploy code
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
|
|
|
|
python deploy/manage.py migrate
|
|
|
|
|
rm -rf deploy
|
|
|
|
|
|
|
|
|
|
- name: Checkout current branch
|
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
|
with:
|
|
|
|
|
path: 'deploy/'
|
|
|
|
|
|
2021-04-09 09:04:53 +02:00
|
|
|
|
- name: Install requirements.txt dependencies with pip at current branch
|
|
|
|
|
run: |
|
|
|
|
|
cd deploy
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
|
|
|
|
python -m pip install freezegun fakeredis pytest pytest-mock pytest-django
|
|
|
|
|
|
2021-02-24 23:20:05 +01:00
|
|
|
|
- name: Link posthog-cloud at current branch
|
2020-11-10 08:47:57 +01:00
|
|
|
|
run: |
|
2021-02-24 08:32:44 +01:00
|
|
|
|
cp deploy/ee/conftest.py multi_tenancy/conftest.py
|
|
|
|
|
cp deploy/ee/conftest.py messaging/conftest.py
|
2020-11-10 08:47:57 +01:00
|
|
|
|
cp -r multi_tenancy deploy/
|
|
|
|
|
cp -r messaging deploy/
|
|
|
|
|
cat multi_tenancy_settings.py >> deploy/posthog/settings.py
|
|
|
|
|
cat requirements.txt >> deploy/requirements.txt
|
|
|
|
|
|
2020-09-01 12:07:48 +02:00
|
|
|
|
- name: Check migrations
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
|
|
|
|
cd deploy
|
|
|
|
|
python manage.py makemigrations --check --dry-run
|
2020-11-10 08:47:57 +01:00
|
|
|
|
python manage.py migrate
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
2020-10-28 09:38:01 +01:00
|
|
|
|
- name: Run posthog tests
|
2020-09-01 12:07:48 +02:00
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
|
|
|
|
cd deploy
|
|
|
|
|
mkdir -p frontend/dist
|
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
2021-02-24 08:32:44 +01:00
|
|
|
|
pytest posthog --reuse-db -m "not skip_on_multitenancy"
|
2020-10-28 09:38:01 +01:00
|
|
|
|
|
2021-02-24 23:20:05 +01:00
|
|
|
|
- name: Run cloud tests (posthog-cloud)
|
2020-10-28 09:38:01 +01:00
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
PRIMARY_DB: 'clickhouse'
|
|
|
|
|
CLICKHOUSE_HOST: 'localhost'
|
|
|
|
|
CLICKHOUSE_DATABASE: 'posthog_test'
|
|
|
|
|
CLICKHOUSE_SECURE: 'False'
|
|
|
|
|
CLICKHOUSE_VERIFY: 'False'
|
|
|
|
|
run: |
|
2021-03-02 22:47:56 +01:00
|
|
|
|
source .env.template
|
2020-10-28 09:38:01 +01:00
|
|
|
|
cd deploy
|
2021-02-24 08:32:44 +01:00
|
|
|
|
pytest multi_tenancy messaging -m "not skip_on_multitenancy"
|
2020-11-10 08:47:57 +01:00
|
|
|
|
- name: Run EE tests
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
PRIMARY_DB: 'clickhouse'
|
|
|
|
|
CLICKHOUSE_HOST: 'localhost'
|
|
|
|
|
CLICKHOUSE_DATABASE: 'posthog_test'
|
|
|
|
|
CLICKHOUSE_SECURE: 'False'
|
|
|
|
|
CLICKHOUSE_VERIFY: 'False'
|
|
|
|
|
run: |
|
2021-02-24 08:32:44 +01:00
|
|
|
|
cd deploy/
|
2021-04-03 01:40:09 +02:00
|
|
|
|
pytest ee -s
|
2020-09-10 18:20:29 +02:00
|
|
|
|
|
|
|
|
|
foss:
|
2020-11-10 08:47:57 +01:00
|
|
|
|
name: Django tests – FOSS
|
2020-09-10 18:20:29 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-30 17:17:58 +02:00
|
|
|
|
if: ${{ github.actor != 'posthog-contributions-bot[bot]' }}
|
2020-09-10 18:20:29 +02:00
|
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:12
|
|
|
|
|
env:
|
|
|
|
|
POSTGRES_USER: postgres
|
|
|
|
|
POSTGRES_PASSWORD: postgres
|
|
|
|
|
POSTGRES_DB: postgres
|
|
|
|
|
ports: ['5432:5432']
|
|
|
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
|
|
|
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v1
|
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 1
|
|
|
|
|
|
2020-09-30 14:59:46 +02:00
|
|
|
|
- name: Set up Python 3.8
|
2020-10-26 11:11:02 +01:00
|
|
|
|
uses: actions/setup-python@v2
|
2020-09-10 18:20:29 +02:00
|
|
|
|
with:
|
2020-09-30 14:59:46 +02:00
|
|
|
|
python-version: 3.8
|
2020-09-10 18:20:29 +02:00
|
|
|
|
|
|
|
|
|
- uses: actions/cache@v1
|
|
|
|
|
with:
|
|
|
|
|
path: ~/.cache/pip
|
|
|
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
|
|
|
|
restore-keys: |
|
|
|
|
|
${{ runner.os }}-pip-
|
|
|
|
|
|
|
|
|
|
- name: Install requirements.txt dependencies with pip
|
|
|
|
|
run: |
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install -r requirements.txt
|
2021-03-23 11:39:13 +01:00
|
|
|
|
python -m pip install freezegun fakeredis pytest pytest-mock pytest-django
|
2020-09-10 18:20:29 +02:00
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
|
|
- name: Remove ee
|
|
|
|
|
run: |
|
|
|
|
|
rm -rf ee/
|
|
|
|
|
|
|
|
|
|
- name: Check migrations
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: python manage.py makemigrations --check --dry-run
|
|
|
|
|
|
|
|
|
|
- name: Run tests
|
|
|
|
|
env:
|
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
|
run: |
|
|
|
|
|
mkdir -p frontend/dist
|
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
2021-02-24 08:32:44 +01:00
|
|
|
|
pytest -m "not ee"
|