|
26 | 26 | coverage: none |
27 | 27 | tools: composer:v2 |
28 | 28 |
|
| 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 | +
|
29 | 46 | - name: Install dependencies for SDK |
30 | 47 | working-directory: ./php/sdk |
31 | 48 | run: composer install --prefer-dist |
|
57 | 74 | coverage: none |
58 | 75 | tools: composer:v2 |
59 | 76 |
|
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 | + |
79 | 78 |
|
80 | 79 | - name: Get current version |
81 | 80 | id: current_version |
|
92 | 91 | # Get current version |
93 | 92 | CURRENT_VERSION=${{ steps.current_version.outputs.version }} |
94 | 93 | |
| 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 | + |
95 | 100 | # Use PHP to increment patch version |
96 | 101 | NEW_VERSION=$(php -r ' |
97 | 102 | $version = "${{ steps.current_version.outputs.version }}"; |
| 103 | + if (!preg_match("/^[0-9]+\.[0-9]+\.[0-9]+$/", $version)) { |
| 104 | + $version = "0.1.0"; |
| 105 | + } |
98 | 106 | list($major, $minor, $patch) = explode(".", $version); |
99 | 107 | $patch++; |
100 | 108 | echo "$major.$minor.$patch"; |
@@ -126,6 +134,10 @@ jobs: |
126 | 134 |
|
127 | 135 | - name: Publish to Packagist |
128 | 136 | run: | |
| 137 | + # Debug info |
| 138 | + echo "Publishing version ${{ steps.bump_version.outputs.new_version }} to Packagist" |
| 139 | + echo "Repository: lingodotdev/sdk" |
| 140 | + |
129 | 141 | # Use our custom script for reliable Packagist publishing |
130 | 142 | export PACKAGIST_USERNAME=lingodotdev |
131 | 143 | export PACKAGIST_API_TOKEN=${{ secrets.PACKAGIST_API_TOKEN }} |
|
0 commit comments