Skip to content

Commit

Permalink
Integrate with Scrutinizer CI
Browse files Browse the repository at this point in the history
Now we introduce the `ci` environment, which is the environment
where we run the CI tests.

It is based on the prd image, although we need the tests folder
and dependencies to be able to run the tests.

It does not have xdebug installed, as we can use the php builtin
debugger to generate the coverage reports.
  • Loading branch information
hgraca committed May 1, 2018
1 parent c679395 commit b0c561e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
45 changes: 45 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
build:

environment:
variables:
ENV: 'ci'
mysql: false
postgresql: false
redis: false
rabbitmq: false
php:
version: 7.1
ini:
'date.timezone': 'Europe/Amsterdam'
docker:
remote_engine: true
cache:
images:
- 'php:7.1-alpine'
- 'hgraca/explicit-architecture:app.sfn.base'

dependencies:
override:
- true # so scrutinizer does't install the dependencies, which we don't need because they are inside the container

tests:
override:
- command: make test-ci
coverage:
file: var/coverage.clover.xml
format: php-clover

filter:
paths:
- "src/"
dependency_paths:
- "vendor/"

build_failure_conditions:
- 'issues.new.exists'
- 'project.metric_change("scrutinizer.test_coverage", < -0.05)'

checks:
php:
code_rating: true
duplication: true
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ DB_PATH='var/data/blog.sqlite'
box-build-base:
docker build -t ${CONTAINER_NAME_BASE} -f ./build/container/app.base.dockerfile .

box-build-ci:
docker-compose -f build/container/ci/docker-compose.yml build --force-rm app

box-build-dev:
docker-compose -f build/container/dev/docker-compose.yml build --force-rm app

Expand Down Expand Up @@ -84,6 +87,10 @@ dep-clearcache-guest:
dep-install:
ENV='dev' ./bin/run composer install

# We use this only when building the box used in the CI
dep-install-ci-guest:
composer install --optimize-autoloader --no-ansi --no-interaction --no-progress --no-scripts

# We use this only when building the box used in PRD
dep-install-prd-guest:
composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --no-scripts
Expand All @@ -102,10 +109,22 @@ test:
$(MAKE) cs-fix
ENV='tst' ./bin/stop

# We use phpdbg because is part of the core and so that we don't need to install xdebug just to get the coverage.
# Furthermore, phpdbg gives us more info in certain conditions, ie if the memory_limit has been reached.
test-ci:
$(MAKE) box-build-prd
$(MAKE) box-build-ci # This is always run by default in the Ci, but having it here makes it possible to run in dev
ENV='ci' ./bin/run
ENV='ci' ./bin/run make db-setup-guest
ENV='ci' ./bin/run make test_cov-guest
docker exec -it app.sfn.ci cat ${COVERAGE_REPORT_PATH} > ${COVERAGE_REPORT_PATH}
ENV='ci' ./bin/run php vendor/bin/php-cs-fixer fix --verbose --dry-run

test_cov:
ENV='tst' ./bin/run phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover=${COVERAGE_REPORT_PATH}
ENV='tst' ./bin/run make test_cov-guest

# We use phpdbg because is part of the core and so that we don't need to install xdebug just to get the coverage.
# Furthermore, phpdbg gives us more info in certain conditions, ie if the memory_limit has been reached.
test_cov-guest:
phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover=${COVERAGE_REPORT_PATH}

up:
if [ ! -f ${DB_PATH} ]; then $(MAKE) db-setup; fi
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Symfony Demo Application
========================
[![Author][Author]](https://www.herbertograca.com)
[![Software License][License]](LICENSE)

[![Build Status][Build]](https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/build-status/master)
[![Scrutinizer Code Quality][Score]](https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/?branch=master)
[![Coverage Status][Coverage]](https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/code-structure)

[![Code Intelligence Status][CodeInt]](https://scrutinizer-ci.com/code-intelligence)

The "Symfony Demo Application" is a reference application created to show how
to develop Symfony applications following the recommended best practices.
Expand Down Expand Up @@ -77,3 +85,11 @@ Configure the test run itself:

[1]: https://symfony.com/doc/current/reference/requirements.html
[2]: https://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

[Author]: http://img.shields.io/badge/[email protected]?style=flat-square
[License]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square

[Build]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/build.png?b=master
[Score]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/quality-score.png?b=master
[Coverage]: https://img.shields.io/scrutinizer/coverage/g/hgraca/explicit-architecture-php.svg?style=flat-square
[CodeInt]: https://scrutinizer-ci.com/g/hgraca/explicit-architecture-php/badges/code-intelligence.svg?b=master
14 changes: 14 additions & 0 deletions build/container/ci/app.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM hgraca/explicit-architecture:app.sfn.prd

ENV ENV="ci"

COPY ./tests /opt/app/tests

COPY ./phpunit.xml.dist /opt/app/
COPY ./.php_cs.dist /opt/app/

WORKDIR /opt/app

RUN make dep-install-ci-guest && \
chmod -R 777 /opt/app/var && \
make dep-clearcache-guest
32 changes: 32 additions & 0 deletions build/container/ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'

services:
app:
image: hgraca/explicit-architecture:app.sfn.ci
container_name: app.sfn.ci
working_dir: /opt/app
build:
context: ../../../
dockerfile: ./build/container/ci/app.dockerfile
tty: true # `stty` is required to test CLI commands
environment:
# These env variables are here just so we can run this container locally
# They are different in the CI and in ACC, setup through the CI and PaaS web interfaces
ENV: 'ci'
###> symfony/framework-bundle ###
APP_ENV: 'test'
APP_DEBUG: 0
APP_SECRET: '67d829bf61dc5f87a73fd814e2c9f629'
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_URL: 'sqlite:///%kernel.project_dir%/var/data/blog.sqlite'
###< doctrine/doctrine-bundle ###
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL: 'null://localhost'
###< symfony/swiftmailer-bundle ###

0 comments on commit b0c561e

Please sign in to comment.