From 0522d4bac1cad58d0476f1fef7d5eddce2b3aa73 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 27 May 2025 22:26:41 +0200 Subject: [PATCH] Replace super-linter with a reusable workflow --- .github/workflows/php.yml | 266 +++++++++--------- .../module_authmemcookie.php.dist | 0 phpcs.xml | 2 +- psalm-dev.xml | 9 - psalm.xml | 2 +- routing/routes/routes.yml | 10 +- tests/src/Controller/MemcookieTest.php | 5 +- tools/linters/.yaml-lint.yml | 7 + 8 files changed, 150 insertions(+), 151 deletions(-) rename {config-templates => config}/module_authmemcookie.php.dist (100%) create mode 100644 tools/linters/.yaml-lint.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f75a7c2..260dddd 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -14,30 +14,142 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: jobs: + phplinter: + name: 'PHP-Linter' + strategy: + fail-fast: false + matrix: + php-version: ['8.1', '8.2', '8.3', '8.4'] + + uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_phplinter.yml@v1.9.2 + with: + php-version: ${{ matrix.php-version }} + linter: - name: Linter - runs-on: ['ubuntu-latest'] + name: 'Linter' + strategy: + fail-fast: false + + uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_linter.yml@v1.9.2 + with: + enable_eslinter: false + enable_jsonlinter: true + enable_stylelinter: false + enable_yamllinter: true + + unit-tests-linux: + name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" + runs-on: ${{ matrix.operating-system }} + needs: [phplinter, linter] + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.1', '8.2', '8.3', '8.4'] steps: + - name: Setup PHP, with composer and extensions + # https://github.com/shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, \ + memcached, openssl, pcre, posix, spl, xml + tools: composer + ini-values: error_reporting=E_ALL + coverage: pcov + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - uses: actions/checkout@v4 + + - name: Get composer cache directory + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV" + + - name: Cache composer dependencies + uses: actions/cache@v4 with: - fetch-depth: 0 - - - name: Lint Code Base - uses: super-linter/super-linter/slim@v7 - env: - SAVE_SUPER_LINTER_OUTPUT: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LINTER_RULES_PATH: 'tools/linters' - LOG_LEVEL: NOTICE - VALIDATE_ALL_CODEBASE: true - VALIDATE_CSS: true - VALIDATE_JAVASCRIPT_ES: true - VALIDATE_JSON: true - VALIDATE_PHP_BUILTIN: true - VALIDATE_YAML: true - VALIDATE_XML: true - VALIDATE_GITHUB_ACTIONS: true + path: $COMPOSER_CACHE + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Run unit tests with coverage + if: ${{ matrix.php-versions == '8.4' }} + run: vendor/bin/phpunit + + - name: Run unit tests (no coverage) + if: ${{ matrix.php-versions != '8.4' }} + run: vendor/bin/phpunit --no-coverage + + - name: Save coverage data + if: ${{ matrix.php-versions == '8.4' }} + uses: actions/upload-artifact@v4 + with: + name: coverage-data + path: ${{ github.workspace }}/build + + unit-tests-windows: + name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" + runs-on: ${{ matrix.operating-system }} + needs: [phplinter, linter] + strategy: + fail-fast: true + matrix: + operating-system: [windows-latest] + php-versions: ['8.1', '8.2', '8.3', '8.4'] + + steps: + - name: Setup PHP, with composer and extensions + # https://github.com/shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, memcached-3.3.0, \ + openssl, pcre, posix, spl, xml + tools: composer + ini-values: error_reporting=E_ALL + coverage: none + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - uses: actions/checkout@v4 + + - name: Get composer cache directory + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV" + + - name: Cache composer dependencies + uses: actions/cache@v4 + with: + path: $COMPOSER_CACHE + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix + + - name: Run unit tests + run: vendor/bin/phpunit --no-coverage quality: name: Quality control @@ -50,7 +162,7 @@ jobs: uses: shivammathur/setup-php@v2 with: # Should be the higest supported version, so we can use the newest tools - php-version: '8.3' + php-version: '8.4' tools: composer, composer-require-checker, composer-unused, phpcs, psalm # optional performance gain for psalm: opcache extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, \ @@ -150,120 +262,6 @@ jobs: - name: Security check for updated dependencies run: composer audit - unit-tests-linux: - name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" - runs-on: ${{ matrix.operating-system }} - needs: [linter, quality, security] - strategy: - fail-fast: false - matrix: - operating-system: [ubuntu-latest] - php-versions: ['8.1', '8.2', '8.3'] - - steps: - - name: Setup PHP, with composer and extensions - # https://github.com/shivammathur/setup-php - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, \ - memcached, openssl, pcre, posix, spl, xml - tools: composer - ini-values: error_reporting=E_ALL - coverage: pcov - - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - - name: Setup problem matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Set git to use LF - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - - uses: actions/checkout@v4 - - - name: Get composer cache directory - run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV" - - - name: Cache composer dependencies - uses: actions/cache@v4 - with: - path: $COMPOSER_CACHE - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install Composer dependencies - run: composer install --no-progress --prefer-dist --optimize-autoloader - - - name: Run unit tests with coverage - if: ${{ matrix.php-versions == '8.3' }} - run: vendor/bin/phpunit - - - name: Run unit tests (no coverage) - if: ${{ matrix.php-versions != '8.3' }} - run: vendor/bin/phpunit --no-coverage - - - name: Save coverage data - if: ${{ matrix.php-versions == '8.3' }} - uses: actions/upload-artifact@v4 - with: - name: coverage-data - path: ${{ github.workspace }}/build - - unit-tests-windows: - name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" - runs-on: ${{ matrix.operating-system }} - needs: [linter, quality, security] - strategy: - fail-fast: true - matrix: - operating-system: [windows-latest] - php-versions: ['8.1'] - #php-versions: ['8.1', '8.2', '8.3'] Waiting for memcached-3.2.1 - - steps: - - name: Setup PHP, with composer and extensions - # https://github.com/shivammathur/setup-php - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, memcached-3.2.0, openssl, pcre, posix, spl, xml - tools: composer - ini-values: error_reporting=E_ALL - coverage: none - - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - - name: Setup problem matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Set git to use LF - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - - uses: actions/checkout@v4 - - - name: Get composer cache directory - run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV" - - - name: Cache composer dependencies - uses: actions/cache@v4 - with: - path: $COMPOSER_CACHE - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install Composer dependencies - run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix - - - name: Run unit tests - run: vendor/bin/phpunit --no-coverage - coverage: name: Code coverage runs-on: [ubuntu-latest] diff --git a/config-templates/module_authmemcookie.php.dist b/config/module_authmemcookie.php.dist similarity index 100% rename from config-templates/module_authmemcookie.php.dist rename to config/module_authmemcookie.php.dist diff --git a/phpcs.xml b/phpcs.xml index 5d9f4ab..93df8ab 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -4,7 +4,7 @@ By default it is less stringent about long lines than other coding standards - config-templates + config src tests diff --git a/psalm-dev.xml b/psalm-dev.xml index 960d692..078f21a 100644 --- a/psalm-dev.xml +++ b/psalm-dev.xml @@ -16,15 +16,6 @@ - - - - - - - - - diff --git a/psalm.xml b/psalm.xml index 0a923ab..955b74d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,7 +6,7 @@ reportMixedIssues="false" > - + diff --git a/routing/routes/routes.yml b/routing/routes/routes.yml index 2a51241..a61186b 100644 --- a/routing/routes/routes.yml +++ b/routing/routes/routes.yml @@ -1,4 +1,8 @@ +--- + memcookie-main: - path: / - defaults: { _controller: 'SimpleSAML\Module\memcookie\Controller\Memcookie::main' } - methods: [GET] + path: / + defaults: { + _controller: 'SimpleSAML\Module\memcookie\Controller\Memcookie::main' + } + methods: [GET] diff --git a/tests/src/Controller/MemcookieTest.php b/tests/src/Controller/MemcookieTest.php index 8713095..047e084 100644 --- a/tests/src/Controller/MemcookieTest.php +++ b/tests/src/Controller/MemcookieTest.php @@ -18,7 +18,7 @@ * * @package SimpleSAML\Test */ -class MemcookieTest extends TestCase +final class MemcookieTest extends TestCase { /** @var \SimpleSAML\Configuration */ protected Configuration $authsources; @@ -68,7 +68,7 @@ protected function setUp(): void Configuration::setPreLoadedConfig($this->authsources, 'authsources.php', 'simplesaml'); $this->http_utils = new class () extends Utils\HTTP { - public function setCookie(string $name, ?string $value, array $params = null, bool $throw = true): void + public function setCookie(string $name, ?string $value, ?array $params = null, bool $throw = true): void { // stub } @@ -132,7 +132,6 @@ public function getAttributes(): array } }); - /** @var \SimpleSAML\HTTP\RunnableResponse $response */ $response = $c->main($request); $this->assertInstanceOf(RunnableResponse::class, $response); diff --git a/tools/linters/.yaml-lint.yml b/tools/linters/.yaml-lint.yml new file mode 100644 index 0000000..630095a --- /dev/null +++ b/tools/linters/.yaml-lint.yml @@ -0,0 +1,7 @@ +--- + +extends: default + +rules: + line-length: + max: 120