diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3759c1f..a96bb71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,9 +33,12 @@ jobs: - php: 7.4 mongo-ext: 1.9.0 mongo-img: 4.4 - - php: 8.0 - mongo-ext: 1.9.0 - mongo-img: 4.4 + - php: 8.1 + mongo-ext: 1.12.0 + mongo-img: 5.0 + - php: 8.2 + mongo-ext: 1.15.0 + mongo-img: 6.0 steps: - name: Checkout diff --git a/.gitignore b/.gitignore index a1656e0..9dbfafe 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ docker-compose.override.yml .phpunit.result.cache auth.json +build diff --git a/CHANGELOG.md b/CHANGELOG.md index e6d65bc..dee05b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +* CI coverage for PHP 8.1 and 8.2 ### Removed * Removed support for PHP < 7.4 +* Docker images dev-dependency from https://github.com/ilario-pierbattista/docker-php-mongodb-bundle ## [1.5.0] (2022-01-06) ### Added diff --git a/Makefile b/Makefile index 20317a6..5198828 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ -.PHONY: up setup sh test phpstan phpstan-baseline cs-fix cs-check usage - +.PHONY: usage usage: @echo '' @echo 'Facile.it MongoDB Bundle' @@ -23,32 +22,63 @@ usage: @echo 'make phpstan-baseline: update the phpstan baseline' @echo '' +################################################################## +# +# RUN OUTISDE THE CONTAINER +# +################################################################## +DOCKER_COMPOSE ?= $(shell (command -v docker-compose > /dev/null && echo "docker-compose") || (command -v docker > /dev/null && echo "docker compose")) + docker-compose.override.yml: cp docker-compose.override.yml.dist docker-compose.override.yml -docker-compose.yml: docker-compose.override.yml +.PHONY: build-74 build-81 build-82 +build-74: + PHP_VERSION=7.4 MONGODB_EXTENSION_VERSION=1.6.0 $(DOCKER_COMPOSE) build +build-81: + PHP_VERSION=8.1 MONGODB_EXTENSION_VERSION=1.12.0 $(DOCKER_COMPOSE) build +build-82: + PHP_VERSION=8.1 MONGODB_EXTENSION_VERSION=1.15.0 $(DOCKER_COMPOSE) build -setup: docker-compose.yml composer.json - docker-compose run --rm php composer install +.PHONY: --setup-common setup setup-74 setup-81 setup-82 +setup: setup-74 +setup-74: | build-74 --setup-common +setup-81: | build-81 --setup-common +setup-82: | build-82 --setup-common +--setup-common: docker-compose.override.yml + rm composer.lock || true + $(DOCKER_COMPOSE) run --rm php composer install +.PHONY: sh stop sh: docker-compose.yml - docker-compose up -d --force-recreate - docker exec -ti mb_php bash + $(DOCKER_COMPOSE) up -d --force-recreate + $(DOCKER_COMPOSE) exec -ti php bash stop: docker-compose.yml - docker-compose stop + $(DOCKER_COMPOSE) stop + +################################################################## +# +# RUN INSIDE THE CONTAINER +# +################################################################## + +.PHONY: test coverage test: bin/phpunit tests +coverage: + bin/phpunit tests --coverage-clover=build/coverage-report.xml +.PHONY: phpstan phpstan-baseline phpstan: bin/phpstan analyze --memory-limit=-1 phpstan-baseline: bin/phpstan analyze --memory-limit=-1 --generate-baseline +.PHONY: cs-fix cs-check cs-fix: composer cs-fix - cs-check: composer cs-check diff --git a/docker-compose.override.yml.dist b/docker-compose.override.yml.dist index a996dbb..1a95c7a 100644 --- a/docker-compose.override.yml.dist +++ b/docker-compose.override.yml.dist @@ -1,4 +1,4 @@ -version: "3.1" +version: "3.8" services: mongo: diff --git a/docker-compose.yml b/docker-compose.yml index 3873c2b..534ab26 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,13 @@ -version: "3.1" +version: "3.8" services: php: - image: ilariopierbattista/mongodb-bundle-php:php-7.4-mongoext-1.6.0-20231111 + image: mongodb-bundle-php:${PHP_VERSION:-7.4}-${MONGODB_EXTENSION_VERSION:-1.6.0} + build: + context: docker + args: + PHP_VERSION: ${PHP_VERSION:-7.4} + MONGODB_EXTENSION_VERSION: ${MONGODB_EXTENSION_VERSION:-1.6.0} volumes: - ./:/home/user-dev/project tty: true diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..9b7b672 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,44 @@ +ARG PHP_VERSION +FROM php:${PHP_VERSION}-cli + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y \ + libbz2-dev \ + libcurl4-openssl-dev \ + libedit-dev \ + libfontconfig \ + libgmp-dev \ + libicu-dev \ + libmcrypt-dev \ + libssl-dev \ + libtidy-dev \ + libxml2-dev \ + libxslt-dev \ + libzip-dev \ + locales \ + openssl \ + libonig-dev \ + git \ + unzip + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +COPY install-extensions.sh . +RUN ./install-extensions.sh + +ARG MONGODB_EXTENSION_VERSION + +RUN pecl install mongodb-${MONGODB_EXTENSION_VERSION} \ + && docker-php-ext-enable mongodb + +ENV TEST_ENV=docker + +RUN useradd -m user-dev + +USER user-dev + +RUN mkdir -p /home/user-dev/project + +WORKDIR /home/user-dev/project diff --git a/docker/install-extensions.sh b/docker/install-extensions.sh new file mode 100755 index 0000000..2ced973 --- /dev/null +++ b/docker/install-extensions.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +# Is everything necessary? +docker-php-ext-install curl +docker-php-ext-install opcache +docker-php-ext-install intl +docker-php-ext-install tidy +docker-php-ext-install bz2 +docker-php-ext-install xml +docker-php-ext-install mbstring +docker-php-ext-install zip + +if echo "$PHP_VERSION" | grep -Eq '7\.\d*' +then + docker-php-ext-install json +fi + +pecl install pcov && docker-php-ext-enable pcov diff --git a/docs/Contributing.md b/docs/Contributing.md index 2effb6b..5454dad 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -34,8 +34,9 @@ Since we defined our code stile, and configured a quality tool for enforce its u ## Development Environment We like a lot Docker and Make. -We use the former and `docker-compose` to set up and insulated, reproducible development environment. -The latter helps us to define a lot of shortcuts. + +We use`docker-compose` to set up and insulated, reproducible development environment. +Make helps us to define easy-to-use build targets. Run `make usage` or just `make` inside the project folder to get a list of available targets. @@ -68,6 +69,21 @@ another port for the binding. Change the port binding into the `docker-compose.override.yml` file. It is generated from the `docker-compose.override.yml.dist` template, and it's not tracked by git. +### Run a different version of PHP and/or the ext-mongodb + +By default `make setup` will build a docker image with the lower supported version of PHP +and `ext-mongodb`. + +If you need a different environment, you should exec one of the following target **instead** of `make setup`. + + make setup-81 # PHP 8.1, ext-mongodb 1.12 + make setup-82 # PHP 8.2, ext-mongodb 1.15 + +Feel free to add other `setup-*` and `build-*` targets to meet your needs (take a look at the [Makefile](../Makefile) and just follow the same convention). + +Remember to edit the [ci.yaml](../.github/workflows/ci.yaml), if you need to test the bundle against +a specific set of PHP and ext-mongodb versions. + ### Tests and Quality Tools This project uses `phpunit` to run its test suite.