Skip to content

Commit

Permalink
Enhancement: Run vimeo/psalm on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 27, 2024
1 parent db5ec41 commit 87e4e1b
Show file tree
Hide file tree
Showing 9 changed files with 1,253 additions and 107 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[*.xml]
indent_size = 2
indent_style = space

[*.yaml]
indent_size = 2
indent_style = space
Expand Down
28 changes: 27 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ about what you're working on, you can contact us via the
```
to automatically fix coding standard issues.
- Run
```shell
make static-code-analysis
```
to run a static code analysis or, if applicable, run
```shell
make static-code-analysis-baseline
```
to regenerate the baseline.
- Review the change once more just before submitting it.
## What happens after submitting contribution?
Expand Down Expand Up @@ -133,7 +146,20 @@ Having said that, here are the organizational rules:
```shell
make coding-standards
```
6. Run
```shell
make static-code-analysis
```
to run a static code analysis or, if applicable, run
```shell
make static-code-analysis-baseline
```
to regenerate the baseline.
6. Use reasonable commit messages.
7. Use reasonable commit messages.
Thank you for contributing to https://www.php.net!
49 changes: 46 additions & 3 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "xdebug"
extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter"
extensions: "none, curl, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter"
extensions: "none, curl, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
Expand All @@ -97,6 +97,49 @@ jobs:
- name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --show-progress=dots --verbose"

static-code-analysis:
name: "Static Code Analysis"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "8.2"

dependencies:
- "locked"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "none, curl, dom, json, mbstring, opcache, pcntl, posix, simplexml, tokenizer, xml, xmlwriter"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""

- name: "Determine composer cache directory"
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v3"
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"

- name: "Install dependencies with composer"
run: "composer install --ansi --no-interaction --no-progress"

- name: "Run vimeo/psalm"
run: "vendor/bin/psalm --config=psalm.xml --output-format=github --shepherd --show-info=false --stats --threads=4"

tests:
name: "Tests"

Expand All @@ -118,7 +161,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter"
extensions: "none, curl, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HTTP_HOST:=localhost:8080

.PHONY: it
it: coding-standards tests ## Runs all the targets
it: coding-standards static-code-analysis tests ## Runs all the targets

.PHONY: code-coverage
code-coverage: vendor ## Collects code coverage from running unit tests with phpunit/phpunit
Expand All @@ -17,6 +17,14 @@ coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fix
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: static-code-analysis
static-code-analysis: vendor ## Runs a static code analysis with vimeo/psalm
vendor/bin/psalm --config=psalm.xml --show-info=false --stats --threads=4

.PHONY: static-code-analysis-baseline
static-code-analysis-baseline: vendor ## Generates a baseline for static code analysis with vimeo/psalm
vendor/bin/psalm --config=psalm.xml --set-baseline=psalm-baseline.xml

.PHONY: tests
tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit
vendor/bin/phpunit --configuration=tests/phpunit.xml --testsuite=unit
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Integrate](https://github.com/php/web-php/actions/workflows/integrate.yaml/badge.svg)](https://github.com/php/web-php/actions/workflows/integrate.yaml)
[![Type Coverage](https://shepherd.dev/github/php/web-php/coverage.svg)](https://shepherd.dev/github/php/web-php)

## Local development

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"require-dev": {
"ext-curl": "*",
"friendsofphp/php-cs-fixer": "^3.50.0",
"phpunit/phpunit": "^10.5.11"
"phpunit/phpunit": "^10.5.11",
"psalm/plugin-phpunit": "~0.18.4",
"vimeo/psalm": "^5.22.2"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 87e4e1b

Please sign in to comment.