diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 4d9dec3c..9c2fdc77 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,7 +1,7 @@ name: reference-tsconfig type: php docroot: "" -php_version: "8.1" +php_version: "8.2" webserver_type: nginx-fpm router_http_port: "8081" router_https_port: "4434" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 00000000..79ac662e --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,17 @@ +name: test documentation + +on: [ push, pull_request ] + +jobs: + tests: + name: documentation + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Test if the documentation will render without warnings + run: | + mkdir -p Documentation-GENERATED-temp \ + && docker run --rm --pull always -v $(pwd):/project \ + ghcr.io/typo3-documentation/render-guides:latest --config=Documentation --no-progress --fail-on-log diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0859ddd6..c7b37058 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,3 @@ jobs: - name: CGL run: Build/Scripts/runTests.sh -n -p ${{ env.php }} -s cgl -n - - - name: Check Rst - run: Build/Scripts/runTests.sh -p ${{ env.php }} -s checkRst diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 93d9a47f..5c161e04 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -42,11 +42,9 @@ No arguments: Run all checks with PHP 8.2 Options: -s <...> Specifies which test suite to run - - checkRst: test .rst files for integrity - cgl: cgl test and fix all php files - composerUpdate: "composer update", handy if host has no PHP - lint: PHP linting - - rector: Apply Rector rules -p <8.2|8.3> Specifies the PHP minor version to be used @@ -165,12 +163,6 @@ DOCKER_PHP_IMAGE=`echo "php${PHP_VERSION}" | sed -e 's/\.//'` # Suite execution case ${TEST_SUITE} in - checkRst) - setUpDockerComposeDotEnv - docker-compose run check_rst - SUITE_EXIT_CODE=$? - docker-compose down - ;; cgl) # Active dry-run for cgl needs not "-n" but specific options if [[ ! -z ${CGLCHECK_DRY_RUN} ]]; then diff --git a/Build/Scripts/validateRstFiles.php b/Build/Scripts/validateRstFiles.php deleted file mode 100755 index ceb80938..00000000 --- a/Build/Scripts/validateRstFiles.php +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env php - - * - * By default, the standard path is used. You can override this for - * testing purposes. - */ -class validateRstFiles -{ - /** - * @var array - */ - protected $messages; - - /** - * @var bool - */ - protected $isError; - - /** - * @var string - */ - protected $baseDir = 'Documentation'; - - public function __construct(string $dir = '') - { - if ($dir) { - $this->baseDir = $dir; - } - } - - public function validate() - { - printf('Searching for rst snippets in ' . $this->baseDir . chr(10)); - - $count = 0; - $finder = $this->findFiles(); - foreach ($finder as $file) { - $filename = (string)$file; - $this->clearMessages(); - $fileContent = $file->getContents(); - $this->validateContent($fileContent); - - if ($this->isError) { - $shortPath = substr($filename, strlen($this->baseDir)); - $shortPath = ltrim($shortPath, '/\\'); - $count++; - printf( - '%-10s | %-12s | %-17s | %s ' . chr(10), - $this->messages['include']['title'], - $this->messages['reference']['title'], - $this->messages['index']['title'], - $shortPath - ); - if ($this->messages['include']['message']) { - printf($this->messages['include']['message'] . chr(10)); - } - if ($this->messages['reference']['message']) { - printf($this->messages['reference']['message'] . chr(10)); - } - if ($this->messages['index']['message']) { - printf($this->messages['index']['message'] . chr(10)); - } - } - } - - if ($count > 0) { - fwrite(STDERR, 'Found ' . $count . ' rst files with errors, check full log for details.' . chr(10)); - exit(1); - } - exit(0); - } - - public function findFiles(): Finder - { - $finder = new Finder(); - $finder - ->files() - ->in($this->baseDir) - ->name('/\.rst$/'); - - return $finder; - } - - protected function clearMessages() - { - $this->messages = [ - 'include' => [ - 'title' => '', - 'message' => '', - ], - 'reference' => [ - 'title' => '', - 'message' => '', - ], - 'index' => [ - 'title' => '', - 'message' => '', - ], - ]; - - $this->isError = false; - } - - protected function validateContent(string $fileContent) - { - $checkForRequired = [ - [ - 'type' => 'include', - 'regex' => '#^\\.\\.\s+include::\s+\/Includes.rst.txt|\:orphan\:#m', - 'title' => 'no include', - 'message' => 'insert \'.. include:: /Includes.rst.txt\' in first line of the file', - ], - [ - 'type' => 'include', - 'regex' => '#\={2,}\n.*\n\={2,}#m', - 'title' => 'no title', - 'message' => 'Each document must have a title with multiple === above and below', - ], - ]; - - foreach ($checkForRequired as $values) { - if (preg_match($values['regex'], $fileContent) !== 1) { - $this->messages[$values['type']]['title'] = $values['title']; - $this->messages[$values['type']]['message'] = $values['message']; - $this->isError = true; - } - } - - $checkForForbidden = [ - [ - 'type' => 'include', - 'regex' => '#\.\. *important::#m', - 'title' => 'admonition warning forbidden', - 'message' => 'use ".. attention" instead of ".. important"', - ], - ]; - - foreach ($checkForForbidden as $values) { - if (preg_match($values['regex'], $fileContent) > 0) { - $this->messages[$values['type']]['title'] = $values['title']; - $this->messages[$values['type']]['message'] = $values['message']; - $this->isError = true; - } - } - } -} - -$dir = ''; -$args = getopt('d:'); -if (isset($args['d'])) { - $dir = $args['d']; -} -$validator = new validateRstFiles($dir); -$validator->validate(); diff --git a/Makefile b/Makefile index 325b94fd..1196ff05 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,27 @@ help: ## Displays this list of targets with descriptions @echo "The following commands are available:\n" @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' - .PHONY: docs docs: ## Generate projects docs (from "Documentation" directory) mkdir -p Documentation-GENERATED-temp docker run --rm --pull always -v "$(shell pwd)":/project -t ghcr.io/typo3-documentation/render-guides:latest --config=Documentation + +.PHONY: codesnippets +codesnippets: ## Regenerate automatic code snippets + .Build/vendor/bin/typo3 codesnippet:create Documentation/CodeSnippets/ + +.PHONY: test +test: test-lint test-cgl test-docs ## Runs all test suites + +.PHONY: test-lint +test-lint: ## Lint PHP includes + Build/Scripts/runTests.sh -s lint + +.PHONY: test-cgl +test-cgl: ## Test coding guidelines to PHP includes + Build/Scripts/runTests.sh -n -s cgl + +.PHONY: fix-cgl +fix-cgl: ## Apply coding guidelines to PHP includes + Build/Scripts/runTests.sh -s cgl diff --git a/composer.json b/composer.json index d3422e17..4e0ddd7e 100644 --- a/composer.json +++ b/composer.json @@ -60,31 +60,5 @@ "typo3/cms-tstemplate": "dev-main", "typo3/cms-viewpage": "dev-main", "typo3/cms-workspaces": "dev-main" - }, - "scripts": { - "check": [ - "@check:php", - "@check:rst" - ], - "check:php": [ - "@check:php:lint", - "@check:php:cs" - ], - "check:php:cs": "Build/Scripts/runTests.sh -n -s cgl", - "check:php:lint": "Build/Scripts/runTests.sh -s lint", - "check:rst": "Build/Scripts/runTests.sh -s checkRst", - "fix": [ - "@fix:php" - ], - "fix:php": [ - "@fix:php:cs" - ], - "fix:php:cs": "Build/Scripts/runTests.sh -s cgl", - "generate:codesnippets": [ - ".Build/vendor/bin/typo3 codesnippet:create Documentation/CodeSnippets/" - ], - "generate": [ - "@generate:codesnippets" - ] } }