Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Put env variables defaults here
# Override locally in gitignored .env.local
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
/examples/ export-ignore
/stubs/ export-ignore
/tests/ export-ignore
/tools/ export-ignore
/.env export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/compose.yaml export-ignore
/composer.lock export-ignore
/infection.json5.dist export-ignore
/Makefile export-ignore
/phpstan.dist.neon export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml.dist export-ignore
/rector.php export-ignore
40 changes: 36 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
on:
workflow_dispatch: ~
push:
branches: ['main', '*.*.x']
branches: [main, '*.*.x']
pull_request: ~

jobs:
check:
uses: thesis-php/.github/.github/workflows/check.yml@main
secrets: inherit
code-style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: make fixer-check rector-check

composer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: make composer-validate composer-normalize-check deps-analyze

phpstan:
runs-on: ubuntu-latest
strategy: &strategy
fail-fast: false
matrix:
php: [ 8.3, 8.4, 8.5 ]
deps: [ lowest, highest ]
steps:
- uses: actions/checkout@v6
- run: PHP_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} phpstan

test:
runs-on: ubuntu-latest
strategy: *strategy
steps:
- uses: actions/checkout@v6
- run: PHP_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} test

# infect:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v6
# - run: make infect
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/tools/**/vendor/
/var/
/vendor/
/.env.local
/.php-cs-fixer.php
/compose.override.yaml
/phpstan.neon
/phpunit.xml
/psalm.xml
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
->setParallelConfig(ParallelConfigFactory::detect())
->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache');

(new PhpCsFixerCodingStandard())->applyTo($config);
(new PhpCsFixerCodingStandard())->applyTo($config, [
// 'rule' => ['overridden' => 'config'],
]);

return $config;
124 changes: 124 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
include .env
-include .env.local

SHELL ?= /bin/bash
DOCKER ?= docker
DOCKER_COMPOSE ?= $(DOCKER) compose
export CONTAINER_USER ?= $(shell id -u):$(shell id -g)
INSIDE_CONTAINER ?= $(shell test -f /.dockerenv && echo 1)

RUN ?= $(if $(INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm php)
COMPOSER ?= $(RUN) composer

##
## Project
## -----

var:
mkdir var

vendor: composer.json
if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi

i: install-highest
install-highest: ## Install Composer dependencies
$(COMPOSER) update
@rm -f vendor/.lowest
.PHONY: i install-highest

install-lowest: ## Install Composer dependencies
$(COMPOSER) update --prefer-lowest --prefer-stable
@touch vendor/.lowest
.PHONY: install-lowest

run: ## Run a command inside the Docker container, e.g. `make run CMD=pwd`
$(RUN) $(CMD)
.PHONY: run

t: terminal
terminal: var ## Start a terminal inside the Docker container
@$(if $(INSIDE_CONTAINER),echo 'Already inside docker container.'; exit 1,)
$(DOCKER_COMPOSE) run --rm php bash
.PHONY: t terminal

##
## Tools
## -----

fixer: var ## Fix code style using PHP-CS-Fixer
$(RUN) php-cs-fixer fix --diff --verbose $(ARGS)
.PHONY: fixer

fixer-check: var ## Check code style using PHP-CS-Fixer
$(RUN) php-cs-fixer fix --diff --verbose --dry-run $(ARGS)
.PHONY: fixer-check

rector: var ## Fix code style using Rector
$(RUN) rector process $(ARGS)
.PHONY: rector

rector-check: var ## Check code style using Rector
$(RUN) rector process --dry-run $(ARGS)
.PHONY: rector-check

phpstan: var vendor ## Analyze code using PHPStan
$(RUN) phpstan analyze $(ARGS)
.PHONY: phpstan

test: var vendor ## Run tests using PHPUnit
$(RUN) vendor/bin/phpunit $(ARGS)
.PHONY: test

infect: var vendor ## Run mutation tests using Infection
$(RUN) infection --show-mutations $(ARGS)
.PHONY: infect

deps-analyze: vendor ## Analyze project dependencies using Composer dependency analyser
$(RUN) composer-dependency-analyser $(ARGS)
.PHONY: deps-analyze

composer-validate: ## Validate composer.json
$(COMPOSER) validate $(ARGS)
.PHONY: composer-validate

composer-normalize: ## Normalize composer.json
$(COMPOSER) normalize --diff $(ARGS)
.PHONY: composer-normalize

composer-normalize-check: ## Check that composer.json is normalized
$(COMPOSER) normalize --diff --dry-run $(ARGS)
.PHONY: composer-normalize-check

fix: fixer rector composer-normalize ## Run all fixing recipes
.PHONY: fix

check: fixer-check rector-check composer-validate composer-normalize-check phpstan test deps-analyze ## Run all project checks
.PHONY: check

# -----------------------

help:
@awk ' \
BEGIN {RS=""; FS="\n"} \
function printCommand(line) { \
split(line, command, ":.*?## "); \
printf "\033[32m%-28s\033[0m %s\n", command[1], command[2]; \
} \
/^[0-9a-zA-Z_-]+: [0-9a-zA-Z_-]+\n[0-9a-zA-Z_-]+: .*?##.*$$/ { \
split($$1, alias, ": "); \
sub(alias[2] ":", alias[2] " (" alias[1] "):", $$2); \
printCommand($$2); \
next; \
} \
$$1 ~ /^[0-9a-zA-Z_-]+: .*?##/ { \
printCommand($$1); \
next; \
} \
/^##(\n##.*)+$$/ { \
gsub("## ?", "\033[33m", $$0); \
print $$0; \
next; \
} \
' $(MAKEFILE_LIST) && printf "\033[0m"
.PHONY: help
.DEFAULT_GOAL := help
10 changes: 10 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
php:
image: ghcr.io/thesis-php/php:${PHP_VERSION:-8.3}
user: ${CONTAINER_USER:-}
environment:
HISTFILE: /app/var/.docker_history
COMPOSER_CACHE_DIR: /app/var/.composer_cache
tty: true
volumes:
- .:/app:cached
35 changes: 7 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"license": "MIT",
"type": "library",
"authors": [
{
"name": "kafkiansky",
"email": "vadimzanfir@gmail.com"
},
{
"name": "Valentin Udaltsov",
"email": "udaltsov.valentin@gmail.com"
Expand All @@ -17,9 +21,8 @@
"php": "^8.3"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^12.1.4",
"symfony/var-dumper": "^6.4.15 || ^7.2.6"
"phpunit/phpunit": "^12.4.4",
"symfony/var-dumper": "^7.3.5"
},
"autoload": {
"psr-4": {
Expand All @@ -32,31 +35,7 @@
}
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"bump-after-update": "dev",
"platform": {
"php": "8.3.17"
},
"lock": false,
"sort-packages": true
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"forward-command": true,
"target-directory": "tools"
}
},
"scripts": {
"analyse-deps": "tools/composer-dependency-analyser/vendor/bin/composer-dependency-analyser",
"fixcs": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff --verbose",
"infection": "tools/infection/vendor/bin/infection --show-mutations",
"normalize": "@composer bin composer-normalize normalize --diff ../../composer.json",
"phpstan": "tools/phpstan/vendor/bin/phpstan analyze",
"pre-command-run": "mkdir -p var",
"psalm": "tools/psalm/vendor/bin/psalm --show-info --no-diff --no-cache",
"rector": "tools/rector/vendor/bin/rector process",
"test": "phpunit"
}
}
Loading