diff --git a/.circleci/config.yml b/.circleci/config.yml index bc29b582..43b5d7ef 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -91,18 +91,23 @@ aliases: - &run-unit-tests-with-coverage run: - name: Run unit tests with coverage - command: docker-compose run composer-coverage + name: Run unit tests with coverage (pcov) + command: docker-compose run coverage-pcov - &run-feature-tests run: name: Run feature tests command: docker-compose run composer feature-tests - - &run-feature-tests-with-coverage + - &run-feature-tests-with-coverage-xdebug run: - name: Run feature tests with coverage - command: docker-compose run feature-coverage + name: Run feature tests with coverage (xdebug) and retry + command: docker-compose run coverage-xdebug-feature-with-retry + + - &run-feature-tests-with-coverage-pcov + run: + name: Run feature tests with coverage (pcov) + command: docker-compose run coverage-pcov feature-code-coverage - &prepare-codeclimate-reporter run: @@ -129,7 +134,7 @@ aliases: - &export-docker-cache run: name: Export Docker image layer cache - command: | + command: |- mkdir -p /home/circleci/caches docker-compose build composer | grep '\-\-\->' | grep -v 'Using cache' | sed -e 's/[ >-]//g' > /tmp/layers.txt docker save $(cat /tmp/layers.txt) | gzip > /home/circleci/caches/${CIRCLE_PROJECT_REPONAME}.tar.gz @@ -180,7 +185,8 @@ aliases: - *static-src-analysis - *static-tests-analysis - *run-unit-tests-with-coverage - - *run-feature-tests-with-coverage + - *run-feature-tests-with-coverage-pcov + - *run-feature-tests-with-coverage-xdebug - *merge-code-coverage - *upload-codecov-report - *upload-codeclimate-report diff --git a/Dockerfile b/Dockerfile index d875b04d..49388f1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,12 @@ ARG SWOOLE_VERSION="4.3.1" RUN pecl install swoole-${SWOOLE_VERSION} && \ docker-php-ext-enable swoole +FROM ext-builder as ext-pcov +RUN pecl install pcov && \ + docker-php-ext-enable pcov +RUN echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \ + echo "pcov.directory=/usr/src/app/src" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + FROM composer:latest as app-installer WORKDIR /usr/src/app RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative --ansi @@ -45,11 +51,7 @@ COPY --from=ext-inotify /usr/local/etc/php/conf.d/docker-php-ext-inotify.ini /us COPY --from=ext-pcntl /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcntl.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcntl.so COPY --from=ext-pcntl /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini -FROM base as base-cli -USER app:runner -COPY --chown=app:runner --from=app-installer /usr/src/app ./ - -FROM base as base-coverage +FROM base as base-coverage-xdebug RUN apk add --no-cache bash lsof ARG PHP_API_VERSION="20180731" COPY --from=ext-xdebug /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/xdebug.so @@ -60,20 +62,36 @@ ENV COVERAGE="1" \ COPY --chown=app:runner --from=app-installer /usr/bin/composer /usr/local/bin/composer COPY --chown=app:runner --from=app-installer /usr/src/app ./ -FROM base-cli as Cli +FROM base as base-coverage-pcov +ARG PHP_API_VERSION="20180731" +COPY --from=ext-pcov /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcov.so +COPY --from=ext-pcov /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +USER app:runner +ENV COVERAGE="1" \ + COMPOSER_ALLOW_SUPERUSER="1" +COPY --chown=app:runner --from=app-installer /usr/bin/composer /usr/local/bin/composer +COPY --chown=app:runner --from=app-installer /usr/src/app ./ + +FROM base as Cli +USER app:runner +COPY --chown=app:runner --from=app-installer /usr/src/app ./ ENTRYPOINT ["./tests/Fixtures/Symfony/app/console"] CMD ["swoole:server:run"] -FROM base-cli as Composer -ENV COMPOSER_ALLOW_SUPERUSER=1 +FROM Cli as Composer +ENV COMPOSER_ALLOW_SUPERUSER="1" COPY --chown=app:runner --from=app-installer /usr/bin/composer /usr/local/bin/composer ENTRYPOINT ["composer"] CMD ["test"] -FROM base-coverage as ComposerCoverage +FROM base-coverage-xdebug as CoverageXdebug +ENTRYPOINT ["composer"] +CMD ["unit-code-coverage"] + +FROM base-coverage-pcov as CoveragePcov ENTRYPOINT ["composer"] CMD ["unit-code-coverage"] -FROM base-coverage as FeatureCoverage +FROM base-coverage-xdebug as CoverageXdebugWithRetry ENTRYPOINT ["/bin/bash"] CMD ["tests/run-feature-tests-code-coverage.sh"] diff --git a/Makefile b/Makefile index 211d4fd8..921e00a2 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,19 @@ -.PHONY: clean-coverage -clean-coverage: +.PHONY: clean/coverage +clean/coverage: @rm -rf cov/* @rm -rf clover.xml -.PHONY: clean-test-resources -clean-test-resources: +.PHONY: clean/tests/resources +clean/tests/resources: @rm -rf tests/Fixtures/resources/*.pid -.PHONY: clean-fixtures-cache -clean-fixtures-cache: +.PHONY: clean/fixtures/cache +clean/fixtures/cache: @rm -rf tests/Fixtures/Symfony/app/var/cache/* -.PHONY: clean-fixtures-logs -clean-fixtures-logs: +.PHONY: clean/fixtures/logs +clean/fixtures/logs: @rm -rf tests/Fixtures/Symfony/app/var/log/* .PHONY: clean -clean: clean-coverage clean-fixtures-cache clean-fixtures-logs clean-test-resources - +clean: clean/coverage clean/fixtures/cache clean/fixtures/logs clean/tests/resources diff --git a/docker-compose.yml b/docker-compose.yml index d02c389c..58d8daa7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,11 +24,11 @@ services: COMPOSER_ARGS: "${COMPOSER_ARGS:-install}" SWOOLE_VERSION: "${SWOOLE_VERSION:-4.3.1}" - composer-coverage: - image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-coverage}:${TAG:-latest}" + coverage-xdebug: + image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-xdebug}:${TAG:-latest}" build: context: . - target: ComposerCoverage + target: CoverageXdebug args: PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}" PHP_API_VERSION: "${PHP_API_VERSION:-20180731}" @@ -37,11 +37,28 @@ services: volumes: - "./cov:/usr/src/app/cov" - feature-coverage: - image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-feature-coverage}:${TAG:-latest}" + coverage-pcov: + image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-pcov}:${TAG:-latest}" build: context: . - target: FeatureCoverage + target: CoveragePcov + args: + PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}" + PHP_API_VERSION: "${PHP_API_VERSION:-20180731}" + COMPOSER_ARGS: "${COMPOSER_ARGS:-install}" + SWOOLE_VERSION: "${SWOOLE_VERSION:-4.3.1}" + volumes: + - "./cov:/usr/src/app/cov" + + coverage-xdebug-feature-with-retry: + image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-xdebug}:${TAG:-latest}" + entrypoint: + - /bin/bash + command: + - tests/run-feature-tests-code-coverage.sh + build: + context: . + target: CoverageXdebug args: PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}" PHP_API_VERSION: "${PHP_API_VERSION:-20180731}" @@ -51,11 +68,11 @@ services: - "./cov:/usr/src/app/cov" merge-code-coverage: - image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-coverage}:${TAG:-latest}" - command: "merge-code-coverage" + image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-pcov}:${TAG:-latest}" + command: merge-code-coverage build: context: . - target: ComposerCoverage + target: CoveragePcov args: PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}" PHP_API_VERSION: "${PHP_API_VERSION:-20180731}"