-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·67 lines (53 loc) · 2.01 KB
/
deploy.sh
File metadata and controls
executable file
·67 lines (53 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Configuration
VERSION="1.0.3"
ARTIFACT_ID="rasedi-java-sdk"
BUNDLE_NAME="${ARTIFACT_ID}-${VERSION}-bundle.zip"
STAGING_DIR="build/repo"
# Load credentials from gradle.properties
USERNAME=$(grep "ossrhUsername" gradle.properties | cut -d'=' -f2)
PASSWORD=$(grep "ossrhPassword" gradle.properties | cut -d'=' -f2)
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
echo "Error: ossrhUsername or ossrhPassword not found in gradle.properties"
exit 1
fi
# Encode credentials for Central Portal (Token format)
AUTH=$(echo -n "$USERNAME:$PASSWORD" | base64 | tr -d '\n')
echo "--- Step 1: Building and Preparing Artifacts ---"
./gradlew clean publishMavenJavaPublicationToStagingRepository
if [ $? -ne 0 ]; then
echo "Build failed."
exit 1
fi
echo "--- Step 2: Creating Bundle (ZIP) ---"
if [ ! -d "$STAGING_DIR" ]; then
echo "Error: Staging directory $STAGING_DIR not found."
exit 1
fi
# Zip the contents of the staging directory
# Note: Sonatype Central Portal expects the directory structure inside the zip
cd "$STAGING_DIR" || exit
rm -f "../../$BUNDLE_NAME"
zip -r "../../$BUNDLE_NAME" .
cd - > /dev/null
echo "Bundle created: $BUNDLE_NAME"
echo "--- Step 3: Uploading to Sonatype Central Portal ---"
# URL for Central Portal V1 API
UPLOAD_URL="https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC"
RESPONSE=$(curl -s -w "\n%{http_code}" --request POST \
--url "$UPLOAD_URL" \
--header "Authorization: Bearer $AUTH" \
--form "bundle=@$BUNDLE_NAME")
HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1)
BODY=$(echo "$RESPONSE" | sed '$d')
echo "-----------------------------------------------"
echo "Response Body: $BODY"
echo "HTTP Status: $HTTP_STATUS"
echo "-----------------------------------------------"
if [ "$HTTP_STATUS" -eq 201 ] || [ "$HTTP_STATUS" -eq 200 ]; then
echo "SUCCESS: Bundle uploaded successfully!"
echo "Check your deployment at: https://central.sonatype.com/publishing/deployments"
else
echo "ERROR: Upload failed with status $HTTP_STATUS"
exit 1
fi