From 8e60acc9139bdfd43d544b98b19a5151d44b7dfc Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Thu, 30 May 2024 08:23:47 +0200 Subject: [PATCH] [TASK] Add automatic test runs and documentation --- .github/workflows/tests.yml | 54 ++++++++++++++++++++++++++++++++ .gitignore | 1 + Build/Scripts/runTests.sh | 17 +++++----- Build/cgl/.php-cs-fixer.dist.php | 3 ++ CONTRIBUTING.md | 26 +++++++++++++++ Makefile | 19 ++++++++--- 6 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4ad8159 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,54 @@ +name: tests + +on: + push: + pull_request: + schedule: + # @todo Refactor workflow execution and introduce a generic workflow dispatching + # scheduled workflow, so nighlies can be ensured over branches (for the future). + - cron: "15 6 * * *" + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + strategy: + matrix: + php: + - '7.4' + - '8.0' + - '8.1' + - '8.2' + - '8.3' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint PHP + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s lint + + code-quality: + name: Code quality + runs-on: ubuntu-latest + strategy: + matrix: + php: + - '7.4' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install testing system + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s composerUpdate + + - name: Composer validate + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s composerValidate + + - name: Composer normalize + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s composerNormalize -n + + - name: CGL + run: Build/Scripts/runTests.sh -n -p ${{ matrix.php }} -s cgl + + - name: phpstan + run: Build/Scripts/runTests.sh -n -p ${{ matrix.php }} -s phpstan \ No newline at end of file diff --git a/.gitignore b/.gitignore index fce285b..fe14d21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /Documentation-GENERATED-temp/ /.Build/ /composer.lock +/composer.json.testing diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index c807b41..2ba1d6f 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -202,9 +202,12 @@ Options: - 15 maintained until 2027-11-11 - 16 maintained until 2028-11-09 - -p <8.2|8.3> + -p <7.4|8.0|8.1|8.2|8.3> Specifies the PHP minor version to be used - - 8.2: (default) use PHP 8.2 + - 7.4: (default) use PHP 7.4 + - 8.0: use PHP 8.0 + - 8.1: use PHP 8.1 + - 8.2: use PHP 8.2 - 8.3: use PHP 8.3 -x @@ -253,7 +256,7 @@ TEST_SUITE="cgl" DATABASE_DRIVER="" DBMS="sqlite" DBMS_VERSION="" -PHP_VERSION="8.2" +PHP_VERSION="7.4" PHP_XDEBUG_ON=0 PHP_XDEBUG_PORT=9003 CGLCHECK_DRY_RUN=0 @@ -290,7 +293,7 @@ while getopts "a:b:d:i:s:p:xy:nhu" OPT; do ;; p) PHP_VERSION=${OPTARG} - if ! [[ ${PHP_VERSION} =~ ^(8.2|8.3)$ ]]; then + if ! [[ ${PHP_VERSION} =~ ^(7.4|8.0|8.1|8.2|8.3)$ ]]; then INVALID_OPTIONS+=("p ${OPTARG}") fi ;; @@ -410,9 +413,9 @@ fi case ${TEST_SUITE} in cgl) if [ "${CGLCHECK_DRY_RUN}" -eq 1 ]; then - COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v --dry-run --diff --config=Build/cgl/.php-cs-fixer.dist.php --using-cache=no ." + COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v --dry-run --diff --config=Build/cgl/.php-cs-fixer.dist.php --using-cache=no" else - COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v --config=Build/cgl/.php-cs-fixer.dist.php --using-cache=no ." + COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v --config=Build/cgl/.php-cs-fixer.dist.php --using-cache=no" fi ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name cgl-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}" SUITE_EXIT_CODE=$? @@ -507,7 +510,7 @@ case ${TEST_SUITE} in esac ;; lint) - COMMAND="find . -name \\*.php ! -path "./.Build/\\*" -print0 | xargs -0 -n1 -P4 php -dxdebug.mode=off -l >/dev/null" + COMMAND="find . \( -path './.Build' -o -path './Build/rector' \) -prune -o -name \\*.php -print0 | xargs -0 -n1 -P4 php -dxdebug.mode=off -l >/dev/null" ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}" SUITE_EXIT_CODE=$? ;; diff --git a/Build/cgl/.php-cs-fixer.dist.php b/Build/cgl/.php-cs-fixer.dist.php index 8ae7d77..470c48f 100644 --- a/Build/cgl/.php-cs-fixer.dist.php +++ b/Build/cgl/.php-cs-fixer.dist.php @@ -5,8 +5,11 @@ use TYPO3\CodingStandards\CsFixerConfig; $config = CsFixerConfig::create(); +$config->getFinder()->in(__DIR__ . '/../../Build'); $config->getFinder()->in(__DIR__ . '/../../Classes'); $config->getFinder()->in(__DIR__ . '/../../Configuration'); +$config->getFinder()->in(__DIR__ . '/../../Tests'); $config->getFinder()->exclude('node_modules'); +$config->getFinder()->exclude('rector'); $config->setCacheFile(__DIR__ . '/../../.Build/.cache/.php_cs.cache'); return $config; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 011dc35..26a8911 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,32 @@ You can render the documentation locally by calling: The result is displayed in folder Documentation-GENERATED-temp +## Run tests and apply coding guidelines + +Install the requirements: + +``` + make install +``` + +Apply automatic coding guideline fixes: + +``` + make fix-cgl +``` + +Run tests: + +``` + make test +``` + +If you have not `make` installed or which for finer control, you can run the tests directly: + +``` + Build/Scripts/runTests.sh -s h +``` + # General TYPO3 Support If you have some general TYPO3 support questions or need help with TYPO3, please see https://typo3.org/help. diff --git a/Makefile b/Makefile index 94a37d8..ded0fa6 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,19 @@ test-docs: ## Test the documentation rendering docker run --rm --pull always -v "$(shell pwd)":/project -t ghcr.io/typo3-documentation/render-guides:latest --config=Documentation --no-progress --fail-on-log -.PHONY: rector -rector: ## Run rector - Build/Scripts/runTests.sh -s rector +.PHONY: install +install: ## Run rector + Build/Scripts/runTests.sh -s composerUpdate -.PHONY: fix-cs -fix-cs: ## Fix PHP coding styles +.PHONY: fix-cgl +fix-cgl: ## Fix PHP coding styles + Build/Scripts/runTests.sh -s cgl + +.PHONY: fix +fix: fix-cgl## Run all fixes + +.PHONY: test-cgl +test-cgl: ## Fix PHP coding styles Build/Scripts/runTests.sh -s cgl .PHONY: phpstan @@ -31,3 +38,5 @@ phpstan: ## Run phpstan tests phpstan-baseline: ## Update the phpstan baseline Build/Scripts/runTests.sh -s phpstanBaseline +.PHONY: test +test: test-cgl phpstan test-docs## Run all tests