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
43 changes: 36 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,13 +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
with:
test: false
rector: true
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
35 changes: 0 additions & 35 deletions .github/workflows/test.yml

This file was deleted.

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
136 changes: 136 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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 highest Composer dependencies
$(COMPOSER) update $(ARGS)
@rm -f vendor/.lowest
.PHONY: i install-highest

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

up: ## Docker compose up
$(DOCKER_COMPOSE) up --build --detach $(ARGS)
.PHONY: up

down: ## Docker compose down
$(DOCKER_COMPOSE) down --remove-orphans $(ARGS)
.PHONY: down

compose: ## Run docker compose command: `make compose CMD=start`
$(DOCKER_COMPOSE) $(CMD)
.PHONY: compose

run: ## Run a command using the php container: `make run CMD='php --version'`
$(RUN) $(CMD)
.PHONY: run

t: terminal
terminal: var ## Start a terminal inside the php container
@$(if $(INSIDE_CONTAINER),echo 'Already inside docker container.'; exit 1,)
$(DOCKER_COMPOSE) run --rm $(ARGS) 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 --memory-limit=1G $(ARGS)
.PHONY: phpstan

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

infect: var vendor up ## 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
14 changes: 14 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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

rabbitmq:
image: rabbitmq:4.0-management-alpine
restart: always
48 changes: 7 additions & 41 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Valentin Udaltsov",
"email": "udaltsov.valentin@gmail.com"
},
{
"name": "kafkiansky",
"email": "vadimzanfir@gmail.com"
},
{
"name": "Valentin Udaltsov",
"email": "udaltsov.valentin@gmail.com"
},
{
"name": "Thesis Team",
"homepage": "https://github.com/orgs/thesis-php/people"
Expand All @@ -36,9 +36,8 @@
"thesis/time-span": "^0.2.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^12.2.7",
"symfony/var-dumper": "^6.4.15 || ^7.3.1"
"phpunit/phpunit": "^12.4.4",
"symfony/var-dumper": "^7.3.5"
},
"autoload": {
"psr-4": {
Expand All @@ -54,40 +53,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",
"check": [
"@composer fixcs -- --dry-run",
"@composer rector -- --dry-run",
"@phpstan",
"@composer validate",
"@composer normalize --dry-run",
"@analyse-deps",
"@test"
],
"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