Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CI tests in container #5752

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
container:
image: python:3.12-bullseye
env:
python-version: '3.12.x'
node-version: '20'
mailroom-version: '9.3.59'

Expand Down Expand Up @@ -39,13 +40,8 @@ jobs:

- name: Install Linux packages
run: |
sudo apt update
sudo apt install -y --no-install-recommends libgdal-dev ffmpeg

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
apt-get update
apt-get install -y --no-install-recommends libgdal-dev ffmpeg

- name: Install Poetry
uses: snok/install-poetry@v1
Expand All @@ -57,24 +53,29 @@ jobs:
with:
node-version: ${{ env.node-version }}

- name: Install Mailroom
run: |
git clone --depth 1 https://github.com/${{ github.repository_owner }}/mailroom
cd mailroom
go install github.com/${{ github.repository_owner }}/mailroom/cmd/mailroom
# start mailroom but use different redis db so that it doesn't actually handle tasks
./mailroom -db=postgres://temba:temba@postgres:5432/temba?sslmode=disable -redis=redis://redis:6379/15 -log-level=info > mailroom.log &
working-directory: ${{ github.workspace }}

- name: Install and start DynamoDB
uses: rrainn/dynamodb-action@v4.0.0
with:
port: 6000

- name: Initialize environment
run: |
npm install -g yarn less
poetry install
yarn install
sudo yarn global add less
ln -s ${{ github.workspace }}/temba/settings.py.dev ${{ github.workspace }}/temba/settings.py
ln -s settings.py.dev temba/settings.py
poetry run python manage.py migrate
poetry run python manage.py migrate_dynamo --testing
# fetch, extract and start mailroom
wget https://github.com/${{ github.repository_owner }}/mailroom/releases/download/v${{ env.mailroom-version }}/mailroom_${{ env.mailroom-version }}_linux_amd64.tar.gz
tar -xvf mailroom_${{ env.mailroom-version }}_linux_amd64.tar.gz mailroom
# start mailroom but use different redis db so that it doesn't actually handle tasks
./mailroom -db=postgres://temba:temba@localhost:5432/temba?sslmode=disable -redis=redis://localhost:6379/15 -log-level=info > mailroom.log &
working-directory: ${{ github.workspace }} # https://github.com/actions/runner/issues/2058#issuecomment-2085119510

- name: Run pre-test checks
run: |
Expand All @@ -83,13 +84,15 @@ jobs:
# check we can collect and compress all static files
poetry run python manage.py collectstatic --noinput --verbosity=0
poetry run python manage.py compress --extension=".html" --settings=temba.settings_compress
working-directory: ${{ github.workspace }}

- name: Run tests
run: |
poetry run coverage run manage.py test --keepdb --noinput --verbosity=2
poetry run coverage report -i
poetry run coverage xml
poetry run coverage html
working-directory: ${{ github.workspace }}

- name: Save coverage report as artifact
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion temba/archives/tests/test_archivecrudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_read(self):
archive = self.create_archive(Archive.TYPE_MSG, "D", date(2020, 7, 31), [{"id": 1}, {"id": 2}])

download_url = (
f"http://localhost:9000/test-archives/{self.org.id}/message_D20200731_{archive.hash}.jsonl.gz?response-con"
f"http://minio:9000/test-archives/{self.org.id}/message_D20200731_{archive.hash}.jsonl.gz?response-con"
f"tent-disposition=attachment%3B&response-content-type=application%2Foctet&response-content-encoding=none"
)

Expand Down
16 changes: 5 additions & 11 deletions temba/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

DATA_UPLOAD_MAX_NUMBER_FIELDS = 2500 # needed for exports of big workspaces

_db_host = "postgres"
_redis_host = "redis"
_minio_host = "minio"
_dynamo_host = "dynamo"

# -----------------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------------
Expand All @@ -27,17 +32,6 @@
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
DEBUG = False

if os.getenv("REMOTE_CONTAINERS") == "true":
_db_host = "postgres"
_redis_host = "redis"
_minio_host = "minio"
_dynamo_host = "dynamo"
else:
_db_host = "localhost"
_redis_host = "localhost"
_minio_host = "localhost"
_dynamo_host = "localhost"

# -----------------------------------------------------------------------------------
# Email
# -----------------------------------------------------------------------------------
Expand Down
Loading