From 593cc624cd79d656dcd4b7212f279fb5177ccb12 Mon Sep 17 00:00:00 2001 From: Tim <162806658+timotei-litespeed@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:26:50 +0300 Subject: [PATCH] Add PHP CS in GH Actions and Local (#745) Co-authored-by: Timotei --- .github/workflows/ci.yml | 19 ++++- .gitignore | 1 + .prettierignore | 6 ++ composer.json | 13 ++++ composer.lock | 161 +++++++++++++++++++++++++++++++++++++++ phpcs.xml.dist | 62 +++++++++++++++ 6 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 phpcs.xml.dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43e3edcf4..ed2c5e9b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,18 +9,29 @@ on: pull_request: jobs: - test: + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - name: Cache Composer dependencies + uses: actions/cache@v3 with: - node-version: '20' + path: .cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + - name: Initialize Node.js + uses: actions/setup-node@v3 + with: + node-version: '22' check-latest: true cache: npm cache-dependency-path: package-lock.json - - run: npm ci + # Start actions + - run: mkdir -p .cache + - run: composer install + - run: composer run sniff-check + - run: npm clean-install - run: npm run format-check diff --git a/.gitignore b/.gitignore index 5ac2a3cc3..e656415ed 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .env* .vscode node_modules +/vendor diff --git a/.prettierignore b/.prettierignore index c5ec21291..32f938100 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,12 @@ **/*.min.* **/*.ori.* **/*.tpl.php +composer.json +composer.lock +package.json +package-lock.json +vendor +.cache assets/js/css_async.js assets/js/webfontloader.js lib diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..8f75b48be --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "litespeedtech/lscache_wp", + "require-dev": { + "squizlabs/php_codesniffer": "*", + "phpcompatibility/php-compatibility": "*" + }, + "prefer-stable": true, + "scripts": { + "post-install-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", + "post-update-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", + "sniff-check": "phpcs" + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..39c17ed3a --- /dev/null +++ b/composer.lock @@ -0,0 +1,161 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "21330dd959c1642a4c7dbc91aa5effef", + "packages": [], + "packages-dev": [ + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.10.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-07-21T23:26:44+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..32d688516 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,62 @@ + + + Apply LiteSpeed Cache Coding Standards to all plugin files + + + + + + + + + + + + + + + + + + + + + + + + . + + + ^wordpress/* + + + /node_modules/* + /vendor/* + + + + + + + + + + + +