Skip to content

Commit 7273b57

Browse files
fix: implement direct Packagist publishing with custom script (#693)
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 a43e51c commit 7273b57

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

.github/workflows/publish-php-sdk.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ jobs:
8888
push_options: "--force"
8989

9090
- name: Publish to Packagist
91-
uses: wscourge/gha-packagist-publish@v1.0
92-
with:
93-
username: lingodotdev
94-
api_token: ${{ secrets.PACKAGIST_API_TOKEN }}
95-
package_name: lingodotdev/sdk
91+
run: |
92+
# Use our custom script for reliable Packagist publishing
93+
export PACKAGIST_USERNAME=lingodotdev
94+
export PACKAGIST_API_TOKEN=${{ secrets.PACKAGIST_API_TOKEN }}
95+
export PACKAGE_NAME=lingodotdev/sdk
96+
php scripts/packagist-publish.php

scripts/packagist-publish.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Packagist Publishing Script
4+
*
5+
* This script handles publishing a package to Packagist using the Packagist API.
6+
* It requires the following environment variables:
7+
* - PACKAGIST_USERNAME: The Packagist username
8+
* - PACKAGIST_API_TOKEN: The Packagist API token
9+
* - PACKAGE_NAME: The name of the package to publish (e.g., vendor/package)
10+
*
11+
* @php 7.4
12+
*/
13+
14+
$username = getenv('PACKAGIST_USERNAME');
15+
$apiToken = getenv('PACKAGIST_API_TOKEN');
16+
$packageName = getenv('PACKAGE_NAME');
17+
18+
if (!$username || !$apiToken || !$packageName) {
19+
echo "Error: Missing required environment variables.\n";
20+
echo "Please ensure PACKAGIST_USERNAME, PACKAGIST_API_TOKEN, and PACKAGE_NAME are set.\n";
21+
exit(1);
22+
}
23+
24+
echo "Starting Packagist publishing process for package: $packageName\n";
25+
26+
$apiUrl = "https://packagist.org/api/update-package?username=$username&apiToken=$apiToken";
27+
28+
$data = [
29+
'repository' => [
30+
'url' => "https://github.com/lingodotdev/lingo.dev"
31+
]
32+
];
33+
34+
$ch = curl_init($apiUrl);
35+
36+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
37+
curl_setopt($ch, CURLOPT_POST, true);
38+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
39+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
40+
'Content-Type: application/json',
41+
'Accept: application/json'
42+
]);
43+
44+
echo "Sending request to Packagist API...\n";
45+
$response = curl_exec($ch);
46+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
47+
48+
if (curl_errno($ch)) {
49+
echo "Error: " . curl_error($ch) . "\n";
50+
curl_close($ch);
51+
exit(1);
52+
}
53+
54+
curl_close($ch);
55+
56+
$responseData = json_decode($response, true);
57+
58+
echo "HTTP Response Code: $httpCode\n";
59+
echo "Response: " . print_r($responseData, true) . "\n";
60+
61+
if ($httpCode >= 200 && $httpCode < 300) {
62+
echo "Package $packageName successfully published to Packagist!\n";
63+
exit(0);
64+
} else {
65+
echo "Failed to publish package $packageName to Packagist.\n";
66+
exit(1);
67+
}

0 commit comments

Comments
 (0)