Skip to content

Commit 6476a23

Browse files
fix: update packagist publishing script to handle new package registration (#698)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Max Prilutskiy <maks.prilutskiy@gmail.com>
1 parent ca03aa1 commit 6476a23

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

scripts/packagist-publish.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@
2323

2424
echo "Starting Packagist publishing process for package: $packageName\n";
2525

26-
$apiUrl = "https://packagist.org/api/update-package?username=$username&apiToken=$apiToken";
26+
$checkUrl = "https://packagist.org/packages/$packageName.json";
27+
$ch = curl_init($checkUrl);
28+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
30+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
31+
'Accept: application/json'
32+
]);
33+
34+
echo "Checking if package exists on Packagist...\n";
35+
$response = curl_exec($ch);
36+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
37+
curl_close($ch);
38+
39+
$packageExists = ($httpCode === 200);
40+
41+
if ($packageExists) {
42+
echo "Package $packageName already exists on Packagist. Updating...\n";
43+
$apiUrl = "https://packagist.org/api/update-package?username=$username&apiToken=$apiToken";
44+
} else {
45+
echo "Package $packageName does not exist on Packagist. Submitting new package...\n";
46+
$apiUrl = "https://packagist.org/api/submit?username=$username&apiToken=$apiToken";
47+
}
48+
49+
$repoUrl = "https://github.com/lingodotdev/lingo.dev";
2750

2851
$data = [
2952
'repository' => [
30-
'url' => "https://github.com/lingodotdev/lingo.dev"
53+
'url' => $repoUrl
3154
]
3255
];
3356

@@ -41,7 +64,7 @@
4164
'Accept: application/json'
4265
]);
4366

44-
echo "Sending request to Packagist API...\n";
67+
echo "Sending request to Packagist API ($apiUrl)...\n";
4568
$response = curl_exec($ch);
4669
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
4770

@@ -59,9 +82,9 @@
5982
echo "Response: " . print_r($responseData, true) . "\n";
6083

6184
if ($httpCode >= 200 && $httpCode < 300) {
62-
echo "Package $packageName successfully published to Packagist!\n";
85+
echo "Package $packageName successfully " . ($packageExists ? "updated" : "submitted") . " to Packagist!\n";
6386
exit(0);
6487
} else {
65-
echo "Failed to publish package $packageName to Packagist.\n";
88+
echo "Failed to " . ($packageExists ? "update" : "submit") . " package $packageName to Packagist.\n";
6689
exit(1);
6790
}

0 commit comments

Comments
 (0)