From e86c61e4c00a02cd62cff978d4e5a791e3225c7d Mon Sep 17 00:00:00 2001 From: MGatner Date: Thu, 19 May 2022 13:06:57 +0000 Subject: [PATCH 1/2] Add Psalm --- README.md | 3 +- composer.json | 3 +- psalm.xml | 19 ++++++ src/Template/.github/workflows/psalm.yml | 75 ++++++++++++++++++++++++ src/Template/psalm.xml | 0 src/Template/psalm_autoload.php | 21 +++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 psalm.xml create mode 100644 src/Template/.github/workflows/psalm.yml create mode 100644 src/Template/psalm.xml create mode 100644 src/Template/psalm_autoload.php diff --git a/README.md b/README.md index 383e1d4..a5509af 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Development toolkit for CodeIgniter libraries and projects * [NexusPHP Tachycardia](https://github.com/NexusPHP/tachycardia) * [PHPStan](https://phpstan.org/user-guide/getting-started) -* [PHPUnit](http://phpunit.readthedocs.io) +* [PHPUnit](https://phpunit.readthedocs.io) +* [Psalm](https://psalm.dev) ### Mocking diff --git a/composer.json b/composer.json index 154b6da..11ad6d1 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.3", - "roave/security-advisories": "dev-latest" + "roave/security-advisories": "dev-latest", + "vimeo/psalm": "^4.22" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..6f69486 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/src/Template/.github/workflows/psalm.yml b/src/Template/.github/workflows/psalm.yml new file mode 100644 index 0000000..03eb1cd --- /dev/null +++ b/src/Template/.github/workflows/psalm.yml @@ -0,0 +1,75 @@ +name: Psalm + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - 'composer.*' + - 'psalm*' + - '.github/workflows/psalm.yml' + push: + branches: + - develop + paths: + - '**.php' + - 'composer.*' + - 'psalm*' + - '.github/workflows/psalm.yml' + +jobs: + build: + name: PHP ${{ matrix.php-versions }} Psalm Analysis + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: phpstan, phpunit + extensions: intl, json, mbstring, xml + coverage: none + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Create Psalm cache directory + run: mkdir -p build/psalm + + - name: Cache Psalm results + uses: actions/cache@v3 + with: + path: build/psalm + key: ${{ runner.os }}-psalm-${{ github.sha }} + restore-keys: ${{ runner.os }}-psalm- + + - name: Install dependencies + run: | + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi + + - name: Run Psalm analysis + run: vendor/bin/psalm diff --git a/src/Template/psalm.xml b/src/Template/psalm.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/Template/psalm_autoload.php b/src/Template/psalm_autoload.php new file mode 100644 index 0000000..ba1bf17 --- /dev/null +++ b/src/Template/psalm_autoload.php @@ -0,0 +1,21 @@ + Date: Fri, 20 May 2022 23:01:19 +0000 Subject: [PATCH 2/2] Limit Psalm to one version --- src/Template/.github/workflows/psalm.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Template/.github/workflows/psalm.yml b/src/Template/.github/workflows/psalm.yml index 03eb1cd..a56ed92 100644 --- a/src/Template/.github/workflows/psalm.yml +++ b/src/Template/.github/workflows/psalm.yml @@ -20,13 +20,9 @@ on: jobs: build: - name: PHP ${{ matrix.php-versions }} Psalm Analysis + name: Psalm Analysis runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" - strategy: - fail-fast: false - matrix: - php-versions: ['7.4', '8.0', '8.1'] steps: - name: Checkout @@ -35,7 +31,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: '8.0' tools: phpstan, phpunit extensions: intl, json, mbstring, xml coverage: none