From 7ddf05c47e557826d7acccc8ac5e134528b2345f Mon Sep 17 00:00:00 2001 From: Ivan Kartolo Date: Tue, 19 Dec 2023 21:46:42 +0100 Subject: [PATCH] Task #424: add github actions to lint the code and release to TER --- .editorconfig | 6 +- .github/workflows/ci.yml | 76 +++++++++++++++++++++ .github/workflows/publish-ter.yml | 20 ++++++ .gitignore | 4 +- .php-cs-fixer.php | 5 ++ .phpcs.xml | 18 +++++ Build/bin/console | 14 ++++ composer.json | 105 ++++++++++++++++++++++++++---- phpstan.neon | 24 +++++++ 9 files changed, 253 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish-ter.yml create mode 100644 .php-cs-fixer.php create mode 100644 .phpcs.xml create mode 100644 Build/bin/console create mode 100644 phpstan.neon diff --git a/.editorconfig b/.editorconfig index 410d80ba1..c7d860603 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,7 +18,7 @@ indent_size = 2 # JSON-Files [*.json] -indent_style = tab +indent_size = 2 # ReST-Files [*.rst] @@ -34,10 +34,6 @@ indent_size = 2 indent_size = 2 indent_style = tab -# package.json -[package.json] -indent_size = 2 - # TypoScript [*.{typoscript,tsconfig}] indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..39ddd9f29 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,76 @@ +--- +# This GitHub Actions workflow uses the same development tools that are also installed locally +# via Composer or PHIVE and calls them using the Composer scripts. +name: CI with Composer scripts +on: + push: + branches: + - main + pull_request: + schedule: + - cron: '15 3 * * 1' +permissions: + contents: read +jobs: + php-lint: + name: "PHP linter" + runs-on: ubuntu-22.04 + steps: + - name: "Checkout" + uses: actions/checkout@v4 + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + coverage: none + tools: composer:v2 + - name: "Show the Composer configuration" + run: "composer config --global --list" + - name: "Run PHP lint" + run: "composer ci:php:lint" + strategy: + fail-fast: false + matrix: + php-version: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + code-quality: + name: "Code quality checks" + runs-on: ubuntu-22.04 + steps: + - name: "Checkout" + uses: actions/checkout@v4 + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + coverage: none + tools: composer:v2 + - name: "Show Composer version" + run: "composer --version" + - name: "Show the Composer configuration" + run: "composer config --global --list" + - name: "Cache dependencies installed with composer" + uses: actions/cache@v3 + with: + key: "php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}" + path: ~/.cache/composer + restore-keys: "php${{ matrix.php-version }}-composer-\n" + - name: "Install Composer dependencies" + run: "composer install --no-progress" + - name: "Run command" + run: "composer ci:${{ matrix.command }}" + strategy: + fail-fast: false + matrix: + command: + - "composer:normalize" + - "composer:psr-verify" + - "php:sniff" + - "php:stan" + - "xliff:lint" + php-version: + - "8.1" diff --git a/.github/workflows/publish-ter.yml b/.github/workflows/publish-ter.yml new file mode 100644 index 000000000..f3bc292a7 --- /dev/null +++ b/.github/workflows/publish-ter.yml @@ -0,0 +1,20 @@ +name: Publish + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' +permissions: + contents: read +jobs: + publish: + permissions: + actions: write + runs-on: ubuntu-22.04 + steps: + - name: "Checkout" + uses: actions/checkout@v4 + - name: "Publish new version to TER" + uses: tomasnorre/typo3-upload-ter@v2 + with: + api-token: ${{ secrets.TYPO3_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 650e760e1..11748ff67 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ # # Ignore by common IDEs used directories/files *.idea -.idea \ No newline at end of file +.idea +/composer.lock +/.Build diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 000000000..b39c04b63 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,5 @@ +getFinder()->in('Classes')->in('Configuration')->in('Tests'); +return $config; diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 000000000..d2bfcd3ef --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,18 @@ + + + + + + + + + + .git/ + + vendor/ + .Build/ + + + + + diff --git a/Build/bin/console b/Build/bin/console new file mode 100644 index 000000000..08b74be0c --- /dev/null +++ b/Build/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env php +add(new XliffLintCommand(null, null, null, false)); +$application->add(new LintCommand()); + +exit($application->run()); diff --git a/composer.json b/composer.json index c8ef80fd2..348f1f42d 100644 --- a/composer.json +++ b/composer.json @@ -1,35 +1,52 @@ { "name": "directmailteam/direct-mail", - "type": "typo3-cms-extension", "description": "Advanced Direct Mail/Newsletter mailer system with sophisticated options for personalization of emails including response statistics.", + "license": [ + "GPL-2.0-or-later" + ], + "type": "typo3-cms-extension", "keywords": [ "TYPO3", "extension", "directmail", "newsletter" ], - "homepage": "https://github.com/kartolo/direct_mail", "authors": [ { "name": "Ivan Kartolo", "role": "Developer" } ], - "license": [ - "GPL-2.0-or-later" - ], + "homepage": "https://github.com/kartolo/direct_mail", "support": { "issues": "https://github.com/kartolo/direct_mail/issues" }, "require": { - "typo3/cms-core": "^11.5", - "typo3/cms-dashboard": "^11.5", - "php": "^7.4 || ^8.0 || ^8.1", + "php": "^7.4 || ^8.0", "friendsoftypo3/tt-address": "^6.0 || ^7.0 || ^8.0", - "tedivm/fetch": "0.7.*" + "tedivm/fetch": "~0.7.0", + "typo3/cms-core": "^11.5", + "typo3/cms-dashboard": "^11.5" }, "require-dev": { - "roave/security-advisories": "dev-master" + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "ergebnis/composer-normalize": "^2.28.3", + "friendsofphp/php-cs-fixer": "^3.41.1", + "phpcompatibility/php-compatibility": "^9.3", + "phpstan/extension-installer": "^1.3.1", + "phpstan/phpstan": "^1.2.0", + "roave/security-advisories": "dev-master", + "saschaegerer/phpstan-typo3": "^1.0.0", + "seld/jsonlint": "^1.10.1", + "squizlabs/php_codesniffer": "^3.8.0", + "symfony/console": "^5.4 || ^6.4", + "symfony/translation": "^5.4 || ^6.4", + "symfony/yaml": "^5.3.6 || ^6.2.0", + "tomasvotruba/type-coverage": "^0.2.1", + "typo3/coding-standards": "^0.6.1" + }, + "replace": { + "typo3-ter/direct-mail": "self.version" }, "minimum-stability": "dev", "autoload": { @@ -37,12 +54,74 @@ "DirectMailTeam\\DirectMail\\": "Classes" } }, - "replace": { - "typo3-ter/direct-mail": "self.version" + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "ergebnis/composer-normalize": true, + "phpstan/extension-installer": true, + "sbuerk/typo3-cmscomposerinstallers-testingframework-bridge": true, + "typo3/class-alias-loader": true, + "typo3/cms-composer-installers": true + }, + "bin-dir": ".Build/bin", + "preferred-install": { + "*": "dist" + }, + "sort-packages": true, + "vendor-dir": ".Build/vendor" }, "extra": { "typo3/cms": { - "extension-key": "direct_mail" + "extension-key": "direct_mail", + "web-dir": ".Build/Web" } + }, + "scripts": { + "ci:composer:normalize": "@composer normalize --no-check-lock --dry-run", + "ci:composer:psr-verify": "@composer dumpautoload --optimize --strict-psr --no-plugins", + "ci:php": [ + "@ci:php:cs-fixer", + "@ci:php:lint", + "@ci:php:sniff", + "@ci:php:stan" + ], + "ci:php:cs-fixer": "php-cs-fixer fix --config .php-cs-fixer.php -v --dry-run --diff", + "ci:php:lint": "find .*.php *.php Classes Configuration Tests -name '*.php' -print0 | xargs -r -0 -n 1 -P 4 php -l", + "ci:php:sniff": "phpcs --standard=.phpcs.xml -n -p -s --extensions=php .", + "ci:php:stan": "phpstan --no-progress", + "ci:xliff:lint": "php Build/bin/console lint:xliff Resources/Private/Language", + "ci:yaml:lint": "find . ! -path '*.Build/*' ! -path '*node_modules/*' -regextype egrep -regex '.*.ya?ml$' | xargs -r php ./.Build/bin/yaml-lint", + "fix:composer:normalize": "@composer normalize --no-check-lock", + "fix:php": [ + "@fix:php:cs", + "@fix:php:sniff" + ], + "fix:php:cs": "php-cs-fixer fix --config .phpcs-fixer.php", + "fix:php:sniff": "phpcbf --standard=.phpcs.xml -n -p -s --extensions=php .", + "prepare-release": [ + "rm -rf .github", + "rm -rf Build", + "rm .gitignore", + "rm .editorconfig", + "rm .php-cs-fixer.php", + "rm .phpcs.xml", + "rm phpstan.neon" + ] + }, + "scripts-descriptions": { + "ci:composer:normalize": "Checks the composer.json.", + "ci:composer:psr-verify": "Verifies PSR-4 namespace correctness.", + "ci:php": "Runs all static checks for the PHP files.", + "ci:php:cs-fixer": "Checks the code style with the PHP Coding Standards Fixer (PHP-CS-Fixer).", + "ci:php:lint": "Lints the PHP files for syntax errors.", + "ci:php:sniff": "Checks the code style with PHP_CodeSniffer (PHPCS).", + "ci:php:stan": "Checks the PHP types using PHPStan.", + "ci:xliff:lint": "Lints the XLIFF files.", + "ci:yaml:lint": "Lints the YAML files.", + "fix:composer:normalize": "Normalizes composer.json file content.", + "fix:php": "Runs all fixers for the PHP code.", + "fix:php:cs": "Fixes the code style with PHP-CS-Fixer.", + "fix:php:sniff": "Fixes the code style with PHP_CodeSniffer.", + "prepare-release": "Removes development-only files in preparation of a TER release." } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..c7240982c --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,24 @@ +parameters: + parallel: + # Don't be overly greedy on machines with more CPU's to be a good neighbor especially on CI + maximumNumberOfProcesses: 5 + + level: 3 + + bootstrapFiles: + - .Build/vendor/autoload.php + + paths: + - Classes + - Configuration + - Tests + + scanDirectories: + - Classes + - Configuration + - Tests + + type_coverage: + return_type: 100 + param_type: 100 + property_type: 95