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

Add Appwrite Tests and Matrix the workflow #32

Draft
wants to merge 10 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
109 changes: 109 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

# Appwrite
_APP_ENV=development
_APP_EDITION=self-hosted
_APP_LOCALE=en
_APP_WORKER_PER_CORE=6
_APP_CONSOLE_WHITELIST_ROOT=disabled
_APP_CONSOLE_WHITELIST_EMAILS=
_APP_CONSOLE_WHITELIST_IPS=
_APP_CONSOLE_COUNTRIES_DENYLIST=AQ
_APP_CONSOLE_HOSTNAMES=localhost,appwrite.io,*.appwrite.io
_APP_SYSTEM_EMAIL_NAME=Appwrite
[email protected]
[email protected]
_APP_SYSTEM_RESPONSE_FORMAT=
_APP_OPTIONS_ABUSE=disabled
_APP_OPTIONS_ROUTER_PROTECTION=disabled
_APP_OPTIONS_FORCE_HTTPS=disabled
_APP_OPTIONS_FUNCTIONS_FORCE_HTTPS=disabled
_APP_OPENSSL_KEY_V1=your-secret-key
_APP_DOMAIN=localhost
_APP_DOMAIN_FUNCTIONS=functions.localhost
_APP_DOMAIN_TARGET=localhost
_APP_REDIS_HOST=redis
_APP_REDIS_PORT=6379
_APP_REDIS_PASS=
_APP_REDIS_USER=
_APP_DB_HOST=mariadb
_APP_DB_PORT=3306
_APP_DB_SCHEMA=appwrite
_APP_DB_USER=user
_APP_DB_PASS=password
_APP_DB_ROOT_PASS=rootsecretpassword
_APP_STORAGE_DEVICE=Local
_APP_STORAGE_S3_ACCESS_KEY=
_APP_STORAGE_S3_SECRET=
_APP_STORAGE_S3_REGION=us-east-1
_APP_STORAGE_S3_BUCKET=
_APP_STORAGE_DO_SPACES_ACCESS_KEY=
_APP_STORAGE_DO_SPACES_SECRET=
_APP_STORAGE_DO_SPACES_REGION=us-east-1
_APP_STORAGE_DO_SPACES_BUCKET=
_APP_STORAGE_BACKBLAZE_ACCESS_KEY=
_APP_STORAGE_BACKBLAZE_SECRET=
_APP_STORAGE_BACKBLAZE_REGION=us-west-004
_APP_STORAGE_BACKBLAZE_BUCKET=
_APP_STORAGE_LINODE_ACCESS_KEY=
_APP_STORAGE_LINODE_SECRET=
_APP_STORAGE_LINODE_REGION=eu-central-1
_APP_STORAGE_LINODE_BUCKET=
_APP_STORAGE_WASABI_ACCESS_KEY=
_APP_STORAGE_WASABI_SECRET=
_APP_STORAGE_WASABI_REGION=eu-central-1
_APP_STORAGE_WASABI_BUCKET=
_APP_STORAGE_ANTIVIRUS=disabled
_APP_STORAGE_ANTIVIRUS_HOST=clamav
_APP_STORAGE_ANTIVIRUS_PORT=3310
_APP_SMTP_HOST=maildev
_APP_SMTP_PORT=1025
_APP_SMTP_SECURE=
_APP_SMTP_USERNAME=
_APP_SMTP_PASSWORD=
_APP_SMS_PROVIDER=sms://username:password@mock
_APP_SMS_FROM=+123456789
_APP_SMS_PROJECTS_DENY_LIST=
_APP_STORAGE_LIMIT=30000000
_APP_STORAGE_PREVIEW_LIMIT=20000000
_APP_FUNCTIONS_SIZE_LIMIT=30000000
_APP_FUNCTIONS_TIMEOUT=900
_APP_FUNCTIONS_BUILD_TIMEOUT=900
_APP_FUNCTIONS_CPUS=1
_APP_FUNCTIONS_MEMORY=1024
_APP_FUNCTIONS_INACTIVE_THRESHOLD=600
_APP_FUNCTIONS_MAINTENANCE_INTERVAL=600
_APP_FUNCTIONS_RUNTIMES_NETWORK=runtimes
_APP_EXECUTOR_SECRET=your-secret-key
_APP_EXECUTOR_HOST=http://proxy/v1
_APP_FUNCTIONS_RUNTIMES=php-8.0,node-18.0,python-3.9,ruby-3.1
_APP_MAINTENANCE_INTERVAL=86400
_APP_MAINTENANCE_DELAY=
_APP_MAINTENANCE_RETENTION_CACHE=2592000
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
_APP_MAINTENANCE_RETENTION_ABUSE=86400
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
_APP_USAGE_AGGREGATION_INTERVAL=30
_APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000
_APP_MAINTENANCE_RETENTION_SCHEDULES=86400
_APP_USAGE_STATS=enabled
_APP_LOGGING_PROVIDER=
_APP_LOGGING_CONFIG=
_APP_GRAPHQL_MAX_BATCH_SIZE=10
_APP_GRAPHQL_MAX_COMPLEXITY=250
_APP_GRAPHQL_MAX_DEPTH=4
_APP_DOCKER_HUB_USERNAME=
_APP_DOCKER_HUB_PASSWORD=
_APP_VCS_GITHUB_APP_NAME=
_APP_VCS_GITHUB_PRIVATE_KEY=disabled
_APP_VCS_GITHUB_APP_ID=
_APP_VCS_GITHUB_CLIENT_ID=
_APP_VCS_GITHUB_CLIENT_SECRET=
_APP_VCS_GITHUB_WEBHOOK_SECRET=
_APP_MIGRATIONS_FIREBASE_CLIENT_ID=
_APP_MIGRATIONS_FIREBASE_CLIENT_SECRET=
_APP_ASSISTANT_OPENAI_API_KEY=
_APP_MESSAGE_SMS_TEST_DSN=
_APP_MESSAGE_EMAIL_TEST_DSN=
_APP_MESSAGE_PUSH_TEST_DSN=
_APP_WEBHOOK_MAX_FAILED_ATTEMPTS=10
_APP_PROJECT_REGIONS=default
60 changes: 55 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
name: Tests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IMAGE: migrations-dev
CACHE_KEY: migrations-dev-${{ github.sha }}

on:
pull_request:
push: { branches: [main] }

jobs:
tests:
name: Run Test Suite
setup:
name: Setup & Build Migrations Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Migrations
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: ${{ env.IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Cache Docker Image
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar

source_unit_tests:
name: Run Source Unit Tests
runs-on: ubuntu-latest
needs: setup
env:
COMPOSE_FILE: docker-compose.yml

strategy:
fail-fast: false
matrix:
adapter: [Appwrite, Supabase, NHost]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run Tests
- name: Load Cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
fail-on-cache-miss: true

- name: Bring up services
run: docker-compose up -d

- name: Run ${{matrix.adapter}} Tests
run: |
docker-compose up -d --build && sleep 5 && docker compose exec tests php ./vendor/bin/phpunit
docker compose exec tests php ./vendor/bin/phpunit /app/tests/Migration/Unit/Sources/${{matrix.adapter}}Test.php
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ composer.lock
/vendor/
/.idea/
*.cache
.env
test-service-account.json
.DS_Store
localBackup/
Expand Down
34 changes: 31 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,44 @@ COPY tests/Migration/resources/nhost/1_globals.sql /docker-entrypoint-initdb.d/1
COPY tests/Migration/resources/nhost/2_main.sql /docker-entrypoint-initdb.d/2_main.sql

FROM composer:2.0 as composer

WORKDIR /usr/local/src/
COPY composer.json /usr/local/src/
RUN composer install --ignore-platform-reqs

FROM php:8.1.21-fpm-alpine3.18 as tests
FROM php:8.1.21 as tests

# Install Appwrite Toolkit
RUN set -ex \
&& mkdir -p /app/toolkit \
&& cd /app/toolkit \
&& curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get install nodejs git -y \
&& git clone https://github.com/Meldiron/appwrite-toolkit.git \
&& cd appwrite-toolkit \
&& git checkout feat-refactor-cli \
&& npm install \
&& npm link

# Postgres
RUN set -ex \
&& apk --no-cache add postgresql-libs postgresql-dev \
&& apt-get install -y libpq-dev \
&& docker-php-ext-install pdo pdo_pgsql \
&& apk del postgresql-dev
&& apt-get remove -y libpq-dev

## Install XDebug, Remove before commit.
RUN \
git clone --depth 1 --branch 3.3.1 https://github.com/xdebug/xdebug && \
cd xdebug && \
phpize && \
./configure && \
make && make install

# Enable Extensions
COPY dev/xdebug.ini /usr/src/code/dev/xdebug.ini
RUN cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

COPY ./src /app/src
COPY ./tests /app/src/tests
COPY --from=composer /usr/local/src/vendor /app/vendor
Expand Down
27 changes: 27 additions & 0 deletions bin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SOURCE=supabase

SOURCE_APPWRITE_TEST_PROJECT=6646cbd3874a550d78e1
SOURCE_APPWRITE_TEST_ENDPOINT=http://localhost/v1
SOURCE_APPWRITE_TEST_KEY=d485cca1318af57b68213bcecc9defbeeccb1f3cf94774a4f097b61415f38b2f78f13faf2a3ec91930105df5b8266854f6f8219a8d693040a83ea600fd4458875f741fc7e318b3eca685c3c25a8523d765bcda9ec7f7e8129448cc5986b2fc2c7797300ae27ed68e764dbda508e82a66514fcf9da3187d0eb5f4453e031a1f7d

FIREBASE_TEST_PROJECT=testProject
FIREBASE_TEST_ACCOUNT='{type: "service_account", ...}'

SUPABASE_TEST_ENDPOINT=https://iwnzcwbimmpurmkqcueg.supabase.co
SUPABASE_TEST_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
SUPABASE_TEST_HOST=aws-0-eu-west-2.pooler.supabase.com
SUPABASE_TEST_DATABASE=postgres
SUPABASE_TEST_USERNAME=postgres.iwnzcwbimmpurmkqcueg
SUPABASE_TEST_PASSWORD=ueTlfhe4bcNfiqHV

NHOST_TEST_SUBDOMAIN=xxxxxxxxxxx
NHOST_TEST_REGION=eu-central-1
NHOST_TEST_SECRET=xxxxxxxxxxxxxxxxx
NHOST_TEST_DATABASE=xxxxxxxxxxxxxxx
NHOST_TEST_USERNAME=postgres
NHOST_TEST_PASSWORD=xxxxxxxxxxxxxxx


DESTINATION_APPWRITE_TEST_PROJECT=6646dd50000c4b4f2b04
DESTINATION_APPWRITE_TEST_ENDPOINT=http://localhost/v1
DESTINATION_APPWRITE_TEST_KEY=c8c3ee7f9491b8320cd57aaad08531a5bbd77651da95b166ee5c26b7f9081dc124952b37a75d1cc4302dd9439d884d7265ceb8c88563cbb3d5bc2bad19381d272233e3836cc7035a166fc75e405dc5a674eeee0c11e646e35848326870974f4ef29412ad97bd81e095fb9c2739fed079f7704a83d8924d199cd65d02534cdda9
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"require-dev": {
"phpunit/phpunit": "9.*",
"vlucas/phpdotenv": "5.*",
"laravel/pint": "1.*"
"laravel/pint": "1.*",
"utopia-php/cli": "^0.18.0"
}
}
6 changes: 6 additions & 0 deletions dev/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
Loading
Loading