2020-08-18 11:08:40 +02:00
|
|
|
name: Backend CI
|
|
|
|
|
|
|
|
on:
|
|
|
|
- pull_request
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
code-quality:
|
|
|
|
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
|
|
|
|
|
|
|
|
- name: Set up Python 3.7
|
|
|
|
uses: actions/setup-python@v1
|
|
|
|
with:
|
|
|
|
python-version: 3.7
|
|
|
|
|
|
|
|
- uses: actions/cache@v1
|
|
|
|
with:
|
|
|
|
path: ~/.cache/pip
|
|
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements/dev.txt') }}
|
|
|
|
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
|
|
|
|
python -m pip install -r requirements/dev.txt
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
- name: Check formatting with black
|
|
|
|
run: |
|
|
|
|
black -l 120 --check .
|
|
|
|
|
|
|
|
- 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:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
REDIS_URL: 'redis://localhost'
|
|
|
|
run: |
|
|
|
|
mypy posthog
|
|
|
|
|
|
|
|
django:
|
|
|
|
name: Django tests
|
|
|
|
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
|
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
|
|
|
|
|
|
|
|
- name: Set up Python 3.7
|
|
|
|
uses: actions/setup-python@v1
|
|
|
|
with:
|
|
|
|
python-version: 3.7
|
|
|
|
|
|
|
|
- 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
|
|
|
|
python -m pip install freezegun
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
- name: Check migrations
|
|
|
|
env:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
REDIS_URL: 'redis://localhost'
|
|
|
|
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:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
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
|
2020-09-09 01:12:27 +02:00
|
|
|
python manage.py test posthog -v 2
|
2020-09-09 06:00:37 +02:00
|
|
|
- name: Run EE tests
|
|
|
|
env:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
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
|
|
|
|
python manage.py test ee --testrunner="ee.clickhouse.clickhouse_test_runner.ClickhouseTestRunner"
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
|
|
multitenancy:
|
|
|
|
name: Django tests (multitenancy)
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
services:
|
2020-09-10 03:34:13 +02:00
|
|
|
redis:
|
|
|
|
# Docker Hub image
|
|
|
|
image: redis
|
|
|
|
# Set health checks to wait until redis has started
|
|
|
|
options: >-
|
|
|
|
--health-cmd "redis-cli ping"
|
|
|
|
--health-interval 10s
|
|
|
|
--health-timeout 5s
|
|
|
|
--health-retries 5
|
2020-09-01 12:07:48 +02:00
|
|
|
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:
|
|
|
|
- name: Fetch posthog-production
|
|
|
|
run: |
|
|
|
|
curl -L https://github.com/posthog/posthog-production/tarball/master | tar --strip-components=1 -xz --
|
|
|
|
mkdir deploy/
|
|
|
|
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
path: 'deploy/'
|
|
|
|
|
|
|
|
- name: Link posthog-production
|
|
|
|
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
|
|
|
|
|
|
|
|
- name: Set up Python 3.7
|
|
|
|
uses: actions/setup-python@v2
|
|
|
|
with:
|
|
|
|
python-version: 3.7
|
|
|
|
|
|
|
|
- uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
path: ~/.cache/pip
|
|
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-pip-
|
|
|
|
|
|
|
|
- name: Install requirements.txt dependencies with pip
|
|
|
|
run: |
|
|
|
|
cd deploy
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
python -m pip install -r requirements.txt
|
|
|
|
python -m pip install freezegun
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
- name: Check migrations
|
|
|
|
env:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
REDIS_URL: 'redis://localhost'
|
|
|
|
run: |
|
|
|
|
cd deploy
|
|
|
|
python manage.py makemigrations --check --dry-run
|
|
|
|
|
|
|
|
- name: Run tests
|
|
|
|
env:
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
|
|
|
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
|
|
|
|
run: |
|
|
|
|
source env.template
|
|
|
|
cd deploy
|
|
|
|
mkdir -p frontend/dist
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
2020-09-10 03:34:13 +02:00
|
|
|
python manage.py test posthog --keepdb -v 2 --exclude-tag=skip_on_multitenancy
|