Skip to content

Commit 368f484

Browse files
committed
chore: #4 add ci step
1 parent cff95f9 commit 368f484

File tree

182 files changed

+1136
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+1136
-727
lines changed

Diff for: .github/workflows/test.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Code Quality
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
env:
9+
HUSKY: 0
10+
BROADCAST_DRIVER: log
11+
CACHE_DRIVER: redis
12+
QUEUE_CONNECTION: redis
13+
SESSION_DRIVER: redis
14+
DB_CONNECTION: pgsql
15+
DB_HOST: localhost
16+
DB_PASSWORD: postgres
17+
DB_USERNAME: postgres
18+
DB_DATABASE: postgres
19+
20+
# Docs: https://docs.github.com/en/actions/using-containerized-services
21+
services:
22+
postgres:
23+
image: postgres:latest
24+
env:
25+
POSTGRES_USER: postgres
26+
POSTGRES_PASSWORD: postgres
27+
POSTGRES_DB: postgres
28+
ports:
29+
- 5432/tcp
30+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
31+
32+
redis:
33+
image: redis
34+
ports:
35+
- 6379/tcp
36+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- uses: shivammathur/setup-php@v2
42+
with:
43+
php-version: '8.3'
44+
extensions: pdo pdo_pgsql pgsql bcmath
45+
coverage: xdebug
46+
47+
- name: Get composer cache directory
48+
id: composer-cache
49+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
50+
51+
- name: Cache composer dependencies
52+
uses: actions/cache@v4
53+
with:
54+
path: ${{ steps.composer-cache.outputs.dir }}
55+
# Use composer.json for key, if composer.lock is not committed.
56+
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
57+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
58+
restore-keys: ${{ runner.os }}-composer-
59+
60+
- name: Install Composer dependencies
61+
run: composer install --no-progress --prefer-dist --optimize-autoloader
62+
63+
- uses: actions/setup-node@v4
64+
with:
65+
node-version-file: '.nvmrc'
66+
cache: 'npm'
67+
68+
- name: Install Node dependencies
69+
run: npm i --frozen-lockfile
70+
71+
- name: Build JS
72+
run: npm run build
73+
74+
- name: Prepare the application
75+
run: |
76+
php -r "file_exists('.env') || copy('.env.example', '.env');"
77+
php artisan key:generate
78+
79+
- name: Clear Config
80+
run: php artisan config:clear
81+
82+
- name: Run Migration
83+
run: php artisan migrate -v
84+
env:
85+
DB_PORT: ${{ job.services.postgres.ports[5432] }}
86+
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
87+
88+
- name: Test with pest
89+
run: php artisan test --coverage-text
90+
env:
91+
DB_PORT: ${{ job.services.postgres.ports[5432] }}
92+
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
93+
94+
- name: Pint!
95+
run: vendor/bin/pint --test

Diff for: .husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lint-staged

Diff for: .nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.x

Diff for: api-nodes/Http/Controllers/EventController.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use ApiNodes\Models\AgentStartedEventData;
66
use App\Models\Node;
7-
use App\Models\NodeData;
8-
use Illuminate\Http\Request;
97
use Illuminate\Support\Facades\DB;
10-
use Illuminate\Support\Facades\Log;
118

129
class EventController
1310
{
@@ -29,8 +26,8 @@ public function started(Node $node, AgentStartedEventData $data)
2926

3027
return [
3128
'settings' => [
32-
'poll_interval' => 5
33-
]
29+
'poll_interval' => 5,
30+
],
3431
];
3532
}
36-
}
33+
}

Diff for: api-nodes/Http/Controllers/NextTaskController.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace ApiNodes\Http\Controllers;
44

55
use App\Models\Node;
6-
use App\Models\NodeTasks\TaskStatus;
76
use App\Models\NodeTaskGroup;
87
use Illuminate\Database\Eloquent\Builder;
98
use Illuminate\Http\Response;
@@ -14,7 +13,7 @@ public function __invoke(Node $node)
1413
{
1514
if ($node->swarm_id === null) {
1615
return new Response([
17-
'message' => 'No task found.'
16+
'message' => 'No task found.',
1817
], 204);
1918
}
2019

@@ -29,20 +28,20 @@ public function __invoke(Node $node)
2928
return $task->only([
3029
'id',
3130
'type',
32-
'payload'
31+
'payload',
3332
]);
3433
}
3534

3635
return new Response([
37-
'message' => 'No task found.'
36+
'message' => 'No task found.',
3837
], 204);
3938
}
4039

4140
protected function getNextTaskFromGroup(Node $node, NodeTaskGroup $taskGroup)
4241
{
4342
if ($taskGroup->tasks()->running()->first()) {
4443
return new Response([
45-
'error_message' => 'Another task should be already running.'
44+
'error_message' => 'Another task should be already running.',
4645
], 409);
4746
}
4847

@@ -63,7 +62,7 @@ protected function pickNextTask(Node $node)
6362
return $query->where('node_id', $node->id)->orWhere('node_id', null);
6463
})->pending()->first();
6564

66-
if (!$taskGroup) {
65+
if (! $taskGroup) {
6766
return null;
6867
}
6968

@@ -73,4 +72,4 @@ protected function pickNextTask(Node $node)
7372

7473
return $task;
7574
}
76-
}
75+
}

Diff for: api-nodes/Http/Controllers/TaskController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public function fail(NodeTask $task, Request $request)
4444

4545
return new Response('', 204);
4646
}
47-
}
47+
}

Diff for: api-nodes/Http/Middleware/AgentTokenAuth.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace ApiNodes\Http\Middleware;
44

55
use App\Models\Node;
6-
use App\Models\NodeTasks;
76
use App\Models\Scopes\TeamScope;
87
use App\Models\Team;
98
use Closure;
@@ -23,13 +22,13 @@ public function handle(Request $request, Closure $next): Response
2322
{
2423
$token = $request->header(self::AUTH_HEADER);
2524

26-
if (!$token) {
25+
if (! $token) {
2726
if ($request->bearerToken()) {
2827
return $next($request);
2928
}
3029

3130
return response()->json([
32-
'message' => 'Unauthorized'
31+
'message' => 'Unauthorized',
3332
], 403);
3433
}
3534

@@ -39,8 +38,8 @@ public function handle(Request $request, Closure $next): Response
3938

4039
$node->save();
4140

42-
app()->singleton(Node::class, fn() => $node);
43-
app()->singleton(Team::class, fn() => $node->team);
41+
app()->singleton(Node::class, fn () => $node);
42+
app()->singleton(Team::class, fn () => $node->team);
4443

4544
return $next($request);
4645
}

Diff for: api-nodes/Models/AgentStartedEventData.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,5 @@ class AgentStartedEventData extends Data
1111
public function __construct(
1212
public NodeData $node,
1313
public ?SwarmData $swarm,
14-
)
15-
{
16-
17-
}
14+
) {}
1815
}

Diff for: api-nodes/Models/AgentStartedEventData/SwarmData.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@ public function __construct(
1414
#[DataCollectionOf(ManagerNode::class)]
1515
/* @var ManagerNode[] */
1616
public array $managerNodes,
17-
)
18-
{
19-
20-
}
21-
}
17+
) {}
18+
}

Diff for: app/Actions/Jetstream/AddTeamMember.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AddTeamMember implements AddsTeamMembers
1818
/**
1919
* Add a new team member to the given team.
2020
*/
21-
public function add(User $user, Team $team, string $email, string $role = null): void
21+
public function add(User $user, Team $team, string $email, ?string $role = null): void
2222
{
2323
Gate::forUser($user)->authorize('addTeamMember', $team);
2424

Diff for: app/Actions/Jetstream/DeleteUser.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class DeleteUser implements DeletesUsers
1313
/**
1414
* Create a new action instance.
1515
*/
16-
public function __construct(protected DeletesTeams $deletesTeams)
17-
{
18-
}
16+
public function __construct(protected DeletesTeams $deletesTeams) {}
1917

2018
/**
2119
* Delete the given user.

Diff for: app/Actions/Jetstream/InviteTeamMember.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class InviteTeamMember implements InvitesTeamMembers
2121
/**
2222
* Invite a new team member to the given team.
2323
*/
24-
public function invite(User $user, Team $team, string $email, string $role = null): void
24+
public function invite(User $user, Team $team, string $email, ?string $role = null): void
2525
{
2626
Gate::forUser($user)->authorize('addTeamMember', $team);
2727

Diff for: app/Api/Controllers/Controller.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
namespace App\Api\Controllers;
44

5-
class Controller
6-
{
7-
8-
}
5+
class Controller {}

Diff for: app/Api/Controllers/ServiceController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Api\Controllers;
44

5-
use App\Models\DeploymentData;
65
use App\Models\Service;
76
use Illuminate\Http\Request;
87
use Illuminate\Support\Facades\DB;
@@ -21,4 +20,4 @@ public function deploy(Service $service, Request $request): array
2120
'deployment_id' => $deployment->id,
2221
];
2322
}
24-
}
23+
}

Diff for: app/Console/Commands/DispatchProcessBackupTask.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function dispatchBackupTask(): void
6767
]);
6868

6969
$date = now()->format('Y-m-d_His');
70-
$backupFileName = dockerize_name("svc-{$service->id}-{$process->name}_backup-{$backupCmd->name}-{$date}") . '.tar.gz';
70+
$backupFileName = dockerize_name("svc-{$service->id}-{$process->name}_backup-{$backupCmd->name}-{$date}").'.tar.gz';
7171
$archivePath = "{$process->backupVolume->path}/$backupFileName";
7272
$backupCommand = "mkdir -p /tmp/{$backupCmd->id} && cd /tmp/{$backupCmd->id} && {$backupCmd->command} && tar czfv $archivePath -C /tmp/{$backupCmd->id} . && rm -rf /tmp/{$backupCmd->id}";
7373

@@ -89,8 +89,8 @@ protected function dispatchBackupTask(): void
8989
'AttachStdout' => true,
9090
'AttachStderr' => true,
9191
'Cmd' => ['sh', '-c', $backupCommand],
92-
]
93-
]
92+
],
93+
],
9494
],
9595
[
9696
'type' => NodeTaskType::UploadS3File,
@@ -105,9 +105,9 @@ protected function dispatchBackupTask(): void
105105
'Target' => $process->backupVolume->path,
106106
],
107107
'SrcFilePath' => $archivePath,
108-
'DestFilePath' => $s3Storage->pathPrefix . '/' . $backupFileName,
108+
'DestFilePath' => $s3Storage->pathPrefix.'/'.$backupFileName,
109109
],
110-
]
110+
],
111111
]);
112112
}
113113
}

Diff for: app/Console/Commands/DispatchVolumeBackupTask.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function dispatchBackupTask(): void
6767
]);
6868

6969
$date = now()->format('Y-m-d_His');
70-
$backupFileName = dockerize_name("svc-{$service->id}-{$process->name}-vol-{$volume->name}-{$date}") . '.tar.gz';
70+
$backupFileName = dockerize_name("svc-{$service->id}-{$process->name}-vol-{$volume->name}-{$date}").'.tar.gz';
7171
$archivePath = "{$process->backupVolume->path}/$backupFileName";
7272
$backupCommand = "tar czfv $archivePath -C {$volume->path} .";
7373

@@ -90,8 +90,8 @@ protected function dispatchBackupTask(): void
9090
'AttachStdout' => true,
9191
'AttachStderr' => true,
9292
'Cmd' => ['sh', '-c', $backupCommand],
93-
]
94-
]
93+
],
94+
],
9595
],
9696
[
9797
'type' => NodeTaskType::UploadS3File,
@@ -106,9 +106,9 @@ protected function dispatchBackupTask(): void
106106
'Target' => $process->backupVolume->path,
107107
],
108108
'SrcFilePath' => $archivePath,
109-
'DestFilePath' => $s3Storage->pathPrefix . '/' . $backupFileName,
109+
'DestFilePath' => $s3Storage->pathPrefix.'/'.$backupFileName,
110110
],
111-
]
111+
],
112112
]);
113113
}
114114
}

Diff for: app/Console/Commands/MakeNodeTask.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class MakeNodeTask extends Command
1717
/**
1818
* The console command description.
1919
*34
20+
*
2021
* @var string
2122
*/
2223
protected $description = 'Create a new node task';
@@ -52,15 +53,15 @@ public function handle(): void
5253
foreach ($dirs as $dir) {
5354
$path = app_path($dir);
5455

55-
$this->info('Creating directory ' . $dir);
56+
$this->info('Creating directory '.$dir);
5657

5758
mkdir($path);
5859
}
5960

6061
foreach ($taskDataFiles as $abstractPath => $template) {
6162
$path = app_path($abstractPath);
6263

63-
$this->info('Writing ' . $abstractPath);
64+
$this->info('Writing '.$abstractPath);
6465

6566
file_put_contents($path, $template);
6667
}
@@ -70,7 +71,7 @@ public function handle(): void
7071

7172
protected function readStub($type, $taskName): string
7273
{
73-
$template = file_get_contents(__DIR__ . "/stubs/MakeNodeTask/$type.stub");
74+
$template = file_get_contents(__DIR__."/stubs/MakeNodeTask/$type.stub");
7475

7576
return str_replace('$taskName', $taskName, $template);
7677
}

0 commit comments

Comments
 (0)