Skip to content

Commit 690a38a

Browse files
fix: php sdk publishing workflow - set version before install (#726)
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 29c1e6b commit 690a38a

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ jobs:
2626
coverage: none
2727
tools: composer:v2
2828

29+
- name: Ensure valid version exists in SDK
30+
run: |
31+
# Check if version is empty or invalid
32+
VERSION=$(php -r '
33+
$composerJson = json_decode(file_get_contents("php/sdk/composer.json"), true);
34+
echo isset($composerJson["version"]) ? $composerJson["version"] : "";
35+
')
36+
37+
if [[ -z "$VERSION" || ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
38+
echo "Setting initial version to 0.1.0"
39+
php -r '
40+
$composerJson = json_decode(file_get_contents("php/sdk/composer.json"), true);
41+
$composerJson["version"] = "0.1.0";
42+
file_put_contents("php/sdk/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
43+
'
44+
fi
45+
2946
- name: Install dependencies for SDK
3047
working-directory: ./php/sdk
3148
run: composer install --prefer-dist
@@ -57,25 +74,7 @@ jobs:
5774
coverage: none
5875
tools: composer:v2
5976

60-
- name: Ensure valid version exists in SDK
61-
run: |
62-
# Check if version is empty or invalid
63-
VERSION=$(php -r '
64-
$composerJson = json_decode(file_get_contents("php/sdk/composer.json"), true);
65-
echo isset($composerJson["version"]) ? $composerJson["version"] : "";
66-
')
67-
68-
if [[ -z "$VERSION" || ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
69-
echo "Setting initial version to 0.1.0"
70-
php -r '
71-
$composerJson = json_decode(file_get_contents("php/sdk/composer.json"), true);
72-
$composerJson["version"] = "0.1.0";
73-
file_put_contents("php/sdk/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
74-
'
75-
VERSION="0.1.0"
76-
fi
77-
78-
echo "Initial version: $VERSION"
77+
7978

8079
- name: Get current version
8180
id: current_version
@@ -92,9 +91,18 @@ jobs:
9291
# Get current version
9392
CURRENT_VERSION=${{ steps.current_version.outputs.version }}
9493
94+
# Validate current version format
95+
if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
96+
echo "Warning: Invalid version format: $CURRENT_VERSION. Using 0.1.0 as base."
97+
CURRENT_VERSION="0.1.0"
98+
fi
99+
95100
# Use PHP to increment patch version
96101
NEW_VERSION=$(php -r '
97102
$version = "${{ steps.current_version.outputs.version }}";
103+
if (!preg_match("/^[0-9]+\.[0-9]+\.[0-9]+$/", $version)) {
104+
$version = "0.1.0";
105+
}
98106
list($major, $minor, $patch) = explode(".", $version);
99107
$patch++;
100108
echo "$major.$minor.$patch";
@@ -126,6 +134,10 @@ jobs:
126134

127135
- name: Publish to Packagist
128136
run: |
137+
# Debug info
138+
echo "Publishing version ${{ steps.bump_version.outputs.new_version }} to Packagist"
139+
echo "Repository: lingodotdev/sdk"
140+
129141
# Use our custom script for reliable Packagist publishing
130142
export PACKAGIST_USERNAME=lingodotdev
131143
export PACKAGIST_API_TOKEN=${{ secrets.PACKAGIST_API_TOKEN }}

php/sdk/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lingodotdev/sdk",
33
"description": "Official PHP SDK for Lingo.dev",
4-
"version": "",
4+
"version": "0.1.0",
55
"type": "library",
66
"license": "MIT",
77
"autoload": {
@@ -28,4 +28,4 @@
2828
"cs": "phpcs src/ tests/",
2929
"cs-fix": "phpcbf src/ tests/"
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)