From 8100d9d22911f92e30e3abfaf394b2591b686594 Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:35:52 -0400 Subject: [PATCH 1/8] Create coding-standards.yml --- .github/workflows/coding-standards.yml | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/coding-standards.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 00000000..5f3afe1d --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,48 @@ +name: "Coding Standards" + +on: + pull_request: + paths: + - 'source/**/*.php' + +env: + PHP_VERSION: "8.2" + # TODO: change to "stable" once 1.20.0 is released + # DRIVER_VERSION: "stable" + DRIVER_VERSION: "mongodb/mongo-php-driver@master" + +jobs: + phpcs: + name: "phpcs" + runs-on: "ubuntu-22.04" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Setup" + uses: "./.github/actions/setup" + with: + php-version: ${{ env.PHP_VERSION }} + driver-version: ${{ env.DRIVER_VERSION }} + + # The -q option is required until phpcs v4 is released + - name: "Run PHP_CodeSniffer" + run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" + + rector: + name: "Rector" + runs-on: "ubuntu-22.04" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - 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" From 940e9f5b1725bd516d33928febf5cac68ad448dc Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 21 Aug 2024 15:43:08 -0400 Subject: [PATCH 2/8] add static analysis --- .github/workflows/static-analysis.yml | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 00000000..da902f79 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,57 @@ +name: "Static Analysis" + +on: + pull_request: + paths: + - "source/**/*.php" + workflow_call: + inputs: + ref: + description: "The git ref to check" + type: string + required: true + +env: + PHP_VERSION: "8.2" + # TODO: change to "stable" once 1.20.0 is released + # DRIVER_VERSION: "stable" + DRIVER_VERSION: "mongodb/mongo-php-driver@master" + +jobs: + psalm: + name: "Psalm" + runs-on: "ubuntu-22.04" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + with: + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }} + + - name: "Get SHA hash of checked out ref" + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + echo CHECKED_OUT_SHA=$(git rev-parse HEAD) >> $GITHUB_ENV + + - name: "Setup" + uses: "./.github/actions/setup" + with: + php-version: ${{ env.PHP_VERSION }} + driver-version: ${{ env.DRIVER_VERSION }} + + - name: "Run Psalm" + run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --report=psalm.sarif" + + - name: "Upload SARIF report" + if: ${{ github.event_name != 'workflow_dispatch' }} + uses: "github/codeql-action/upload-sarif@v3" + with: + sarif_file: psalm.sarif + + - name: "Upload SARIF report" + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: "github/codeql-action/upload-sarif@v3" + with: + sarif_file: psalm.sarif + ref: ${{ inputs.ref }} + sha: ${{ env.CHECKED_OUT_SHA }} From 694ec2e254199f1c04346d4dea006b899bcffca4 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 22 Aug 2024 10:10:48 -0400 Subject: [PATCH 3/8] JM review actions --- .github/workflows/coding-standards.yml | 20 ++------------------ .github/workflows/static-analysis.yml | 1 + composer.json | 12 ++++++++++++ 3 files changed, 15 insertions(+), 18 deletions(-) create mode 100644 composer.json diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 5f3afe1d..30012e46 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -3,7 +3,8 @@ name: "Coding Standards" on: pull_request: paths: - - 'source/**/*.php' + - "source/**/*.php" + - ".github/workflows/*.yml" env: PHP_VERSION: "8.2" @@ -29,20 +30,3 @@ jobs: # The -q option is required until phpcs v4 is released - name: "Run PHP_CodeSniffer" run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" - - rector: - name: "Rector" - runs-on: "ubuntu-22.04" - - steps: - - name: "Checkout" - uses: "actions/checkout@v4" - - - 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" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index da902f79..ef58d7c5 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -4,6 +4,7 @@ on: pull_request: paths: - "source/**/*.php" + - ".github/workflows/*.yml" workflow_call: inputs: ref: diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..d1582a96 --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "name": "mongodb/docs-php-library", + "description": "MongoDB PHP Library Documentation", + "require": { + "mongodb/mongodb": "^1.20" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "squizlabs/php_codesniffer": "^3.7", + "vimeo/psalm": "^5.13" + } +} From 447277ed381a3edc995a7a2681fd67f3baa2e86b Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 22 Aug 2024 10:12:36 -0400 Subject: [PATCH 4/8] add setup action --- .github/actions/setup/action.yml | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/actions/setup/action.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 00000000..61d350f3 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,52 @@ +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: ${{ inputs.php-version }} + extensions: "mongodb-${{ inputs.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/composer-install@3.0.0 + with: + # Revert when psalm supports PHP 8.4 + # composer-options: "--no-suggest" + composer-options: "--no-suggest ${{ inputs.php-version == '8.4' + && '--ignore-platform-req=php+' || '' }}" From f6418c4237f62b1ebb2c2246ecb5a1f9c8a1b764 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 22 Aug 2024 10:22:08 -0400 Subject: [PATCH 5/8] downgrade php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d1582a96..ec47c537 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mongodb/docs-php-library", "description": "MongoDB PHP Library Documentation", "require": { - "mongodb/mongodb": "^1.20" + "mongodb/mongodb": "^1.19" }, "require-dev": { "doctrine/coding-standard": "^12.0", From ac68830f668e5a1ffec821d19414e29af6278c6b Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 22 Aug 2024 10:26:19 -0400 Subject: [PATCH 6/8] allow plugin --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index ec47c537..f4225c83 100644 --- a/composer.json +++ b/composer.json @@ -8,5 +8,10 @@ "doctrine/coding-standard": "^12.0", "squizlabs/php_codesniffer": "^3.7", "vimeo/psalm": "^5.13" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } From 84e1d055759ef96b90e1a0ebd5b8634f74f986f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 23 Aug 2024 18:27:11 +0200 Subject: [PATCH 7/8] Add phpcs rules --- .gitignore | 3 + phpcs.xml | 126 ++++++++++++++++++ .../handling-embedded-documents/Person.php | 2 +- 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 phpcs.xml diff --git a/.gitignore b/.gitignore index b42a4f24..c50788aa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build *giza.log source/* backups/* +vendor/ +composer.lock +.phpcs-cache diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..b7a82547 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + source/examples + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tests + + + tests + + + tests + + + + + + + + src + + + + + + + + /src/GridFS/StreamWrapper + /tests/DocumentationExamplesTest.php + /tests/GridFS/UnusableStream.php + /tests/SpecTests/ClientSideEncryption/Prose* + + + /examples + /tests/PHPUnit/ConstraintTrait.php + + + /examples + + + /tests/SpecTests/ClientSideEncryption/Prose* + + diff --git a/source/examples/codecs/handling-embedded-documents/Person.php b/source/examples/codecs/handling-embedded-documents/Person.php index a2440d54..9367c27e 100644 --- a/source/examples/codecs/handling-embedded-documents/Person.php +++ b/source/examples/codecs/handling-embedded-documents/Person.php @@ -8,7 +8,7 @@ final class Person public function __construct( public string $name, - public readonly ObjectId $id = new ObjectId() + public readonly ObjectId $id = new ObjectId(), ) { } } From 00c1a2ad70f7f373d97432fe56c9ee37d454fd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 23 Aug 2024 18:38:02 +0200 Subject: [PATCH 8/8] Add psalm config --- composer.json | 1 + psalm-baseline.xml | 57 ++++++++++++++++++++++++++++++++++++++++++++++ psalm.xml | 37 ++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 psalm-baseline.xml create mode 100644 psalm.xml diff --git a/composer.json b/composer.json index f4225c83..3efdceab 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "mongodb/docs-php-library", "description": "MongoDB PHP Library Documentation", "require": { + "ext-mongodb": "^1.19", "mongodb/mongodb": "^1.19" }, "require-dev": { diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 00000000..19357242 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..dc1d7d11 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + +