Skip to content

Commit

Permalink
Prepare release (#426)
Browse files Browse the repository at this point in the history
* Updated JS dependencies and TailwindCSS

* Rebuilt assets

* Add intl (extension) requirement

* Code style

* Removed PurgeCSS and purgecss-webpack-plugin + rebuilt assets

* New Docker testing setup
  • Loading branch information
DamienHarper authored Sep 8, 2024
1 parent 36b281d commit de1df95
Show file tree
Hide file tree
Showing 10 changed files with 2,225 additions and 2,342 deletions.
111 changes: 111 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Default values
php ?= 8.3
sf ?= 7.1
args ?=

# Allowed PHP and Symfony version combinations
# (PHP_VERSION;SYMFONY_VERSION)
valid_combinations = \
8.3;7.1 \
8.3;6.4 \
8.3;5.4 \
8.2;7.1 \
8.2;6.4 \
8.2;5.4

current_combination = $(php);$(sf)

# list of config files to provide to docker compose
compose_files = -f tools/docker/compose.yaml

# Help target
.PHONY: help
help:
@echo "Usage: make <target> [php=<php_version>] [sf=<symfony_version>] [args=<phpunit_args>]"
@echo ""
@echo "Targets:"
@echo " tests - Run the test suite using PHPUnit."
@echo " cs-fix - Run PHP-CS-Fixer to fix coding standards issues."
@echo " phpstan - Run PHPStan for static code analysis."
@echo ""
@echo "Options:"
@echo " php - PHP version to use (default: $(php)). Supported: 8.2, 8.3"
@echo " sf - Symfony version to use (default: $(sf)). Supported: 5.4, 6.4, 7.1"
@echo " args - Additional arguments:"
$(eval $(call set_args,tests))
@echo " Defaults for 'tests' target: $(args)"
$(eval $(call set_args,phpstan))
@echo " Defaults for 'phpstan' target: $(args)"
$(eval $(call set_args,cs-fix))
@echo " Defaults for 'cs-fix' target: $(args)"
@echo ""
@echo "Examples:"
@echo " make tests php=8.2 sf=6.4"
@echo " make cs-fix"
@echo " make phpstan"
@echo " make tests args='--filter=TestClassName'"
@echo ""
@echo "Note: Ensure that the PHP and Symfony versions are valid combinations:"
@echo " $(valid_combinations) (PHP_VERSION;SYMFONY_VERSION)"

# Common target setup
define common_setup
@rm -f composer.lock
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer global config --no-plugins allow-plugins.symfony/flex true"
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer global require --no-progress --no-scripts --no-plugins symfony/flex --quiet"
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer install --quiet"
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer reinstall damienharper/auditor --prefer-install=source --quiet"
endef

# Run PHPUnit target
.PHONY: tests
tests: validate_matrix
$(eval $(call set_args,tests))
#$(call common_setup)
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli vendor/bin/phpunit $(args)"

# Run PHPStan target
.PHONY: phpstan
phpstan: validate_matrix
$(eval $(call set_args,phpstan))
$(call common_setup)
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer install --working-dir=tools/phpstan --quiet"
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli tools/phpstan/vendor/bin/phpstan $(args)"

# Run PHP-CS-Fixer target
.PHONY: cs-fix
cs-fix: validate_matrix
$(eval $(call set_args,cs-fix))
$(call common_setup)
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer install --working-dir=tools/php-cs-fixer --quiet"
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli tools/php-cs-fixer/vendor/bin/php-cs-fixer $(args)"

# Validate PHP and Symfony version matrix
validate_matrix:
@if ! echo "$(valid_combinations)" | grep -q "$(current_combination)"; then \
echo "Error: Invalid combination of PHP and Symfony versions: php=$(php), sf=$(sf)"; \
echo "Allowed combinations are:"; \
echo "(PHP_VERSION;SYMFONY_VERSION)"; \
echo "$(valid_combinations)" | tr ' ' '\n'; \
exit 1; \
fi

# Set default args for each target
define set_args
ifeq ($(1),tests)
args := --colors=always --no-coverage
else ifeq ($(1),phpstan)
args := analyse src --memory-limit=1G --ansi
else ifeq ($(1),cs-fix)
args := fix --using-cache=no --verbose --ansi
endif
endef
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"require": {
"php": ">=8.1",
"ext-json": "*",
"ext-intl": "*",
"damienharper/auditor": "dev-master",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.13 || ^3.2",
"doctrine/orm": "^2.13|^3.2",
"symfony/asset": "^5.4|^6.4|^7.0",
"symfony/doctrine-bridge": "^5.4|^6.4|^7.0",
"symfony/event-dispatcher": "^5.4|^6.4|^7.0",
Expand Down Expand Up @@ -64,7 +65,8 @@
"rector-check": "tools/rector/vendor/bin/rector --dry-run",
"update-tools": "composer update --working-dir=tools/php-cs-fixer ; composer update --working-dir=tools/phpstan ; composer update --working-dir=tools/rector",
"setup54": "SYMFONY_REQUIRE='^5.4' composer update --prefer-stable && rm -rf tests/App/var/cache/*",
"setup64": "SYMFONY_REQUIRE='^6.4' composer update --prefer-stable && rm -rf tests/App/var/cache/*"
"setup64": "SYMFONY_REQUIRE='^6.4' composer update --prefer-stable && rm -rf tests/App/var/cache/*",
"setup71": "SYMFONY_REQUIRE='^7.1' composer update --prefer-stable && rm -rf tests/App/var/cache/*"
},
"config": {
"sort-packages": true,
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"devDependencies": {
"@symfony/webpack-encore": "^1.6.1",
"autoprefixer": "^10.3.6",
"glob-all": "^3.2.1",
"postcss": "^8.4.37",
"postcss-loader": "^6.1.1",
"purgecss": "^4.0.3",
"purgecss-webpack-plugin": "^4.0.3",
"tailwindcss": "^2.2.16"
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@symfony/webpack-encore": "^4.7.0",
"autoprefixer": "^10.4.20",
"babel-loader": "^9.1.3",
"glob-all": "^3.3.1",
"postcss": "^8.4.45",
"postcss-loader": "^8.1.1",
"tailwindcss": "^3.4.10",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<server name="KERNEL_CLASS" value="DH\AuditorBundle\Tests\App\Kernel"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<!-- <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>-->
<!-- <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>-->
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
<testsuites>
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/public/app.css

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
content: [
'./src/Resources/**/*.html.twig',
],
variants: {
extend: {
backgroundColor: ['even'],
Expand Down
17 changes: 17 additions & 0 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli AS auditor

WORKDIR /app

# install PHP extensions
# - pdo_mysql
# - pdo_pgsql
# - xdebug
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN install-php-extensions @composer intl pdo_mysql pdo_pgsql xdebug

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

CMD [ "php" ]
36 changes: 36 additions & 0 deletions tools/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: auditor-bundle-tester
services:
php-cli:
image: auditor:${PHP_VERSION}
build:
context: .
target: auditor
args:
PHP_VERSION: ${PHP_VERSION}
environment:
SYMFONY_REQUIRE: ^${SYMFONY_VERSION}
XDEBUG_MODE: ${XDEBUG_MODE:-coverage}
volumes:
- ../..:/app
- vendor_php${PHP_VERSION}_sf${SYMFONY_VERSION}:/app/vendor
- phpcsfixer_php${PHP_VERSION}:/app/tools/php-cs-fixer/vendor
- phpstan_php${PHP_VERSION}:/app/tools/phpstan/vendor
- rector_php${PHP_VERSION}:/app/tools/rector/vendor
- phpstan_cache:/tmp/phpstan
- composer_root:/root/.composer

volumes:
composer_root:
vendor_php8.3_sf7.1:
vendor_php8.3_sf6.4:
vendor_php8.3_sf5.4:
vendor_php8.2_sf7.1:
vendor_php8.2_sf6.4:
vendor_php8.2_sf5.4:
phpcsfixer_php8.2:
phpcsfixer_php8.3:
phpstan_php8.3:
phpstan_php8.2:
rector_php8.3:
rector_php8.2:
phpstan_cache:
15 changes: 0 additions & 15 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
const Encore = require('@symfony/webpack-encore');
const PurgeCssPlugin = require('purgecss-webpack-plugin');
const glob = require('glob-all');
const path = require('path');

if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

if (Encore.isProduction()) {
Encore.addPlugin(new PurgeCssPlugin({
paths: glob.sync([
path.join(__dirname, 'src/Resources/views/**/**/*.html.twig'),
path.join(__dirname, 'src/Resources/views/**/*.html.twig'),
path.join(__dirname, 'src/Resources/assets/**/*.css'),
path.join(__dirname, 'src/Resources/assets/**/*.js'),
]),
defaultExtractor: (content) => {
return content.match(/[\w-./:]+(?<!:)/g) || [];
}
}));
}

Encore
// directory where compiled assets will be stored
.setOutputPath('src/Resources/public/')
Expand Down
Loading

0 comments on commit de1df95

Please sign in to comment.