Skip to content

Commit 9d39ed1

Browse files
committed
create workflow
1 parent ef79b22 commit 9d39ed1

File tree

14 files changed

+412
-59
lines changed

14 files changed

+412
-59
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
ci:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Cache Composer packages
21+
id: composer-cache
22+
uses: actions/cache@v3
23+
with:
24+
path: vendor
25+
key: ${{ runner.os }}-ci-${{ hashFiles('**/composer.json') }}
26+
restore-keys: |
27+
${{ runner.os }}-ci-
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress
31+
32+
- name: Run ci checks
33+
run: composer ci

README.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# CodeBuddy
22

3-
## All-in-One Code Quality Tool for Laravel
3+
## All-in-One Code Quality Tool for your codebase
44

5-
> **Note:** This package is currently compatible only with the Laravel framework.
5+
> **Note:** This package is currently compatible only with the Laravel framework 11 & 12.
66
77
## About
8+
89
CodeBuddy is a wrapper around essential development tools that help maintain code quality in your Laravel projects. It integrates:
910

1011
- **Rector** (automated code refactoring)
@@ -18,29 +19,22 @@ CodeBuddy is a wrapper around essential development tools that help maintain cod
1819
- Automated fixes for coding standards.
1920
- Code health reporting with email support.
2021

21-
## Commands
22+
## Installation
2223

23-
### Configure Code Quality Tools
24-
```sh
25-
php artisan codebuddy:configure
2624
```
27-
This command sets up **Rector, PestPHP, Pint, and PHPStan** with standard configurations.
28-
29-
### Run CI Checks
30-
```sh
31-
php artisan codebuddy:ci [--fix]
25+
composer require codebuddyphp/codebuddy --dev
3226
```
33-
Runs tests, performs static analysis, and checks code style in a **dry-run mode** (does not modify files). Optimized for CI/CD pipelines.
3427

35-
- `--fix`: Automatically applies fixes for Rector and Pint where possible.
28+
## Commands
3629

37-
### Generate Code Quality Report
38-
```sh
39-
php artisan codebuddy:report [--show|--send-to=<email>]
4030
```
41-
- `--show`: Displays the overall code health report in the console.
42-
- `--send-to=<email>`: Sends the report to the specified email address.
31+
php artisan codebuddy:configure
32+
```
4333

44-
---
34+
```
35+
php artisan codebuddy:review
36+
```
4537

46-
This package simplifies code quality enforcement, making it easier to maintain a high standard across your Laravel projects.
38+
```
39+
php artisan codebuddy:insights
40+
```

composer.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
{
22
"name": "codebuddyphp/codebuddy",
3-
"description": "All-in-one tool for your codebase",
3+
"description": "All-in-one tool for your codebase quality",
44
"type": "library",
55
"require": {
66
"php": "^8.2",
77
"laravel/framework": "^11.0",
8-
"nunomaduro/termwind": "^2.3",
9-
"laravel/pint": "^1.20",
8+
"laravel/pint": "^1.21",
9+
"driftingly/rector-laravel": "^2.0",
1010
"larastan/larastan": "^3.0",
11-
"rector/rector": "^2.0"
11+
"pestphp/pest": "^3.7"
12+
},
13+
"require-dev": {
1214
},
1315
"autoload": {
1416
"psr-4": {
1517
"Codebuddyphp\\Codebuddy\\": "src/"
1618
}
1719
},
1820
"scripts": {
21+
"lint": "XDEBUG_MODE=off pint --test",
22+
"lint.fix": "XDEBUG_MODE=off pint",
23+
"stan": "XDEBUG_MODE=off phpstan analyse --ansi --memory-limit=-1",
24+
"test.arch": "XDEBUG_MODE=off pest --testsuite=Architecture",
25+
"test.unit": "XDEBUG_MODE=off pest --testsuite=Unit",
26+
"test.feature": "XDEBUG_MODE=coverage pest --testsuite=Feature --coverage --min=90",
27+
"rector": "XDEBUG_MODE=off rector process --dry-run",
28+
"rector.fix": "XDEBUG_MODE=off rector process",
29+
"ci": [
30+
"@lint",
31+
"@rector"
32+
],
33+
"ci.fix": [
34+
"@rector.fix",
35+
"@lint.fix"
36+
]
1937
},
2038
"extra": {
2139
"laravel": {
@@ -27,7 +45,10 @@
2745
}
2846
},
2947
"config": {
30-
"preferred-install": "dist"
48+
"preferred-install": "dist",
49+
"allow-plugins": {
50+
"pestphp/pest-plugin": true
51+
}
3152
},
3253
"minimum-stability": "dev",
3354
"prefer-stable": true

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- vendor/larastan/larastan/extension.neon
3+
- vendor/nesbot/carbon/extension.neon
4+
5+
parameters:
6+
7+
paths:
8+
- src/
9+
10+
level: max

rector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__.'/config',
10+
__DIR__.'/src',
11+
])
12+
// uncomment to reach your current PHP version
13+
// ->withPhpSets()
14+
->withTypeCoverageLevel(0)
15+
->withDeadCodeLevel(0)
16+
->withCodeQualityLevel(0);

resources/views/banner.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="m-1">
2+
<div class="px-1 bg-sky-600">CodeBuddy</div>
3+
<em class="ml-1 underline">
4+
All-in-one tool for your codebase quality
5+
</em>
6+
</div>

src/CodebuddyServiceProvider.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Codebuddyphp\Codebuddy;
44

55
use Codebuddyphp\Codebuddy\Commands\Configure;
6+
use Codebuddyphp\Codebuddy\Commands\Install;
7+
use Codebuddyphp\Codebuddy\Commands\Report;
8+
use Codebuddyphp\Codebuddy\Commands\Review;
69
use Illuminate\Support\ServiceProvider;
710

811
class CodebuddyServiceProvider extends ServiceProvider
@@ -12,23 +15,32 @@ public function register()
1215
// Register bindings if any
1316
}
1417

15-
public function boot()
18+
public function boot(): void
1619
{
1720
if ($this->app->runningInConsole()) {
1821
$this->commands([
1922
Configure::class,
23+
Review::class,
24+
Report::class,
2025
]);
2126

2227
$this->publishes([
2328
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
2429
]);
2530
}
31+
32+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'codebuddy');
2633
}
2734

28-
public function provides()
35+
/**
36+
* @return array<string>
37+
*/
38+
public function provides(): array
2939
{
3040
return [
3141
Configure::class,
42+
Review::class,
43+
Report::class,
3244
];
3345
}
34-
}
46+
}

src/Commands/Configure.php

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
7+
8+
use Illuminate\Support\Facades\File;
9+
use Illuminate\Support\Facades\Process;
10+
use function Laravel\Prompts\spin;
711
use function Termwind\render;
12+
use function Laravel\Prompts\info;
813

914
class Configure extends Command
1015
{
@@ -14,43 +19,54 @@ class Configure extends Command
1419

1520
public function handle(): void
1621
{
17-
$filesystem = new Filesystem();
22+
render(view('codebuddy::banner'));
1823

19-
$configs = [
20-
'rector.php',
21-
'phpstan.neon',
22-
'pint.json',
24+
$packages = [
25+
[
26+
'package_name' => 'driftingly/rector-laravel',
27+
'stub_file' => 'rector.php.stub',
28+
'config_file' => 'rector.php',
29+
'description' => 'Rector makes upgrading and maintaining code easier.',
30+
],
31+
[
32+
'package_name' => 'larastan/larastan',
33+
'stub_file' => 'phpstan.neon.stub',
34+
'config_file' => 'phpstan.neon',
35+
'description' => 'PHPStan helps detect errors at compile time instead of runtime.',
36+
],
37+
[
38+
'package_name' => 'laravel/pint',
39+
'stub_file' => 'pint.json.stub',
40+
'config_file' => 'pint.json',
41+
'description' => 'Pint ensures your code follows consistent formatting rules.',
42+
],
43+
[
44+
'package_name' => 'pestphp/pest',
45+
'stub_file' => 'phpunit.xml.stub',
46+
'config_file' => 'phpunit.xml',
47+
'description' => 'Elegant testing framework.',
48+
],
2349
];
2450

25-
foreach ($configs as $file) {
26-
$sourceFile = __DIR__ . "/../../config/laravel/{$file}";
27-
$destinationFile = base_path($file);
28-
29-
if (!$filesystem->exists($sourceFile)) {
30-
$this->error("Source file not found: {$sourceFile}");
31-
continue;
32-
}
33-
34-
if ($filesystem->exists($destinationFile)) {
35-
$overwrite = $this->confirmOverwrite($destinationFile);
36-
if (!$overwrite) {
37-
$this->warn("Skipped: {$destinationFile} already exists");
38-
continue;
39-
}
40-
}
41-
42-
$filesystem->copy($sourceFile, $destinationFile);
43-
$this->info("Copied: {$file} to project root");
44-
$this->newLine();
51+
foreach ($packages as $package) {
52+
$this->configurePackage($package);
4553
}
4654
}
4755

48-
private function confirmOverwrite(string $file): bool
56+
private function configurePackage(array $package): void
4957
{
50-
$this->info(
51-
sprintf('%s already exists. Do you want to overwrite it?', $file)
52-
);
53-
54-
return $this->ask('Overwrite?', false);
58+
spin(
59+
callback: function () use($package): void {
60+
sleep(1);
61+
$result = File::copy(
62+
__DIR__.'/../../stubs/' . $package['stub_file'],
63+
base_path($package['config_file'])
64+
);
65+
if (! $result) {
66+
self::fail(sprintf('❌ Failed to copy %s configuration file', $package['config_file']));
67+
}
68+
},
69+
message: sprintf('Configuring %s...', $package['package_name']));
70+
$this->info(sprintf('✅ %s configured successfully!', $package['package_name']));
5571
}
5672
}

0 commit comments

Comments
 (0)