From 9ed017ffecd0d448563e99c3bce7d0cc11f42f3f Mon Sep 17 00:00:00 2001 From: Maksym Leonov Date: Sun, 26 Apr 2026 22:59:21 +0300 Subject: [PATCH 1/4] Add Docker dev env and CI workflow --- .dockerignore | 10 +++++ .github/workflows/php.yml | 79 +++++++++++++++++++-------------------- Makefile | 45 ++++++++++++++++++++++ compose.yaml | 42 +++++++++++++++++++++ docker/Dockerfile | 17 +++++++++ 5 files changed, 153 insertions(+), 40 deletions(-) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 compose.yaml create mode 100644 docker/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bf6bc12 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git/ +.github/ +.idea/ +.vscode/ +build/ +vendor/ +*.md +.env +.env.* +.phpunit.result.cache diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0798957..9e918e4 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,53 +1,52 @@ -name: Pipeline +name: CI on: [push, pull_request] +permissions: + contents: read + jobs: - run: + test: + name: PHP ${{ matrix.php }} runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - php-versions: ['7.3', '7.4', '8.0'] - name: PHP ${{ matrix.php-versions }} + php: ['8.2', '8.3', '8.4'] steps: - - name: Checkout - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring - coverage: pcov + - name: Build image + run: make PHP=${{ matrix.php }} build-svc + + - name: Composer install + run: make PHP=${{ matrix.php }} install + + - name: Lint + run: make PHP=${{ matrix.php }} lint + + - name: Tests + run: make PHP=${{ matrix.php }} test + + coverage: + name: Coverage + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: make PHP=8.4 build-svc - - name: Validate composer.json - run: composer validate + - name: Composer install + run: make PHP=8.4 install - - name: Get Composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Run tests with coverage + run: make PHP=8.4 test-coverage - - name: Cache dependencies - uses: actions/cache@v1 + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --no-progress -o - - - name: Check syntax - run: | - php -l src/ - vendor/bin/phpcs --standard=psr2 --ignore=Tests src/ - - - name: Run tests - run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml - - - name: Upload coverage results to Coveralls - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=build/logs/clover.xml -v + name: clover-coverage + path: build/logs/clover.xml + if-no-files-found: error diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..147ebaf --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +PHP ?= 8.4 +SERVICE := php$(subst .,,$(PHP)) +COMPOSE := $(shell docker compose version >/dev/null 2>&1 && echo "docker compose" || echo "docker-compose") +DC := $(COMPOSE) run --rm $(SERVICE) + +.PHONY: build build-svc install update test test-coverage lint lint-fix analyse ci ci-full shell matrix clean + +build: + $(COMPOSE) build + +build-svc: + $(COMPOSE) build $(SERVICE) + +install: + $(DC) composer install + +update: + $(DC) composer update + +test: + $(DC) vendor/bin/phpunit + +test-coverage: + $(DC) vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml + +lint: + $(DC) vendor/bin/phpcs --standard=psr2 --ignore=Tests src/ + +lint-fix: + $(DC) vendor/bin/phpcbf --standard=psr2 --ignore=Tests src/ + +analyse: + $(DC) vendor/bin/phpstan analyse --level=8 src/ + +ci: lint test +ci-full: lint analyse test + +shell: + $(DC) bash + +matrix: + @printf '8.2\n8.3\n8.4\n' | xargs -n1 -P3 -I{} $(MAKE) PHP={} install ci + +clean: + $(COMPOSE) down -v diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..2aeac7c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,42 @@ +services: + php82: + build: + context: . + dockerfile: docker/Dockerfile + args: + PHP_VERSION: '8.2' + working_dir: /app + volumes: + - .:/app + - composer-cache:/tmp/composer + - vendor-82:/app/vendor + + php83: + build: + context: . + dockerfile: docker/Dockerfile + args: + PHP_VERSION: '8.3' + working_dir: /app + volumes: + - .:/app + - composer-cache:/tmp/composer + - vendor-83:/app/vendor + + php84: + build: + context: . + dockerfile: docker/Dockerfile + args: + PHP_VERSION: '8.4' + working_dir: /app + volumes: + - .:/app + - composer-cache:/tmp/composer + - vendor-84:/app/vendor + +volumes: + composer-cache: + vendor-82: + vendor-83: + vendor-84: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..17f57af --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,17 @@ +ARG PHP_VERSION=8.4 +FROM php:${PHP_VERSION}-cli + +RUN apt-get update \ + && apt-get install -y --no-install-recommends git unzip \ + && pecl install pcov \ + && docker-php-ext-enable pcov \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + +ENV COMPOSER_HOME=/tmp/composer \ + COMPOSER_ALLOW_SUPERUSER=1 \ + COMPOSER_NO_INTERACTION=1 + +WORKDIR /app From 1480a441636374210b68e8268554fddde80cd0e4 Mon Sep 17 00:00:00 2001 From: Maksym Leonov Date: Sun, 26 Apr 2026 22:59:25 +0300 Subject: [PATCH 2/4] Ignore build/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0ed9c8f..1b0ac08 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /vendor/ /.phpunit.result.cache /composer.lock +/build/ From 4f2a86868a3f9938bdb6deda0bdec6e16c1073f0 Mon Sep 17 00:00:00 2001 From: Maksym Leonov Date: Sun, 26 Apr 2026 23:03:04 +0300 Subject: [PATCH 3/4] Add PHP 8.5 to matrix --- .github/workflows/php.yml | 2 +- Makefile | 2 +- compose.yaml | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9e918e4..e35f49c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.2', '8.3', '8.4'] + php: ['8.2', '8.3', '8.4', '8.5'] steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 147ebaf..8e1ffee 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ shell: $(DC) bash matrix: - @printf '8.2\n8.3\n8.4\n' | xargs -n1 -P3 -I{} $(MAKE) PHP={} install ci + @printf '8.2\n8.3\n8.4\n8.5\n' | xargs -n1 -P4 -I{} $(MAKE) PHP={} install ci clean: $(COMPOSE) down -v diff --git a/compose.yaml b/compose.yaml index 2aeac7c..d35cdc2 100644 --- a/compose.yaml +++ b/compose.yaml @@ -35,8 +35,21 @@ services: - composer-cache:/tmp/composer - vendor-84:/app/vendor + php85: + build: + context: . + dockerfile: docker/Dockerfile + args: + PHP_VERSION: '8.5' + working_dir: /app + volumes: + - .:/app + - composer-cache:/tmp/composer + - vendor-85:/app/vendor + volumes: composer-cache: vendor-82: vendor-83: vendor-84: + vendor-85: From 723046e079a26020bcedeca986701af9608f30f4 Mon Sep 17 00:00:00 2001 From: Maksym Leonov Date: Sun, 26 Apr 2026 23:07:07 +0300 Subject: [PATCH 4/4] update composer.json --- composer.json | 84 +++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index a6f4ea8..3efe558 100644 --- a/composer.json +++ b/composer.json @@ -1,44 +1,44 @@ { - "name": "maxbanton/cwh", - "homepage": "https://github.com/maxbanton/cwh", - "type": "library", - "description": "AWS CloudWatch Handler for Monolog library", - "keywords": [ - "aws", - "cloudwatch", - "monolog" - ], - "license": "MIT", - "authors": [ - { - "name": "Max Leonov", - "email": "hi@maxleonov.pw", - "homepage": "https://maxleonov.pw" - } - ], - "support": { - "issues": "https://github.com/maxbanton/cwh/issues", - "source": "https://github.com/maxbanton/cwh" - }, - "require": { - "php": "^7.2 || ^8", - "monolog/monolog": "^2.0", - "aws/aws-sdk-php": "^3.18" - }, - "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.4", - "squizlabs/php_codesniffer": "^3.5" - }, - "suggest": { - "maxbanton/dd": "Minimalistic dump-and-die function for easy debugging" - }, - "config": { - "preferred-install": "dist" - }, - "autoload": { - "psr-4": { - "Maxbanton\\Cwh\\": "src" - } - }, - "minimum-stability": "stable" + "name": "maxbanton/cwh", + "homepage": "https://github.com/maxbanton/cwh", + "type": "library", + "description": "AWS CloudWatch Handler for Monolog library", + "keywords": [ + "aws", + "cloudwatch", + "monolog" + ], + "license": "MIT", + "authors": [ + { + "name": "Maksym Leonov", + "email": "ruses_entails4f@icloud.com", + "homepage": "https://maxbanton.github.io" + } + ], + "support": { + "issues": "https://github.com/maxbanton/cwh/issues", + "source": "https://github.com/maxbanton/cwh" + }, + "require": { + "php": "^7.2 || ^8", + "monolog/monolog": "^2.0", + "aws/aws-sdk-php": "^3.18" + }, + "require-dev": { + "phpunit/phpunit": "^8.5 || ^9.4", + "squizlabs/php_codesniffer": "^3.5" + }, + "suggest": { + "maxbanton/dd": "Minimalistic dump-and-die function for easy debugging" + }, + "config": { + "preferred-install": "dist" + }, + "autoload": { + "psr-4": { + "Maxbanton\\Cwh\\": "src" + } + }, + "minimum-stability": "stable" }