-
Notifications
You must be signed in to change notification settings - Fork 0
05: Static analysis in CI #5
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
+118
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8a2aed
Add PHPStan level 5 and the static analysis workflow
nikolaystrikhar 47e6e8c
Address review: stop the analysis job from drifting off the 7.4 floor
nikolaystrikhar 4e6c22d
Plan: track widening PHPStan to test-support code as deferred item G
nikolaystrikhar b5620f3
Raise PHPStan to level 8
nikolaystrikhar ebd45aa
Add tests directory to PHPStan analysis and exclude generated files
nikolaystrikhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # cspell:ignore shivammathur ramsey reqs | ||
| name: PHPStan | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| # This workflow only reads the repository. Narrow the token accordingly. | ||
| permissions: | ||
| contents: read | ||
|
|
||
| # A superseded PR run is a result nobody is waiting on any more. Pushes to a | ||
| # long-lived branch are left alone so their history stays complete. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| phpstan: | ||
| name: phpstan | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| # The library's own floor, which is also what config.platform.php pins | ||
| # dependency resolution to. Matching the two means this job analyses the | ||
| # exact dependency tree a consumer on the minimum supported PHP gets. | ||
| - name: Configure PHP environment | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: "7.4" | ||
| extensions: mbstring, intl | ||
| coverage: none | ||
|
|
||
| # ext-* only, never the blanket --ignore-platform-reqs. The blanket form | ||
| # also switches off the config.platform.php pin, which resolves dev | ||
| # dependencies requiring PHP 8.1+ that cannot run here at all -- PHPStan | ||
| # would then check src/ against signatures from code this library can | ||
| # never load. wp-browser hard-requires ext-mysqli, ext-zip, and | ||
| # ext-fileinfo that a static-analysis run has no use for; those are what | ||
| # actually need waiving. | ||
| - uses: ramsey/composer-install@v3 | ||
| with: | ||
| composer-options: "--ignore-platform-req=ext-* --optimize-autoloader" | ||
| dependency-versions: highest | ||
|
|
||
| # PHPStan 1.x prints "No files found to analyse" and still exits 0. If | ||
| # src/ ever moves out from under the paths setting, analysis would stop | ||
| # running while the check stayed green, and every later task's "keep | ||
| # test:analysis green" gate would silently become a no-op. | ||
| - name: Assert there is something to analyse | ||
| run: | | ||
| count=$(find src -name '*.php' -type f | wc -l) | ||
| if [ "${count}" -lt 1 ]; then | ||
| echo "phpstan.neon.dist points at src/, which holds no PHP files. Analysis would pass without analysing anything." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Cache entries are immutable, so the write key carries the run id to keep | ||
| # it unique and restore-keys does the actual matching, longest prefix | ||
| # first. head_ref is the branch on a pull_request, where ref_name would be | ||
| # the far less legible "N/merge". | ||
| - name: Restore PHPStan cache | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: phpstan-cache | ||
| key: v1-phpstan-${{ runner.os }}-${{ github.head_ref || github.ref_name }}-${{ github.run_id }} | ||
| restore-keys: | | ||
| v1-phpstan-${{ runner.os }}-${{ github.head_ref || github.ref_name }}- | ||
| v1-phpstan-${{ runner.os }}- | ||
| v1-phpstan- | ||
|
|
||
| - name: Run PHPStan static analysis | ||
| run: composer test:analysis | ||
|
|
||
| # Saved even on failure: the result cache is per-file and records errors | ||
| # as legitimately as passes, so the next run still skips unchanged files. | ||
| - name: Save PHPStan cache | ||
| uses: actions/cache/save@v4 | ||
| if: ${{ !cancelled() }} | ||
| with: | ||
| path: phpstan-cache | ||
| key: v1-phpstan-${{ runner.os }}-${{ github.head_ref || github.ref_name }}-${{ github.run_id }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| includes: | ||
| - vendor/szepeviktor/phpstan-wordpress/extension.neon | ||
|
|
||
| parameters: | ||
| phpVersion: 70400 | ||
| level: 8 | ||
| tmpDir: phpstan-cache | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want to ensure this is in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| # This library is called from untyped WordPress plugin code, so runtime type | ||
| # guards have to survive even where the PHPDoc says they cannot fail. | ||
| treatPhpDocTypesAsCertain: false | ||
|
|
||
| paths: | ||
| - src | ||
| - tests | ||
|
|
||
| excludePaths: | ||
| analyse: | ||
| # Codeception generates the actor's trait from the suite's module list. | ||
| # It is not committed, so on a fresh checkout it does not exist at all; | ||
| # the actor that uses it is excluded alongside it. Everything else under | ||
| # tests/ is hand-written and is analysed. | ||
| - tests/_support/_generated/* | ||
| - tests/_support/UnitTester.php | ||
|
|
||
| scanDirectories: | ||
| - vendor/stellarwp/container-contract/src | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.