Skip to content

Commit cf6738d

Browse files
committed
create workflow
1 parent ef79b22 commit cf6738d

File tree

8 files changed

+169
-8
lines changed

8 files changed

+169
-8
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

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
}
1717
},
1818
"scripts": {
19+
"lint": "XDEBUG_MODE=off pint --test",
20+
"lint.fix": "XDEBUG_MODE=off pint",
21+
"stan": "XDEBUG_MODE=off phpstan analyse --ansi --memory-limit=-1",
22+
"test.arch": "XDEBUG_MODE=off pest --testsuite=Architecture",
23+
"test.unit": "XDEBUG_MODE=off pest --testsuite=Unit",
24+
"test.feature": "XDEBUG_MODE=coverage pest --testsuite=Feature --coverage --min=90",
25+
"rector": "XDEBUG_MODE=off rector process --dry-run",
26+
"rector.fix": "XDEBUG_MODE=off rector process",
27+
"ci": [
28+
"@lint",
29+
"@rector"
30+
],
31+
"ci.fix": [
32+
"@rector.fix",
33+
"@lint.fix"
34+
]
1935
},
2036
"extra": {
2137
"laravel": {

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>
2+
<div class="px-1 bg-green-600">CodeBuddy</div>
3+
<em class="ml-1">
4+
All-in-one tool for your codebase quality
5+
</em>
6+
</div>

src/CodebuddyServiceProvider.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Codebuddyphp\Codebuddy;
44

5+
use Codebuddyphp\Codebuddy\Commands\Ci;
56
use Codebuddyphp\Codebuddy\Commands\Configure;
67
use Illuminate\Support\ServiceProvider;
78

@@ -17,18 +18,25 @@ public function boot()
1718
if ($this->app->runningInConsole()) {
1819
$this->commands([
1920
Configure::class,
21+
Ci::class,
2022
]);
2123

2224
$this->publishes([
2325
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
2426
]);
2527
}
28+
29+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'codebuddy');
2630
}
2731

28-
public function provides()
32+
/**
33+
* @return array<string>
34+
*/
35+
public function provides(): array
2936
{
3037
return [
3138
Configure::class,
39+
Ci::class,
3240
];
3341
}
34-
}
42+
}

src/Commands/Ci.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Codebuddyphp\Codebuddy\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Filesystem\Filesystem;
7+
8+
use function Termwind\render;
9+
10+
class Ci extends Command
11+
{
12+
protected $signature = 'codebuddy:ci';
13+
14+
protected $description = 'Run ci checks';
15+
16+
public function handle(): void
17+
{
18+
$checks = [
19+
'vendor/bin/pint --test',
20+
'vendor/bin/rector --dry-run',
21+
'vendor/bin/phpstan analyse',
22+
];
23+
24+
// @phpstan-ignore-next-line
25+
render(view('codebuddy::banner'));
26+
27+
$this->info('Running CI checks...');
28+
$this->newLine();
29+
30+
$failed = false;
31+
32+
foreach ($checks as $check) {
33+
$this->info("Running: $check");
34+
$process = proc_open($check, [
35+
0 => ['pipe', 'r'],
36+
1 => ['pipe', 'w'],
37+
2 => ['pipe', 'w'],
38+
], $pipes);
39+
40+
$output = stream_get_contents($pipes[1]);
41+
$errors = stream_get_contents($pipes[2]);
42+
fclose($pipes[0]);
43+
fclose($pipes[1]);
44+
fclose($pipes[2]);
45+
46+
$exitCode = proc_close($process);
47+
48+
if ($exitCode !== 0) {
49+
$this->error("Failed: $check");
50+
$this->line($output);
51+
$this->error($errors);
52+
$failed = true;
53+
} else {
54+
$this->info("Passed: $check");
55+
}
56+
57+
$this->newLine();
58+
}
59+
60+
if ($failed) {
61+
$this->error('CI checks failed.');
62+
exit(1);
63+
} else {
64+
$this->info('All CI checks passed successfully!');
65+
}
66+
}
67+
}

src/Commands/Configure.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
7+
78
use function Termwind\render;
89

910
class Configure extends Command
@@ -14,33 +15,37 @@ class Configure extends Command
1415

1516
public function handle(): void
1617
{
17-
$filesystem = new Filesystem();
18+
$filesystem = new Filesystem;
1819

1920
$configs = [
2021
'rector.php',
2122
'phpstan.neon',
2223
'pint.json',
2324
];
2425

26+
render(view('codebuddy::banner'));
27+
2528
foreach ($configs as $file) {
26-
$sourceFile = __DIR__ . "/../../config/laravel/{$file}";
29+
$sourceFile = __DIR__."/../../config/laravel/{$file}";
2730
$destinationFile = base_path($file);
2831

29-
if (!$filesystem->exists($sourceFile)) {
32+
if (! $filesystem->exists($sourceFile)) {
3033
$this->error("Source file not found: {$sourceFile}");
34+
3135
continue;
3236
}
3337

3438
if ($filesystem->exists($destinationFile)) {
3539
$overwrite = $this->confirmOverwrite($destinationFile);
36-
if (!$overwrite) {
40+
if (! $overwrite) {
3741
$this->warn("Skipped: {$destinationFile} already exists");
42+
3843
continue;
3944
}
4045
}
4146

4247
$filesystem->copy($sourceFile, $destinationFile);
43-
$this->info("Copied: {$file} to project root");
48+
$this->info("Created: {$file} in project root");
4449
$this->newLine();
4550
}
4651
}
@@ -51,6 +56,6 @@ private function confirmOverwrite(string $file): bool
5156
sprintf('%s already exists. Do you want to overwrite it?', $file)
5257
);
5358

54-
return $this->ask('Overwrite?', false);
59+
return $this->confirm('Overwrite?', true);
5560
}
5661
}

0 commit comments

Comments
 (0)