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
5 changes: 5 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dockerComposeFile": "compose.yaml",
"service": "php",
"workspaceFolder": "/workspace"
}
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Put env variables defaults here
# Override locally in gitignored .env.local
PHP_IMAGE_VERSION=8.3
8 changes: 6 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/.devcontainer/ export-ignore
/.github/ export-ignore
/docker/ export-ignore
/examples/ export-ignore
/stubs/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/composer.lock export-ignore
/infection.json.dist 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
48 changes: 48 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check

on:
workflow_dispatch: ~
push:
branches: [main, '*.*.x']
pull_request: ~

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
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_IMAGE_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} phpstan

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

# infect:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v6
# - run: make infect
11 changes: 0 additions & 11 deletions .github/workflows/check.yml

This file was deleted.

82 changes: 0 additions & 82 deletions .github/workflows/test.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**/vendor/
/var/
/vendor/
/.env.local
/.php-cs-fixer.php
/compose.override.yaml
/phpstan.neon
/phpunit.xml
/psalm.xml
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
$config = (new Config())
->setFinder(
Finder::create()
->in(__DIR__ . '/examples')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->in(__DIR__ . '/examples')
->append([
__FILE__,
]),
Expand Down
191 changes: 169 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,179 @@
UID := $(shell id -u)
GID := $(shell id -g)
SHELL := /bin/bash

build:
docker compose build --build-arg UID=$(UID) --build-arg GID=$(GID)
DOCKER ?= docker
DOCKER_COMPOSE ?= $(DOCKER) compose $(shell test -f .env.local && echo '--env-file .env --env-file .env.local')
export CONTAINER_USER ?= $(shell id -u):$(shell id -g)

up: build
docker compose up -d
RUN ?= $(if $(INSIDE_DEVCONTAINER),,$(DOCKER_COMPOSE) run --rm php)
COMPOSER ?= $(RUN) composer

down:
docker compose down --remove-orphans
##
## Project
## -----

php:
docker compose exec php bash
var:
mkdir var

kv-list:
docker run --rm --network host bitnamilegacy/natscli:latest --server localhost:4222 --user user --password Pswd1 kv ls
vendor: composer.json $(wildcard composer.lock)
@if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi

object-list:
docker run --rm --network host bitnamilegacy/natscli:latest --server localhost:4222 --user user --password Pswd1 object ls
i: install-highest
install-highest: ## Install highest Composer dependencies
$(COMPOSER) install
@rm -f vendor/.lowest
@touch vendor
.PHONY: i install-highest

stream-list:
docker run --rm --network host bitnamilegacy/natscli:latest --server localhost:4222 --user user --password Pswd1 stream ls
install-lowest: ## Install lowest Composer dependencies
$(COMPOSER) update --prefer-lowest --prefer-stable
@touch vendor/.lowest
@touch vendor
.PHONY: install-lowest

nats-help:
docker run --rm --network host bitnamilegacy/natscli:latest --server localhost:4222 --user user --password Pswd1 --help
up: ## Docker compose up
$(DOCKER_COMPOSE) up --remove-orphans --build --detach $(ARGS)
.PHONY: up

nats-latency:
docker run --rm --network host bitnamilegacy/natscli:latest --server localhost:4222 --user user --password Pswd1 latency --server-b localhost:4223 --rate 500000
down: ## Docker compose down
$(DOCKER_COMPOSE) down --remove-orphans $(ARGS)
.PHONY: down

nats-stop:
docker compose down nats-1 nats-2 nats-3
dc: docker-compose
docker-compose: ## Run docker compose command: `make dc CMD=start`
$(DOCKER_COMPOSE) $(CMD)
.PHONY: dc docker-compose

c: composer
composer: ## Run Composer command: `make c CMD=start`
$(COMPOSER) $(CMD)
.PHONY: c composer

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

rescaffold:
$(DOCKER) run \
--volume .:/project \
--user $(CONTAINER_USER) \
--interactive --tty --rm \
--pull always \
ghcr.io/phpyh/scaffolder:latest \
--user-name-default '$(shell git config user.name 2>/dev/null || whoami 2>/dev/null)' \
--user-email-default '$(shell git config user.email 2>/dev/null)' \
--package-project-default '$(shell basename $$(pwd))'
git add --all 2>/dev/null || true
.PHONY: rescaffold

##
## Nats
## -----

nats-help: up
$(DOCKER_COMPOSE) run --rm nats-cli --server nats-1:4222 --user user --password Pswd1 --help
.PHONY: nats-help

nats-kv-list: up
$(DOCKER_COMPOSE) run --rm nats-cli --server nats-1:4222 --user user --password Pswd1 kv ls
.PHONY: nats-kv-list

nats-object-list: up
$(DOCKER_COMPOSE) run --rm nats-cli --server nats-1:4222 --user user --password Pswd1 object ls
.PHONY: nats-object-list

nats-stream-list: up
$(DOCKER_COMPOSE) run --rm nats-cli --server nats-1:4222 --user user --password Pswd1 stream ls
.PHONY: nats-stream-list

nats-latency: up
$(DOCKER_COMPOSE) run --rm nats-cli --server nats-1:4222 --user user --password Pswd1 latency --server-b nats-2:4222 --rate 500000
.PHONY: nats-latency

##
## 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 $(shell [[ $$($(COMPOSER) info cuyz/valinor) == *"versions : * 2"* ]] && echo '--configuration phpstan-highest.neon') $(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 --no-check-lock --no-update-lock --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 deps-analyze phpstan test ## 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
Loading