Skip to content

Commit 19fa019

Browse files
committed
feat: bundle GPG signature & project uuid
1 parent 6d0ddc3 commit 19fa019

File tree

3 files changed

+79
-16
lines changed

3 files changed

+79
-16
lines changed

src/Electron/Commands/Bifrost/ClearBundleCommand.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,45 @@ public function handle(): int
2020
intro('Clearing downloaded bundle...');
2121

2222
$bundlePath = base_path('build/__nativephp_app_bundle');
23+
$signaturePath = $bundlePath . '.asc';
2324

24-
if (! file_exists($bundlePath)) {
25-
$this->warn('No bundle found to clear.');
25+
$bundleExists = file_exists($bundlePath);
26+
$signatureExists = file_exists($signaturePath);
27+
28+
if (! $bundleExists && ! $signatureExists) {
29+
$this->warn('No bundle or signature files found to clear.');
2630

2731
return static::SUCCESS;
2832
}
2933

30-
if (unlink($bundlePath)) {
31-
$this->info('Bundle cleared successfully!');
34+
$cleared = [];
35+
$failed = [];
36+
37+
if ($bundleExists) {
38+
if (unlink($bundlePath)) {
39+
$cleared[] = 'bundle';
40+
} else {
41+
$failed[] = 'bundle';
42+
}
43+
}
44+
45+
if ($signatureExists) {
46+
if (unlink($signaturePath)) {
47+
$cleared[] = 'GPG signature';
48+
} else {
49+
$failed[] = 'GPG signature';
50+
}
51+
}
52+
53+
if (! empty($cleared)) {
54+
$clearedText = implode(' and ', $cleared);
55+
$this->info("Cleared {$clearedText} successfully!");
3256
$this->line('Note: Building in this state would be unsecure without a valid bundle.');
33-
} else {
34-
$this->error('Failed to remove bundle file.');
57+
}
58+
59+
if (! empty($failed)) {
60+
$failedText = implode(' and ', $failed);
61+
$this->error("Failed to remove {$failedText}.");
3562

3663
return static::FAILURE;
3764
}

src/Electron/Commands/Bifrost/DownloadBundleCommand.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,30 @@ public function handle(): int
5050

5151
$buildData = $response->json();
5252

53-
if (! isset($buildData['download_url'])) {
53+
if (! isset($buildData['data']['download_url'])) {
5454
$this->error('Bundle download URL not found in response.');
5555

5656
return static::FAILURE;
5757
}
5858

59-
$this->displayBundleInfo($buildData);
59+
$this->displayBundleInfo($buildData['data']);
6060

6161
$bundlePath = $this->prepareBundlePath();
6262

63-
if (! $this->downloadBundle($buildData['download_url'], $bundlePath)) {
63+
if (! $this->downloadBundle($buildData['data']['download_url'], $bundlePath)) {
6464
return static::FAILURE;
6565
}
6666

67-
$this->displaySuccessInfo($bundlePath);
67+
// Download GPG signature if available
68+
$signaturePath = null;
69+
if (isset($buildData['data']['signature_url'])) {
70+
$signaturePath = $bundlePath . '.asc';
71+
if (! $this->downloadSignature($buildData['data']['signature_url'], $signaturePath)) {
72+
$this->warn('Failed to download GPG signature file.');
73+
}
74+
}
75+
76+
$this->displaySuccessInfo($bundlePath, $signaturePath);
6877

6978
return static::SUCCESS;
7079
} catch (Exception $e) {
@@ -143,7 +152,27 @@ private function cleanupFailedDownload(string $bundlePath): void
143152
}
144153
}
145154

146-
private function displaySuccessInfo(string $bundlePath): void
155+
private function downloadSignature(string $signatureUrl, string $signaturePath): bool
156+
{
157+
$this->line('');
158+
$this->info('Downloading GPG signature...');
159+
160+
try {
161+
$downloadResponse = Http::get($signatureUrl);
162+
163+
if ($downloadResponse->failed()) {
164+
return false;
165+
}
166+
167+
file_put_contents($signaturePath, $downloadResponse->body());
168+
169+
return true;
170+
} catch (Exception $e) {
171+
return false;
172+
}
173+
}
174+
175+
private function displaySuccessInfo(string $bundlePath, ?string $signaturePath = null): void
147176
{
148177
$this->line('');
149178
$this->info('Bundle downloaded successfully!');
@@ -153,6 +182,13 @@ private function displaySuccessInfo(string $bundlePath): void
153182
$sizeInMB = number_format(filesize($bundlePath) / 1024 / 1024, 2);
154183
$this->line("Size: {$sizeInMB} MB");
155184
}
185+
186+
if ($signaturePath && file_exists($signaturePath)) {
187+
$this->line('GPG Signature: '.$signaturePath);
188+
$this->line('');
189+
$this->info('To verify the bundle integrity:');
190+
$this->line('gpg --verify '.basename($signaturePath).' '.basename($bundlePath));
191+
}
156192
}
157193

158194
private function handleApiError($response): void

src/Electron/Commands/Bifrost/InitCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ public function handle(): int
6767
$name = $project['name'] ?? 'Unknown';
6868
$repo = $project['repo'] ?? 'No repository';
6969

70-
return [$project['id'] => "{$name} - {$repo}"];
70+
return [$project['uuid'] => "{$name} - {$repo}"];
7171
})->toArray();
7272

73-
$selectedProjectId = select(
73+
$selectedProjectUuid = select(
7474
label: 'Select a desktop project',
7575
options: $choices,
7676
required: true
7777
);
7878

79-
$selectedProject = collect($projects)->firstWhere('id', $selectedProjectId);
79+
$selectedProject = collect($projects)->firstWhere('uuid', $selectedProjectUuid);
8080

8181
if (! $selectedProject) {
8282
$this->error('Selected project not found.');
8383

8484
return static::FAILURE;
8585
}
8686

87-
// Store project in .env file
88-
$this->updateEnvFile('BIFROST_PROJECT', $selectedProjectId);
87+
// Store project UUID in .env file
88+
$this->updateEnvFile('BIFROST_PROJECT', $selectedProjectUuid);
8989

9090
$this->displaySuccessMessage($selectedProject);
9191

0 commit comments

Comments
 (0)