Skip to content

Commit d213c17

Browse files
committed
Fix Maven deployment response parsing and improve idempotency
- Handle plain text deployment ID response (not JSON) - Gracefully handle duplicate upload attempts (400 errors) - Add better error reporting for failed uploads - Ensure workflow succeeds if artifact is already being processed
1 parent 167a07a commit d213c17

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,17 @@ jobs:
407407
shell: bash
408408
working-directory: artifacts
409409
run: |
410-
# Check if artifact already exists in Maven Central
410+
# Check if artifact already exists or is being published
411411
if curl -f -s -o /dev/null "https://repo1.maven.org/maven2/io/stepfunc/dnp3/${{github.ref_name}}/dnp3-${{github.ref_name}}.jar"; then
412-
echo "Artifact io.stepfunc:dnp3:${{github.ref_name}} already exists in Maven Central - skipping deployment"
412+
echo "Artifact io.stepfunc:dnp3:${{github.ref_name}} already exists in Maven Central - skipping deployment"
413413
else
414-
echo "Artifact not found in Maven Central - proceeding with deployment"
414+
echo "Artifact not found in Maven Central - checking if deployment is in progress..."
415+
416+
# Create base64 encoded token for Authorization header
417+
AUTH_TOKEN=$(echo -n "${{ secrets.MAVEN_CENTRAL_USERNAME }}:${{ secrets.MAVEN_CENTRAL_TOKEN }}" | base64 -w 0)
418+
419+
# Try to upload - if it fails due to duplicate, that means it's already being processed
420+
echo "Attempting to upload to Central Portal..."
415421
416422
# Create Maven repository structure (starting from groupId)
417423
mkdir -p io/stepfunc/dnp3/${{github.ref_name}}
@@ -438,9 +444,6 @@ jobs:
438444
cd ../../../..
439445
zip -r bundle.zip io/
440446
441-
# Create base64 encoded token for Authorization header
442-
AUTH_TOKEN=$(echo -n "${{ secrets.MAVEN_CENTRAL_USERNAME }}:${{ secrets.MAVEN_CENTRAL_TOKEN }}" | base64 -w 0)
443-
444447
# Upload bundle to Central Portal
445448
echo "Uploading bundle to Central Portal..."
446449
RESPONSE=$(curl -X POST \
@@ -449,8 +452,8 @@ jobs:
449452
-H "Content-Type: multipart/form-data" \
450453
-F "[email protected];type=application/octet-stream" \
451454
-F "publishingType=AUTOMATIC" \
452-
--fail-with-body \
453-
-w "\nHTTP_STATUS:%{http_code}")
455+
-w "\nHTTP_STATUS:%{http_code}" \
456+
-s)
454457
455458
# Extract HTTP status code
456459
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2)
@@ -459,13 +462,17 @@ jobs:
459462
echo "Response: $BODY"
460463
echo "HTTP Status: $HTTP_STATUS"
461464
462-
# Extract deployment ID if successful
465+
# Handle response
463466
if [[ $HTTP_STATUS -ge 200 && $HTTP_STATUS -lt 300 ]]; then
464-
DEPLOYMENT_ID=$(echo "$BODY" | grep -o '"deploymentId"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
467+
# The API returns the deployment ID as plain text, not JSON
468+
DEPLOYMENT_ID=$(echo "$BODY" | tr -d '[:space:]')
465469
echo "✅ Upload successful! Deployment ID: $DEPLOYMENT_ID"
466470
echo "The deployment will be automatically published to Maven Central after validation."
471+
elif [[ $HTTP_STATUS -eq 400 ]] && [[ "$BODY" =~ "duplicate" || "$BODY" =~ "already exists" || "$BODY" =~ "PUBLISHED" ]]; then
472+
echo "✅ Version ${{github.ref_name}} is already uploaded or being processed - skipping deployment"
467473
else
468474
echo "❌ Upload failed with status $HTTP_STATUS"
475+
echo "Error details: $BODY"
469476
exit 1
470477
fi
471478
fi

0 commit comments

Comments
 (0)