2022-02-22 16:06:04 +01:00
|
|
|
|
# This workflow runs all of our backend django tests.
|
|
|
|
|
#
|
|
|
|
|
# If these tests get too slow, look at increasing concurrency and re-timing the tests by manually dispatching
|
|
|
|
|
# .github/workflows/ci-backend-update-test-timing.yml action
|
2020-08-18 11:08:40 +02:00
|
|
|
|
name: Backend CI
|
|
|
|
|
|
|
|
|
|
on:
|
2021-10-21 09:12:19 +02:00
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- master
|
|
|
|
|
pull_request:
|
2022-02-22 16:06:04 +01:00
|
|
|
|
workflow_dispatch:
|
|
|
|
|
inputs:
|
|
|
|
|
clickhouseServerVersion:
|
|
|
|
|
description: ClickHouse server version. Leave blank for default
|
|
|
|
|
type: string
|
|
|
|
|
|
2021-02-24 08:32:44 +01:00
|
|
|
|
env:
|
|
|
|
|
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
|
2021-10-01 10:43:50 +02:00
|
|
|
|
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
|
2021-02-24 08:32:44 +01:00
|
|
|
|
REDIS_URL: 'redis://localhost'
|
2021-10-01 10:43:50 +02:00
|
|
|
|
CLICKHOUSE_HOST: 'localhost'
|
|
|
|
|
CLICKHOUSE_SECURE: 'False'
|
|
|
|
|
CLICKHOUSE_VERIFY: 'False'
|
|
|
|
|
SAML_DISABLED: 1
|
2021-08-25 10:58:09 +02:00
|
|
|
|
TEST: 1
|
2022-02-22 16:06:04 +01:00
|
|
|
|
CLICKHOUSE_SERVER_IMAGE_VERSION: ${{ github.event.inputs.clickhouseServerVersion || '' }}
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
|
|
|
|
jobs:
|
2021-10-13 14:09:40 +02:00
|
|
|
|
# Job to decide if we should run backend ci
|
|
|
|
|
# See https://github.com/dorny/paths-filter#conditional-execution for more details
|
2021-10-12 09:21:10 +02:00
|
|
|
|
changes:
|
|
|
|
|
runs-on: ubuntu-latest
|
2021-10-25 23:59:31 +02:00
|
|
|
|
if: github.repository == 'PostHog/posthog'
|
2021-10-13 14:09:40 +02:00
|
|
|
|
name: Determine need to run backend checks
|
2021-10-12 09:21:10 +02:00
|
|
|
|
# Set job outputs to values from filter step
|
|
|
|
|
outputs:
|
|
|
|
|
backend: ${{ steps.filter.outputs.backend }}
|
|
|
|
|
steps:
|
2021-10-21 09:42:41 +02:00
|
|
|
|
# For pull requests it's not necessary to checkout the code, but we
|
|
|
|
|
# also want this to run on master so we need to checkout
|
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
|
|
2021-10-12 09:21:10 +02:00
|
|
|
|
- uses: dorny/paths-filter@v2
|
|
|
|
|
id: filter
|
|
|
|
|
with:
|
|
|
|
|
filters: |
|
|
|
|
|
backend:
|
|
|
|
|
# Avoid running backend tests for irrelevant changes
|
|
|
|
|
# NOTE: we are at risk of missing a dependency here. We could make
|
|
|
|
|
# the dependencies more clear if we separated the backend/frontend
|
|
|
|
|
# code completely
|
|
|
|
|
- 'ee/**/*'
|
|
|
|
|
- 'posthog/**/*'
|
|
|
|
|
- requirements.txt
|
|
|
|
|
- requirements-dev.txt
|
|
|
|
|
- mypy.ini
|
|
|
|
|
- pytest.ini
|
|
|
|
|
# Make sure we run if someone is explicitly change the workflow
|
|
|
|
|
- .github/workflows/ci-backend.yml
|
2022-02-22 16:06:04 +01:00
|
|
|
|
- .github/workflows/backend-tests-action/action.yml
|
2021-10-12 09:21:10 +02:00
|
|
|
|
|
2021-01-22 15:36:30 +01:00
|
|
|
|
backend-code-quality:
|
2021-10-12 09:21:10 +02:00
|
|
|
|
needs: changes
|
|
|
|
|
# Make sure we only run on backend changes
|
2021-10-25 23:59:31 +02:00
|
|
|
|
if: ${{ needs.changes.outputs.backend == 'true' && github.repository == 'PostHog/posthog' }}
|
2021-10-12 09:21:10 +02:00
|
|
|
|
|
2022-02-22 16:06:04 +01:00
|
|
|
|
name: Python code quality checks
|
2020-08-18 11:08:40 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:12
|
|
|
|
|
env:
|
2021-07-16 02:20:37 +02:00
|
|
|
|
POSTGRES_USER: posthog
|
|
|
|
|
POSTGRES_PASSWORD: posthog
|
|
|
|
|
POSTGRES_DB: posthog
|
2020-08-18 11:08:40 +02:00
|
|
|
|
ports: ['5432:5432']
|
|
|
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
|
|
|
|
|
|
|
|
steps:
|
2022-02-22 16:06:04 +01:00
|
|
|
|
- uses: actions/checkout@v2
|
2020-08-18 11:08:40 +02:00
|
|
|
|
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
|
|
|
|
|
2021-09-13 14:55:13 +02:00
|
|
|
|
- uses: syphar/restore-virtualenv@v1.2
|
2021-11-03 10:33:16 +01:00
|
|
|
|
id: cache-backend-tests
|
|
|
|
|
with:
|
|
|
|
|
custom_cache_key_element: v1-
|
2021-09-13 14:55:13 +02:00
|
|
|
|
|
2021-05-25 18:25:37 +02:00
|
|
|
|
- uses: syphar/restore-pip-download-cache@v1
|
2021-11-03 10:33:16 +01:00
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
2021-09-13 14:55:13 +02:00
|
|
|
|
|
2021-05-25 18:25:37 +02:00
|
|
|
|
- name: Install python dependencies
|
2021-11-03 10:33:16 +01:00
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
2020-08-18 11:08:40 +02:00
|
|
|
|
run: |
|
2020-11-10 10:17:48 +01:00
|
|
|
|
python -m pip install -r requirements-dev.txt
|
2021-04-19 21:59:10 +02:00
|
|
|
|
python -m pip install -r requirements.txt
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
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
|
|
|
|
|
2022-02-18 11:10:32 +01:00
|
|
|
|
- name: Check for errors and code style violations
|
2020-08-18 11:08:40 +02:00
|
|
|
|
run: |
|
2022-02-18 11:10:32 +01:00
|
|
|
|
flake8 .
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
2022-02-18 11:10:32 +01:00
|
|
|
|
- name: Check static typing
|
2020-08-18 11:08:40 +02:00
|
|
|
|
run: |
|
2020-11-02 15:55:20 +01:00
|
|
|
|
mypy .
|
2020-08-18 11:08:40 +02:00
|
|
|
|
|
2022-02-22 16:06:04 +01:00
|
|
|
|
check-migrations:
|
2021-10-12 09:21:10 +02:00
|
|
|
|
needs: changes
|
2021-10-25 23:59:31 +02:00
|
|
|
|
if: ${{ needs.changes.outputs.backend == 'true' && github.repository == 'PostHog/posthog' }}
|
2021-10-12 09:21:10 +02:00
|
|
|
|
|
2022-02-22 16:06:04 +01:00
|
|
|
|
name: Validate django migrations
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
|
|
|
|
|
|
- name: Start stack with Docker Compose
|
|
|
|
|
run: |
|
|
|
|
|
docker-compose -f docker-compose.dev.yml down
|
|
|
|
|
docker-compose -f docker-compose.dev.yml up -d db &
|
|
|
|
|
|
|
|
|
|
- name: Set up Python
|
|
|
|
|
uses: actions/setup-python@v2
|
|
|
|
|
with:
|
|
|
|
|
python-version: 3.8.5
|
|
|
|
|
|
|
|
|
|
- uses: syphar/restore-virtualenv@v1.2
|
|
|
|
|
id: cache-backend-tests
|
|
|
|
|
with:
|
|
|
|
|
custom_cache_key_element: v1-
|
|
|
|
|
|
|
|
|
|
- uses: syphar/restore-pip-download-cache@v1
|
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
|
|
- name: Install python dependencies
|
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
|
|
|
|
run: |
|
|
|
|
|
python -m pip install -r requirements-dev.txt
|
|
|
|
|
python -m pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
- name: Check migrations
|
|
|
|
|
run: |
|
|
|
|
|
python manage.py makemigrations --check --dry-run
|
|
|
|
|
git fetch origin master
|
|
|
|
|
# `git diff --name-only` returns a list of files that were changed - added OR deleted OR modified
|
|
|
|
|
# With `--name-status` we get the same, but including a column for status, respectively: A, D, M
|
|
|
|
|
# In this check we exclusively care about files that were added (A) in posthog/migrations/
|
|
|
|
|
git diff --name-status origin/master..HEAD | grep "A\tposthog/migrations/" | awk '{print $2}' | python manage.py test_migrations_are_null
|
|
|
|
|
|
|
|
|
|
django:
|
|
|
|
|
needs: changes
|
|
|
|
|
if: ${{ needs.changes.outputs.backend == 'true' && github.repository == 'PostHog/posthog' || github.event_name == 'workflow_dispatch' }}
|
|
|
|
|
|
2021-11-01 16:23:23 +01:00
|
|
|
|
name: Django tests – Py ${{ matrix.python-version }} ${{ matrix.name }} (${{matrix.group}}/${{ matrix.concurrency }})
|
2020-08-18 11:08:40 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
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:
|
2021-11-01 16:23:23 +01:00
|
|
|
|
python-version: ['3.8.5']
|
|
|
|
|
ee: [true]
|
|
|
|
|
foss: [false]
|
|
|
|
|
saml: [false]
|
|
|
|
|
name: ['']
|
|
|
|
|
# :NOTE: Keep concurrency and group's in sync
|
|
|
|
|
concurrency: [5]
|
|
|
|
|
group: [1, 2, 3, 4, 5]
|
|
|
|
|
include:
|
|
|
|
|
# :TRICKY: Run FOSS tests in a separate container
|
|
|
|
|
- python-version: '3.8.5'
|
|
|
|
|
ee: false
|
|
|
|
|
saml: false
|
|
|
|
|
foss: true
|
|
|
|
|
name: 'FOSS'
|
|
|
|
|
concurrency: 1
|
|
|
|
|
group: 1
|
|
|
|
|
# :TRICKY: Run FOSS tests in a separate container
|
|
|
|
|
- python-version: '3.9.0'
|
|
|
|
|
ee: false
|
|
|
|
|
saml: false
|
|
|
|
|
foss: true
|
|
|
|
|
name: 'FOSS'
|
|
|
|
|
concurrency: 1
|
|
|
|
|
group: 1
|
|
|
|
|
# :TRICKY: Run SAML tests in a separate container
|
|
|
|
|
- python-version: '3.8.5'
|
|
|
|
|
ee: false
|
|
|
|
|
saml: true
|
|
|
|
|
foss: false
|
|
|
|
|
name: 'SAML'
|
|
|
|
|
concurrency: 1
|
|
|
|
|
group: 1
|
2020-08-18 11:08:40 +02:00
|
|
|
|
steps:
|
2022-02-22 16:06:04 +01:00
|
|
|
|
- uses: actions/checkout@v2
|
2020-08-18 11:08:40 +02:00
|
|
|
|
with:
|
|
|
|
|
fetch-depth: 1
|
2021-08-27 16:20:49 +02:00
|
|
|
|
|
2022-02-22 16:06:04 +01:00
|
|
|
|
- uses: ./.github/actions/run-backend-tests
|
2020-08-18 11:08:40 +02:00
|
|
|
|
with:
|
2022-02-22 16:06:04 +01:00
|
|
|
|
cache-id: ${{ matrix.name }}
|
2020-10-26 11:11:02 +01:00
|
|
|
|
python-version: ${{ matrix.python-version }}
|
2022-02-22 16:06:04 +01:00
|
|
|
|
ee: ${{ matrix.ee }}
|
|
|
|
|
foss: ${{ matrix.foss }}
|
|
|
|
|
saml: ${{ matrix.saml }}
|
|
|
|
|
concurrency: ${{ matrix.concurrency }}
|
|
|
|
|
group: ${{ matrix.group }}
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
2020-11-10 08:47:57 +01:00
|
|
|
|
cloud:
|
2021-10-12 09:21:10 +02:00
|
|
|
|
needs: changes
|
2021-10-25 23:59:31 +02:00
|
|
|
|
if: ${{ needs.changes.outputs.backend == 'true' && github.repository == 'PostHog/posthog' }}
|
2021-10-12 09:21:10 +02:00
|
|
|
|
|
2020-11-10 08:47:57 +01:00
|
|
|
|
name: Django tests – Cloud
|
2020-09-01 12:07:48 +02:00
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
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/
|
2021-12-16 11:14:21 +01:00
|
|
|
|
cat multi_tenancy_settings.py > deploy/posthog/settings/cloud.py
|
2020-09-01 12:07:48 +02:00
|
|
|
|
cat requirements.txt >> deploy/requirements.txt
|
2021-07-16 02:20:37 +02:00
|
|
|
|
- name: Start stack with Docker Compose
|
2021-12-04 00:42:19 +01:00
|
|
|
|
run: |
|
2022-01-18 20:32:28 +01:00
|
|
|
|
docker-compose -f deploy/docker-compose.dev.yml down
|
2022-02-10 16:20:38 +01:00
|
|
|
|
docker-compose -f deploy/docker-compose.dev.yml up -d db clickhouse zookeeper kafka redis &
|
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
|
2021-08-27 16:20:49 +02:00
|
|
|
|
|
2021-09-13 14:55:13 +02:00
|
|
|
|
- uses: syphar/restore-virtualenv@v1.2
|
2021-05-25 18:25:37 +02:00
|
|
|
|
id: cache-backend-tests
|
2021-09-13 14:55:13 +02:00
|
|
|
|
|
2021-05-25 18:25:37 +02:00
|
|
|
|
- uses: syphar/restore-pip-download-cache@v1
|
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
2021-09-13 14:55:13 +02:00
|
|
|
|
|
2021-05-25 18:25:37 +02:00
|
|
|
|
- name: Install python dependencies
|
|
|
|
|
if: steps.cache-backend-tests.outputs.cache-hit != 'true'
|
2020-09-01 12:07:48 +02:00
|
|
|
|
run: |
|
2021-05-25 18:25:37 +02:00
|
|
|
|
python -m pip install -r deploy/requirements-dev.txt
|
|
|
|
|
python -m pip install -r deploy/requirements.txt
|
2020-09-01 12:07:48 +02:00
|
|
|
|
|
2021-12-15 00:09:16 +01:00
|
|
|
|
- name: Wait for Clickhouse & Kafka
|
2021-12-15 00:50:56 +01:00
|
|
|
|
run: deploy/bin/check_kafka_clickhouse_up
|
2021-12-15 00:09:16 +01: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
|
|
|
|
|
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
|
2021-10-13 16:00:47 +02:00
|
|
|
|
python -m pip install freezegun fakeredis pytest pytest-mock pytest-django syrupy
|
2021-04-09 09:04:53 +02:00
|
|
|
|
|
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/
|
2021-12-16 11:14:21 +01:00
|
|
|
|
cat multi_tenancy_settings.py > deploy/posthog/settings/cloud.py
|
2020-11-10 08:47:57 +01:00
|
|
|
|
cat requirements.txt >> deploy/requirements.txt
|
|
|
|
|
|
2020-09-01 12:07:48 +02:00
|
|
|
|
- name: Check migrations
|
|
|
|
|
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
|
|
|
|
|
2021-10-01 10:43:50 +02:00
|
|
|
|
- name: Add kafka host to /etc/hosts for kafka connectivity
|
|
|
|
|
run: sudo echo "127.0.0.1 kafka" | sudo tee -a /etc/hosts
|
|
|
|
|
|
2021-11-01 16:23:23 +01:00
|
|
|
|
- name: Set up needed files
|
2020-09-01 12:07:48 +02:00
|
|
|
|
run: |
|
|
|
|
|
cd deploy
|
|
|
|
|
mkdir -p frontend/dist
|
2022-01-12 21:06:40 +01:00
|
|
|
|
python manage.py collectstatic --noinput
|
2020-09-01 12:07:48 +02:00
|
|
|
|
touch frontend/dist/index.html
|
|
|
|
|
touch frontend/dist/layout.html
|
|
|
|
|
touch frontend/dist/shared_dashboard.html
|
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
|
|
|
|
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"
|