Skip to content

Commit

Permalink
Contribution guideline (draft) and multiple PHP containers (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista authored Apr 22, 2023
1 parent 68b9776 commit e065cf9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build/

.php_cs.dist
.php-cs-fixer.dist.php
.idea
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Contributing to PHP Codec


## Dev environment

PHP Codec comes with a containerized environment in order to make
contribution really easy.
The container comes with `composer` and `xdebug` installed.

Run

```shell
make run
```

and you're in. By default, `run` will build and start the container with the
lowest PHP version supported.
To start a container with a different version, choose one of the other targets.

```shell
make run-php7.4 # *default
make run-php8.0
make run-php8.1
make run-php8.2
```

Each `run-php*` target will remove the `composer.lock` file and execute a
clean `composer install`.

To execute all the testing targets, run the following from the inside
of the container:

```shell
make ci
```

It will run PHPUnit tests, PHPStan, Psalm and the code style checker.
Consult `Makefile` to learn which are the other targets that allow to run
those checks singularly.


## How to contribute

Open an issue before each non-trivial PR.
Describe what are your needs and your proposal, if any.
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
usage:
@echo "select target"

setup:
docker-compose run php composer install --no-interaction

sh:
docker-compose up -d
docker-compose exec php bash

.PHONY: run run-php7.4 run-php8.0 run-php8.1 run-php8.2
run-php7.4:
docker-compose run --rm php74 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run-php8.0:
docker-compose run --rm php80 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run-php8.1:
docker-compose run --rm php81 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run-php8.2:
docker-compose run --rm php82 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run: run-php7.4

.PHONY: psalm psalm-src psalm-tests psalm-update-baseline

psalm-src:
./vendor/bin/psalm src --no-cache

Expand All @@ -26,7 +28,6 @@ psalm-update-baseline:


.PHONY: phpstan phpstan-update-baseline

phpstan:
./vendor/bin/phpstan analyse src tests

Expand All @@ -35,14 +36,13 @@ phpstan-update-baseline:


.PHONY: type-assertions test

type-assertions:
./vendor/bin/psalm tests/type-assertions --no-cache

test:
./vendor/bin/phpunit

.PHONY: ci cs-check cs-fix
.PHONY: ci ci-check cs-check cs-fix
cs-fix:
./vendor/bin/php-cs-fixer fix --ansi --verbose

Expand Down
14 changes: 0 additions & 14 deletions docker-compose.override.yml.dist

This file was deleted.

23 changes: 22 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
version: "3.8"

services:
php:
php74: &base
build:
context: docker/
args:
PHP_IMAGE: php:7.4
XDEBUG: xdebug-3.1.5
volumes:
- .:/home/dev/lib
tty: true
user: dev
working_dir: /home/dev/lib
php80:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.0
php81:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.1
php82:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.2
20 changes: 9 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
FROM php:7.4
ARG PHP_IMAGE
FROM $PHP_IMAGE

COPY --from=composer /usr/bin/composer /usr/bin/composer

RUN apt-get update \
&& apt-get -y install \
git \
zip \
&& apt-get -y install libxml2-dev \
&& docker-php-ext-install \
xml \
dom \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN apt-get update
RUN apt-get -y install git zip libxml2-dev
RUN docker-php-ext-install xml dom

ARG XDEBUG=xdebug
RUN pecl install ${XDEBUG}
RUN docker-php-ext-enable xdebug

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

Expand Down

0 comments on commit e065cf9

Please sign in to comment.