From 6ac937965cf8a42c6dcdd0eca882ca6b43cce04b Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 31 Jan 2024 15:05:51 -0500 Subject: [PATCH 1/4] feat: Add code analysis via CI --- .github/workflows/code-analysis.yaml | 40 ++++++++++++++++++++++++++++ composer.json | 9 +++++++ ecs.php | 3 +-- phpstan.neon | 3 ++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/code-analysis.yaml diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml new file mode 100644 index 0000000..d4bf3fa --- /dev/null +++ b/.github/workflows/code-analysis.yaml @@ -0,0 +1,40 @@ +name: Code Analysis + +on: + pull_request: null + push: + branches: + - develop + workflow_dispatch: +permissions: + contents: read +jobs: + code_analysis: + strategy: + fail-fast: false + matrix: + actions: + - name: 'PHPStan' + run: composer phpstan + - name: 'Coding Standards' + run: composer fix-cs + name: ${{ matrix.actions.name }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + - name: Setup PHP + id: setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip' + ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M + tools: composer:v2 + - name: Install Composer dependencies + run: composer install --no-interaction --no-ansi --no-progress + - run: ${{ matrix.actions.run }} diff --git a/composer.json b/composer.json index fee0791..799bc58 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,15 @@ "nystudio107/craft-code-editor": "^1.0.0", "putyourlightson/craft-sprig-core": "^2.6.4" }, + "require-dev": { + "craftcms/ecs": "dev-main", + "craftcms/phpstan": "dev-main" + }, + "scripts": { + "phpstan": "phpstan --ansi --memory-limit=1G", + "check-cs": "ecs check --ansi", + "fix-cs": "ecs check --fix --ansi", + }, "autoload": { "psr-4": { "putyourlightson\\sprig\\plugin\\": "src/" diff --git a/ecs.php b/ecs.php index ff09fdd..85860c2 100644 --- a/ecs.php +++ b/ecs.php @@ -4,11 +4,10 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function(ECSConfig $ecsConfig): void { - $ecsConfig->parallel(); $ecsConfig->paths([ __DIR__ . '/src', __FILE__, ]); - + $ecsConfig->parallel(); $ecsConfig->sets([SetList::CRAFT_CMS_4]); }; diff --git a/phpstan.neon b/phpstan.neon index 4514cd7..44554e4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - - %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon + - vendor/craftcms/phpstan/phpstan.neon + parameters: level: 5 paths: From 5f81d6028c548612602d880a78124e5f85b01080 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 31 Jan 2024 15:07:21 -0500 Subject: [PATCH 2/4] refactor: Use PHP 8.1 --- .github/workflows/code-analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml index d4bf3fa..678e0c1 100644 --- a/.github/workflows/code-analysis.yaml +++ b/.github/workflows/code-analysis.yaml @@ -31,7 +31,7 @@ jobs: id: setup-php uses: shivammathur/setup-php@v2 with: - php-version: 8.2 + php-version: 8.1 extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip' ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M tools: composer:v2 From 4e9947145a3234a74118e78dea9ab97b63b3f5e3 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 31 Jan 2024 15:11:08 -0500 Subject: [PATCH 3/4] refactor: Add `config` --- composer.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 799bc58..2b6074b 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,21 @@ "scripts": { "phpstan": "phpstan --ansi --memory-limit=1G", "check-cs": "ecs check --ansi", - "fix-cs": "ecs check --fix --ansi", + "fix-cs": "ecs check --fix --ansi" }, "autoload": { "psr-4": { "putyourlightson\\sprig\\plugin\\": "src/" } }, + "config": { + "allow-plugins": { + "craftcms/plugin-installer": true, + "yiisoft/yii2-composer": true + }, + "optimize-autoloader": true, + "sort-packages": true + }, "support": { "docs": "https://putyourlightson.com/plugins/sprig", "source": "https://github.com/putyourlightson/craft-sprig", From e2cee6f1c95a8d7dc68d2a24683cbe12d8e6f2b6 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 31 Jan 2024 15:32:25 -0500 Subject: [PATCH 4/4] refactor: Add note about tests --- .github/workflows/code-analysis.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml index 678e0c1..0a5fedd 100644 --- a/.github/workflows/code-analysis.yaml +++ b/.github/workflows/code-analysis.yaml @@ -18,6 +18,10 @@ jobs: run: composer phpstan - name: 'Coding Standards' run: composer fix-cs + # Tests could be run here too, just set the environment variables as needed, see: + # https://docs.github.com/en/actions/learn-github-actions/variables + # - name: 'Tests' + # run: composer test name: ${{ matrix.actions.name }} runs-on: ubuntu-latest steps: