From caa291e66e3918ac5f1f8298ab5d8fee40ec273e Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 12 May 2025 23:15:32 +0200 Subject: [PATCH 1/6] Replace super-linter with a reusable workflow --- .github/workflows/php.yml | 269 ++++++++++++++++---------------- routing/routes/routes.yml | 18 ++- tools/linters/.stylelintrc.json | 4 + tools/linters/.yaml-lint.yml | 7 + tools/linters/eslint.config.js | 19 +++ 5 files changed, 179 insertions(+), 138 deletions(-) create mode 100644 tools/linters/.stylelintrc.json create mode 100644 tools/linters/.yaml-lint.yml create mode 100644 tools/linters/eslint.config.js diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index bd604b1..c49b33c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -14,34 +14,148 @@ 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: true + enable_jsonlinter: true + enable_stylelinter: true + 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, 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, 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 runs-on: [ubuntu-latest] + needs: [unit-tests-linux] steps: - name: Setup PHP, with composer and extensions @@ -50,7 +164,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, opcache, openssl, pcre, posix, spl, xml @@ -112,6 +226,8 @@ jobs: security: name: Security checks runs-on: [ubuntu-latest] + needs: [unit-tests-linux] + steps: - name: Setup PHP, with composer and extensions # https://github.com/shivammathur/setup-php @@ -150,122 +266,11 @@ 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, 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', '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, 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] needs: [unit-tests-linux] + steps: - uses: actions/checkout@v4 diff --git a/routing/routes/routes.yml b/routing/routes/routes.yml index 5528f7a..5633363 100644 --- a/routing/routes/routes.yml +++ b/routing/routes/routes.yml @@ -1,9 +1,15 @@ +--- + discopower-main: - path: /disco.php - defaults: { _controller: 'SimpleSAML\Module\discopower\Controller\DiscoPower::main' } - methods: [GET] + path: /disco.php + defaults: { + _controller: 'SimpleSAML\Module\discopower\Controller\DiscoPower::main' + } + methods: [GET] discopower-tablist: - path: /tablist - defaults: { _controller: 'SimpleSAML\Module\discopower\Controller\DiscoPower::tablist' } - methods: [GET] + path: /tablist + defaults: { + _controller: 'SimpleSAML\Module\discopower\Controller\DiscoPower::tablist' + } + methods: [GET] diff --git a/tools/linters/.stylelintrc.json b/tools/linters/.stylelintrc.json new file mode 100644 index 0000000..531712e --- /dev/null +++ b/tools/linters/.stylelintrc.json @@ -0,0 +1,4 @@ +{ + "rules": { + } +} 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 diff --git a/tools/linters/eslint.config.js b/tools/linters/eslint.config.js new file mode 100644 index 0000000..8f7e60e --- /dev/null +++ b/tools/linters/eslint.config.js @@ -0,0 +1,19 @@ +// eslint.config.js +const { defineConfig } = require("eslint/config"); + +module.exports = defineConfig([ + { + ignores: ["!/tools/linters/.eslint.config.js", "!/tools/linters/.stylelintrc.json", "!/public/assets/components/jquery-ui.min.js"], + languageOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + files: [ + "**/*.js", + ], + rules: { + semi: "error", + "prefer-const": "error" + } + } +]); From f685b6178969be008e39827c821c14c4e82bb8e6 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 12 May 2025 23:31:50 +0200 Subject: [PATCH 2/6] Replace super-linter with a reusable workflow --- tools/linters/eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linters/eslint.config.js b/tools/linters/eslint.config.js index 8f7e60e..eaa130d 100644 --- a/tools/linters/eslint.config.js +++ b/tools/linters/eslint.config.js @@ -3,7 +3,7 @@ const { defineConfig } = require("eslint/config"); module.exports = defineConfig([ { - ignores: ["!/tools/linters/.eslint.config.js", "!/tools/linters/.stylelintrc.json", "!/public/assets/components/jquery-ui.min.js"], + ignores: ["!/tools/linters/.eslint.config.js", "!/tools/linters/.stylelintrc.json", "/public/assets/components/jquery-ui.min.js"], languageOptions: { ecmaVersion: 2015, sourceType: "module" From 71ddb92bda69668eb967bb88877b1d6cc108bebf Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 May 2025 19:38:55 +0200 Subject: [PATCH 3/6] Remove stale symlinks --- public/assets/components/jquery-ui.min.css | 1 - public/assets/components/jquery-ui.min.js | 1 - public/assets/components/jquery.min.js | 1 - public/assets/components/jquery.min.map | 1 - 4 files changed, 4 deletions(-) delete mode 120000 public/assets/components/jquery-ui.min.css delete mode 120000 public/assets/components/jquery-ui.min.js delete mode 120000 public/assets/components/jquery.min.js delete mode 120000 public/assets/components/jquery.min.map diff --git a/public/assets/components/jquery-ui.min.css b/public/assets/components/jquery-ui.min.css deleted file mode 120000 index d53e00d..0000000 --- a/public/assets/components/jquery-ui.min.css +++ /dev/null @@ -1 +0,0 @@ -../../../../../vendor/components/jqueryui/themes/base/jquery-ui.min.css \ No newline at end of file diff --git a/public/assets/components/jquery-ui.min.js b/public/assets/components/jquery-ui.min.js deleted file mode 120000 index 88f0deb..0000000 --- a/public/assets/components/jquery-ui.min.js +++ /dev/null @@ -1 +0,0 @@ -../../../../../vendor/components/jqueryui/jquery-ui.min.js \ No newline at end of file diff --git a/public/assets/components/jquery.min.js b/public/assets/components/jquery.min.js deleted file mode 120000 index 5822c49..0000000 --- a/public/assets/components/jquery.min.js +++ /dev/null @@ -1 +0,0 @@ -../../../../../vendor/components/jquery/jquery.min.js \ No newline at end of file diff --git a/public/assets/components/jquery.min.map b/public/assets/components/jquery.min.map deleted file mode 120000 index 189eda1..0000000 --- a/public/assets/components/jquery.min.map +++ /dev/null @@ -1 +0,0 @@ -../../../../../vendor/components/jquery/jquery.min.map \ No newline at end of file From eec6b9c45f0f2978aea8a982d971f7beee4081ac Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 May 2025 19:41:44 +0200 Subject: [PATCH 4/6] Add missing semi-colons --- public/assets/js/quicksilver.js | 36 ++++++++++++++++----------------- public/assets/js/suggest.js | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/public/assets/js/quicksilver.js b/public/assets/js/quicksilver.js index 831cf0b..5769349 100644 --- a/public/assets/js/quicksilver.js +++ b/public/assets/js/quicksilver.js @@ -36,18 +36,18 @@ String.prototype.score = function (abbreviation,offset) { - offset = offset || 0 // TODO: I think this is unused... remove + offset = offset || 0; // TODO: I think this is unused... remove if (abbreviation.length === 0) { - return 0.9 + return 0.9; } if (abbreviation.length > this.length) { - return 0.0 + return 0.0; } for (var i = abbreviation.length; i > 0; i--) { - var sub_abbreviation = abbreviation.substring(0,i) - var index = this.indexOf(sub_abbreviation) + var sub_abbreviation = abbreviation.substring(0,i); + var index = this.indexOf(sub_abbreviation); if (index < 0) { @@ -57,27 +57,27 @@ String.prototype.score = function (abbreviation,offset) { continue; } - var next_string = this.substring(index + sub_abbreviation.length) - var next_abbreviation = null + var next_string = this.substring(index + sub_abbreviation.length); + var next_abbreviation = null; if (i >= abbreviation.length) { - next_abbreviation = '' + next_abbreviation = ''; } else { - next_abbreviation = abbreviation.substring(i) + next_abbreviation = abbreviation.substring(i); } - var remaining_score = next_string.score(next_abbreviation,offset + index) + var remaining_score = next_string.score(next_abbreviation,offset + index); if (remaining_score > 0) { var score = this.length - next_string.length; if (index != 0) { var j = 0; - var c = this.charCodeAt(index - 1) + var c = this.charCodeAt(index - 1); if ( c == 32 || c == 9) { for (j = (index - 2); j >= 0; j--) { - c = this.charCodeAt(j) - score -= ((c == 32 || c == 9) ? 1 : 0.15) + c = this.charCodeAt(j); + score -= ((c == 32 || c == 9) ? 1 : 0.15); } // XXX maybe not port this heuristic // @@ -89,14 +89,14 @@ String.prototype.score = function (abbreviation,offset) { // score -= 0.15; // } } else { - score -= index + score -= index; } } - score += remaining_score * next_string.length + score += remaining_score * next_string.length; score /= this.length; - return score + return score; } } - return 0.0 -} + return 0.0; +}; diff --git a/public/assets/js/suggest.js b/public/assets/js/suggest.js index c30e7ba..9a5a669 100644 --- a/public/assets/js/suggest.js +++ b/public/assets/js/suggest.js @@ -22,4 +22,4 @@ String.prototype.score = function (abbreviation,offset) { } } return 1; -} +}; From 95ab94f25cdffebc73dca7be433ed541f110c923 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 May 2025 19:56:19 +0200 Subject: [PATCH 5/6] Bump SSP to 2.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 35380d4..48734de 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "php": "^8.1", "simplesamlphp/assert": "^1.6.0", - "simplesamlphp/simplesamlphp": "^2.3.0", + "simplesamlphp/simplesamlphp": "^2.4.0", "simplesamlphp/simplesamlphp-assets-jquery": "^2.3.0", "simplesamlphp/composer-module-installer": "^1.3.5", "symfony/http-foundation": "^6.4.0" From fb8dbe5f8572c6378574ec90a5fff77370819743 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 13 May 2025 19:56:54 +0200 Subject: [PATCH 6/6] Final test-classes --- tests/src/Controller/DiscoPowerTest.php | 2 +- tests/src/PowerIdPDiscoTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Controller/DiscoPowerTest.php b/tests/src/Controller/DiscoPowerTest.php index 47b5293..4165d8f 100644 --- a/tests/src/Controller/DiscoPowerTest.php +++ b/tests/src/Controller/DiscoPowerTest.php @@ -16,7 +16,7 @@ * Set of tests for the controllers in the "discopower" module. */ #[CoversClass(Controller\DiscoPower::class)] -class DiscoPowerTest extends ClearStateTestCase +final class DiscoPowerTest extends ClearStateTestCase { /** @var \SimpleSAML\Configuration */ private static Configuration $discoconfig; diff --git a/tests/src/PowerIdPDiscoTest.php b/tests/src/PowerIdPDiscoTest.php index 26b729a..997687a 100644 --- a/tests/src/PowerIdPDiscoTest.php +++ b/tests/src/PowerIdPDiscoTest.php @@ -12,7 +12,7 @@ use SimpleSAML\Module\discopower\PowerIdPDisco; #[CoversClass(PowerIdPDisco::class)] -class PowerIdPDiscoTest extends TestCase +final class PowerIdPDiscoTest extends TestCase { /** @var \SimpleSAML\Module\discopower\PowerIdPDisco */ private static PowerIdPDisco $discoHandler;