Skip to content

PHPLIB-1435: Integrate static analysis for releases #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Setup
description: Sets up the build environment
inputs:
php-version:
description: "PHP version to install"
required: true
driver-version:
description: "MongoDB extension version to install"
required: true
php-ini-values:
description: "INI values to pass along to setup-php action"
required: false
default: ""

runs:
using: composite
steps:
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: "mongodb-${{ inputs.driver-version }}"
php-version: "${{ inputs.php-version }}"
tools: cs2pr
ini-values: "${{ inputs.php-ini-values }}"

- name: Show driver information
run: "php --ri mongodb"
shell: bash

- name: Install dependencies with Composer
uses: ramsey/[email protected]
with:
composer-options: "--no-suggest"
31 changes: 3 additions & 28 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,11 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
- name: "Setup"
uses: "./.github/actions/setup"
with:
php-version: ${{ env.PHP_VERSION }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
php-version: "${{ env.PHP_VERSION }}"
tools: "cs2pr"

- name: "Show driver information"
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/[email protected]"
with:
composer-options: "--no-suggest"
driver-version: ${{ env.DRIVER_VERSION }}

# The -q option is required until phpcs v4 is released
- name: "Run PHP_CodeSniffer"
Expand Down
52 changes: 21 additions & 31 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
- "v*.*"
- "master"
- "feature/*"
tags:
- "*"
Copy link
Member

@GromNaN GromNaN May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The analysis will be performed twice on the same commit: 1) for the push on master, 2) for the tag. I presume it's so that the results are linked correctly to the tag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct.


env:
PHP_VERSION: "8.2"
Expand All @@ -26,45 +28,33 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
- name: "Setup"
uses: "./.github/actions/setup"
with:
php-version: ${{ env.PHP_VERSION }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"
driver-version: ${{ env.DRIVER_VERSION }}

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: "Run Psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --report=psalm.sarif"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: "Upload SARIF report"
uses: "github/codeql-action/upload-sarif@v3"
with:
coverage: "none"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
php-version: "${{ env.PHP_VERSION }}"
tools: "cs2pr"
sarif_file: psalm.sarif

- name: "Show driver information"
run: "php --ri mongodb"
rector:
name: "Rector"
runs-on: "ubuntu-22.04"

- name: "Install dependencies with Composer"
uses: "ramsey/[email protected]"
with:
composer-options: "--no-suggest"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Run Psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --report=psalm.sarif"
- name: "Setup"
uses: "./.github/actions/setup"
with:
php-version: ${{ env.PHP_VERSION }}
driver-version: ${{ env.DRIVER_VERSION }}

- name: "Run Rector"
run: "vendor/bin/rector --ansi --dry-run"

- name: "Upload Psalm report"
uses: actions/upload-artifact@v4
with:
name: psalm.sarif
path: psalm.sarif
33 changes: 4 additions & 29 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,12 @@ jobs:
version: ${{ matrix.mongodb-version }}
topology: ${{ matrix.topology }}

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
- name: "Setup"
uses: "./.github/actions/setup"
with:
php-version: ${{ matrix.php-version }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
tools: "pecl"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
coverage: "none"
ini-values: "zend.assertions=1"

- name: "Show driver information"
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/[email protected]"
with:
composer-options: "--no-suggest"
driver-version: ${{ env.DRIVER_VERSION }}
php-ini-values: "zend.assertions=1"

- name: "Run PHPUnit"
run: "vendor/bin/simple-phpunit -v"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"rector/rector": "^0.19",
"rector/rector": "^1.1",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^5.2",
"vimeo/psalm": "^5.13"
Expand Down