From b75e240ec2091266dd635fa23ef03b6cdd8afe89 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 13:32:57 -0500 Subject: [PATCH 1/7] Automatically sync domains with forge --- app/Actions/ConfigureGroup.php | 13 +++-- app/Actions/SyncDomainsWithForge.php | 85 ++++++++++++++++++++++++++++ composer.json | 1 + composer.lock | 76 ++++++++++++++++++++++++- config/services.php | 6 ++ 5 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 app/Actions/SyncDomainsWithForge.php diff --git a/app/Actions/ConfigureGroup.php b/app/Actions/ConfigureGroup.php index 9efbb7b..9faf7df 100644 --- a/app/Actions/ConfigureGroup.php +++ b/app/Actions/ConfigureGroup.php @@ -24,6 +24,7 @@ public function handle( string $timezone = 'America/New_York', // One true timezone ?string $bsky_url = null, ?string $meetup_url = null, + ?string $og_asset = null, ): Group { $group = Group::updateOrCreate([ 'domain' => $domain, @@ -32,14 +33,15 @@ public function handle( 'region' => $region, 'description' => $description, 'timezone' => $timezone, - 'bsky_url' => $bsky_url - ?: null, - 'meetup_url' => $meetup_url - ?: null, + 'bsky_url' => $bsky_url ?: null, + 'meetup_url' => $meetup_url ?: null, + 'og_asset' => $og_asset ?: null, ]); Cache::clear(); + SyncDomainsWithForge::run(); + app()->instance("group:{$domain}", $group); return $group; @@ -71,6 +73,7 @@ public function asCommand(Command $command): int $timezone = suggest('Timezone', DateTimeZone::listIdentifiers(), default: str($existing->timezone), required: true); $bsky_url = text('Is there a Bluesky URL?', default: str($existing->bsky_url)); $meetup_url = text('Is there a Meetup URL?', default: str($existing->meetup_url)); + $og_asset = text('What is the open graph image name?', default: str($existing->og_asset)); table(['Option', 'Value'], [ ['Name', $name], @@ -78,6 +81,7 @@ public function asCommand(Command $command): int ['Timezone', $timezone], ['Bluesky', $bsky_url], ['Meetup', $meetup_url], + ['Open Graph Image', $og_asset], ]); if (confirm('Is this correct?')) { @@ -89,6 +93,7 @@ public function asCommand(Command $command): int timezone: $timezone, bsky_url: $bsky_url, meetup_url: $meetup_url, + og_asset: $og_asset, ); $command->info($group->wasRecentlyCreated diff --git a/app/Actions/SyncDomainsWithForge.php b/app/Actions/SyncDomainsWithForge.php new file mode 100644 index 0000000..2846c49 --- /dev/null +++ b/app/Actions/SyncDomainsWithForge.php @@ -0,0 +1,85 @@ +aliases()->values()->toArray(), + ); + } + + public function getCommandSignature(): string + { + return 'forge:sync-domains {--force}'; + } + + public function asCommand(Command $command): int + { + $changes = $this->aliases()->diff($this->site()->aliases); + + table( + headers: ['Domain', 'Status'], + rows: $this->aliases()->map(fn($alias) => [ + $alias, + $changes->contains($alias) ? 'Will be added' : 'Exists', + ]), + ); + + if ($command->option('force') || confirm('Save these changes?')) { + try { + $site = $this->handle(); + } catch (Throwable $exception) { + error($exception->getMessage()); + return 1; + } + + info('New aliases: '.implode(', ', $site->aliases)); + + return 0; + } + + return 1; + } + + protected function site(): Site + { + return $this->site ??= Forge::site( + serverId: config('services.forge.server'), + siteId: config('services.forge.site'), + ); + } + + protected function aliases(): Collection + { + return $this->aliases ??= Group::query()->pluck('domain') + ->merge($this->site()->aliases) + ->unique() + ->sort(); + } +} diff --git a/composer.json b/composer.json index 46cd9f1..35dd6d5 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.2", "glhd/bits": "^0.4.1", + "laravel/forge-sdk": "^3.19", "laravel/framework": "^11.0", "laravel/prompts": "^0.1.21", "laravel/tinker": "^2.9", diff --git a/composer.lock b/composer.lock index 7953ca4..54022e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fea8bed45ce6a65af6705b3ed0151cfb", + "content-hash": "4127c6778646641d30d9ba17827d4c55", "packages": [ { "name": "brick/math", @@ -1294,6 +1294,80 @@ ], "time": "2023-12-16T14:21:10+00:00" }, + { + "name": "laravel/forge-sdk", + "version": "v3.19.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/forge-sdk.git", + "reference": "1b7f1e9fce87fb045618019c43c5a4f730bfe7b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/forge-sdk/zipball/1b7f1e9fce87fb045618019c43c5a4f730bfe7b9", + "reference": "1b7f1e9fce87fb045618019c43c5a4f730bfe7b9", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^6.3.1|^7.0", + "php": "^7.2|^8.0" + }, + "require-dev": { + "illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0", + "mockery/mockery": "^1.3.1", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.4|^9.0|^10.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Forge\\ForgeServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Forge\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + }, + { + "name": "Mohamed Said", + "email": "mohamed@laravel.com" + }, + { + "name": "Dries Vints", + "email": "dries@laravel.com" + }, + { + "name": "James Brooks", + "email": "james@laravel.com" + } + ], + "description": "The official Laravel Forge PHP SDK.", + "keywords": [ + "forge", + "laravel" + ], + "support": { + "issues": "https://github.com/laravel/forge-sdk/issues", + "source": "https://github.com/laravel/forge-sdk" + }, + "time": "2024-11-12T12:22:14+00:00" + }, { "name": "laravel/framework", "version": "v11.30.0", diff --git a/config/services.php b/config/services.php index 6bb68f6..4183d3d 100644 --- a/config/services.php +++ b/config/services.php @@ -30,5 +30,11 @@ 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), ], ], + + 'forge' => [ + 'token' => env('FORGE_TOKEN'), + 'server' => env('FORGE_SERVER_ID'), + 'site' => env('FORGE_SITE_ID'), + ], ]; From b0a494ffb112030ef0cfd36624076d77fe423fe3 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:18:24 -0500 Subject: [PATCH 2/7] Create .gitkeep --- tests/Unit/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/Unit/.gitkeep diff --git a/tests/Unit/.gitkeep b/tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 From d9e7bc792e15dd2426cad1242f44d5cd6539e7b0 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:22:21 -0500 Subject: [PATCH 3/7] Update phpunit.xml --- phpunit.xml | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index f685809..312f332 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,31 +4,31 @@ bootstrap="vendor/autoload.php" colors="true" > - - - tests/Unit - - - tests/Feature - - - - - app - - - - - - - - - - - - - - - - + + + tests/Unit + + + tests/Feature + + + + + app + + + + + + + + + + + + + + + + From 4fbab973ca3d3ebc0249303d8dc77ccc164d3eff Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:23:51 -0500 Subject: [PATCH 4/7] Update phpunit.xml --- phpunit.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 312f332..12a245a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,17 +18,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + From d9b0a8a5f8964c290c6018c9a39914c4b38bab3c Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:25:29 -0500 Subject: [PATCH 5/7] ugh --- tests/TestCase.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 0cf3787..05930c9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,4 +15,10 @@ public function seedDefaultGroups(): void $this->afterApplicationCreated(fn() => $this->seed(GroupSeeder::class)); } } + + #[Before] + public function disableVite(): void + { + $this->withoutVite(); + } } From c84c98e35e98e19c740e2ea472690f7a0a3bce04 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:27:29 -0500 Subject: [PATCH 6/7] Update TestCase.php --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 05930c9..621a20a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,6 +19,6 @@ public function seedDefaultGroups(): void #[Before] public function disableVite(): void { - $this->withoutVite(); + $this->afterApplicationCreated(fn() => $this->withoutVite()); } } From 74e6ffa4674e080e954097ce5b151f6092d805ae Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 14 Nov 2024 16:29:21 -0500 Subject: [PATCH 7/7] Only run on pushes to main --- .github/workflows/phpunit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index d8da53d..5266c69 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -2,6 +2,8 @@ name: PHPUnit on: push: + branches: + - main pull_request: jobs: