Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into create-table-mariadb
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Database/Adapter/MariaDB.php
#	src/Database/Adapter/Postgres.php
  • Loading branch information
abnegate committed Aug 9, 2023
2 parents 94ed8a2 + 98dc6a9 commit b5f8c60
Show file tree
Hide file tree
Showing 94 changed files with 18,308 additions and 5,721 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "CodeQL"

on: [ pull_request ]
jobs:
lint:
name: CodeQL
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- run: git checkout HEAD^2

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
20 changes: 20 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Linter"

on: [ pull_request ]
jobs:
lint:
name: Linter
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- run: git checkout HEAD^2

- name: Run Linter
run: |
docker run --rm -v $PWD:/app composer sh -c \
"composer install --profile --ignore-platform-reqs && composer lint"
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Tests"

on: [pull_request]
jobs:
tests:
name: Unit & E2E
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: recursive

- run: git checkout HEAD^2

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

- name: Build image
uses: docker/build-push-action@v3
with:
context: .
push: false
tags: database-dev
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Start Databases
run: |
docker compose up -d
sleep 10
- name: Run Tests
run: docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml

- name: Check Coverage
run: docker compose exec -T tests vendor/bin/coverage-check tmp/clover.xml 90
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ database.sql
## - Oh Wess!
Makefile
.envrc
.vscode
.vscode
tmp
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

74 changes: 74 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,80 @@ This is also important for the Utopia-php lead developers to be able to give tec

You can follow our [Adding new Database Adapter](docs/add-new-adapter.md) tutorial to add new database support in this library.

## Tests

To run tests, you first need to bring up the example Docker stack with the following command:

```bash
docker compose up -d --build
```

To run all unit tests, use the following Docker command:

```bash
docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml tests
```

To run tests for a single file, use the following Docker command structure:

```bash
docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml tests/Database/[FILE_PATH]
```

To run static code analysis, use the following phpstan command:

```bash
composer check
```

### Load testing

Three commands have been added to `bin/` to fill, index, and query the DB to test changes:

- `bin/load` invokes `bin/tasks/load.php`
- `bin/index` invokes `bin/tasks/index.php`
- `bin/query` invokes `bin/tasks/query.php`

To test your DB changes under load:

#### Load the database

```bash
docker compose exec tests bin/load --adapter=[adapter] --limit=[limit] [--name=[name]]

# [adapter]: either 'mongodb' or 'mariadb', no quotes
# [limit]: integer of total documents to generate
# [name]: (optional) name for new database
```
#### Create indexes
```bash
docker compose exec tests bin/index --adapter=[adapter] --name=[name]

# [adapter]: either 'mongodb' or 'mariadb', no quotes
# [name]: name of filled database by bin/load
```
#### Run Query Suite
```bash
docker compose exec tests bin/query --adapter=[adapter] --limit=[limit] --name=[name]

# [adapter]: either 'mongodb' or 'mariadb', no quotes
# [limit]: integer of query limit (default 25)
# [name]: name of filled database by bin/load
```
#### Visualize Query Results
```bash
docker compose exec tests bin/compare
```
Navigate to `localhost:8708` to visualize query results.
## Other Ways to Help
Pull requests are great, but there are many other areas where you can help Utopia-php.
Expand Down
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ RUN \
&& ./configure \
&& make && make install

## PCOV Extension
FROM compile AS pcov
RUN \
git clone https://github.com/krakjoe/pcov.git \
&& cd pcov \
&& phpize \
&& ./configure --enable-pcov \
&& make && make install

FROM compile as final

LABEL maintainer="[email protected]"
Expand All @@ -62,6 +71,7 @@ WORKDIR /usr/src/code
RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini
RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini
RUN echo extension=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini
RUN echo extension=pcov.so >> /usr/local/etc/php/conf.d/pcov.ini

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

Expand All @@ -73,8 +83,10 @@ COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor
COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20200930/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
COPY --from=redis /usr/local/lib/php/extensions/no-debug-non-zts-20200930/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20200930/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
COPY --from=pcov /usr/local/lib/php/extensions/no-debug-non-zts-20200930/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/

# Add Source Code
COPY . /usr/src/code
COPY ./bin /usr/src/code/bin
COPY ./src /usr/src/code/src

CMD [ "tail", "-f", "/dev/null" ]
Loading

0 comments on commit b5f8c60

Please sign in to comment.