Skip to content

ci: add rector #100

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 1 commit into from
Feb 20, 2025
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
21 changes: 13 additions & 8 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,45 @@ jobs:
php-version: ${{ matrix.php-versions }}
extensions: none,iconv,dom,curl,mbstring,tokenizer,xml,xmlwriter,simplexml,ctype
coverage: pcov

- name: ♻️ Get composer cache directory
id: composer-cache
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: ♻️ Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: ⚙️ Install dependencies
shell: bash
run: |
composer install --no-progress --prefer-dist --optimize-autoloader
composer --working-dir=tools install --no-progress --prefer-dist --optimize-autoloader

- name: ♻️ Tools cache
uses: actions/cache@v4
with:
path: tools/cache
key: ${{ runner.os }}-tools-${{ github.sha }}
key: ${{ runner.os }}-tools-${{ matrix.php-versions }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-tools-

- name: 👕 Lint
if: matrix.stable
run: composer php-cs-fixer -- --format=checkstyle | tools/vendor/bin/cs2pr

- name: 🔬 Rector
id: rector
if: matrix.stable
run: composer rector

- name: 🔬 Static analysis
if: matrix.stable
run: composer stan -- --error-format=checkstyle | tools/vendor/bin/cs2pr
run: composer phpstan -- --error-format=github

- name: ♻️ Tests cache
uses: actions/cache@v4
Expand All @@ -66,7 +71,7 @@ jobs:
key: ${{ runner.os }}-tests-${{ github.sha }}
restore-keys: |
${{ runner.os }}-tests-

- name: 🧪 Test
run: composer test:ci

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ lint: ## Execute lint for given PHP version
@$(call run-php,composer php-cs-fixer $(filter-out $@,$(MAKECMDGOALS)))

lint-fix: ## Execute lint fixing for given PHP version
@$(call run-php,composer php-cs-fixer:fix $(filter-out $@,$(MAKECMDGOALS)))
@$(call run-php,composer php-cs-fixer:fix $(filter-out $@,$(MAKECMDGOALS)))

stan: ## Execute PHPStan for given PHP version
@$(call run-php,composer stan $(filter-out $@,$(MAKECMDGOALS)))
rector: ## Execute rector for given PHP version
@$(call run-php,composer rector $(filter-out $@,$(MAKECMDGOALS)))

rector-fix: ## Execute rector fixing for given PHP version
@$(call run-php,composer rector:fix $(filter-out $@,$(MAKECMDGOALS)))

phpstan: ## Execute PHPStan for given PHP version
@$(call run-php,composer phpstan $(filter-out $@,$(MAKECMDGOALS)))

ci: ## Execute CI scripts for given PHP version
@$(call run-php,composer ci $(filter-out $@,$(MAKECMDGOALS)))
Expand Down
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,4 @@
2. [Usage](https://neilime.github.io/php-css-lint/usage)
3. [Code Coverage](https://codecov.io/gh/neilime/php-css-lint)
4. [PHP Doc](https://neilime.github.io/php-css-lint/phpdoc)

# Development

## Setup

`PHP_VERSION` is the version of php to use during the development. Example: `8.2`

```sh
make build-php PHP_VERSION
make install PHP_VERSION
```

## Running tests

```sh
make test PHP_VERSION
```

## Fix code linting

```sh
make lint-fix PHP_VERSION
```

## Running CI scripts

```sh
make ci PHP_VERSION
```
5. [Development](https://neilime.github.io/php-css-lint/development)
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@
"test:ci": "@test -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/",
"php-cs-fixer": "@php-cs-fixer:fix --dry-run",
"php-cs-fixer:fix": "tools/vendor/bin/php-cs-fixer fix --show-progress=dots --diff --config=.php-cs-fixer.dist.php",
"stan": "tools/vendor/bin/phpstan analyse --level 5 src",
"rector": "@rector:fix --dry-run",
"rector:fix": "tools/vendor/bin/rector process src",
"phpstan": "tools/vendor/bin/phpstan analyse --level max src",
"ci": [
"@php-cs-fixer",
"@stan",
"@rector",
"@phpstan",
"@test:ci"
]
},
Expand Down
35 changes: 35 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withAttributesSets(
all: true
)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
naming: true,
instanceOf: true,
earlyReturn: true,
strictBooleans: true,
carbon: true,
rectorPreset: true,
phpunitCodeQuality: true,
phpunit: true,
)
->withCache(
cacheClass: FileCacheStorage::class,
cacheDirectory: __DIR__ . '/tools/cache/rector'
);;
Loading
Loading