Skip to content
Prev Previous commit
Next Next commit
also publish it
  • Loading branch information
TingDaoK committed May 30, 2025
commit fa6e56a8bcb281c20fa81e6e45d94976157e0a7c
22 changes: 13 additions & 9 deletions codebuild/cd/publish-bundle.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/bin/sh

set -ex
set -euo pipefail

# Send all diagnostic output to stderr
exec 3>&1 # Save stdout
exec 1>&2 # Redirect stdout to stderr for messages

# Configuration
BUNDLE_FILE="bundle.zip"
SONATYPE_API_URL="https://central.sonatype.com/api/v1/publisher/upload"
SONATYPE_API_UPLOAD_URL="https://central.sonatype.com/api/v1/publisher/upload"

# Validate prerequisites
if [ -z "${AUTH_HEADER_VAL:-}" ]; then
Expand All @@ -23,20 +20,27 @@ fi

echo "Uploading bundle to Sonatype Central..."

# Upload bundle (verbose output goes to stderr)
# Upload bundle
DEPLOY_ID=$(curl \
--fail \
--verbose \
--show-error \
--request POST \
--header "Authorization: Bearer ${AUTH_HEADER_VAL}" \
--form "bundle=@${BUNDLE_FILE}" \
"${SONATYPE_API_URL}" 2>&1) || {
"${SONATYPE_API_UPLOAD_URL}" 2>&1) || {
echo "Error: Failed to upload bundle to Sonatype Central"
exit 1
}

echo "Successfully uploaded. Deployment ID: ${DEPLOY_ID}"

# Output only the DEPLOY_ID to original stdout for the caller
echo "${DEPLOY_ID}" | tee /tmp/deploy-id.txt
SONATYPE_API_PUBLISH_URL="https://central.sonatype.com/api/v1/publisher/deployment/${DEPLOY_ID}"

# Publish the uploaded bundle
curl \
--fail \
--verbose \
--request POST \
--header "Authorization: Bearer ${AUTH_HEADER_VAL}" \
"${SONATYPE_API_URL}"
Loading