-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-lib.sh
executable file
·170 lines (135 loc) · 4.42 KB
/
build-lib.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
echo "Checking environment variables:"
if [ -z "$SONATYPE_TOKEN" ]; then
echo "ERROR: SONATYPE_TOKEN is not set!"
fi
echo "Library generation process initiated."
echo "Generating artifacts for React Native Gradle Plugin."
cd ..
cd node_modules/@react-native/gradle-plugin
./gradlew build
./gradlew publish
# echo "Applying LibraryCreation Patch."
# Navigate to the Android folder and apply the patch
cd ../../../android
# cd ../../../hyperswitch-sdk-android
# git apply libraryCreation.patch
cd hyperswitch-gradle-plugin
./gradlew build
./gradlew publish
cd ..
echo "Generating artifacts for Hyperswitch Android SDK."
# ./gradlew clean
./gradlew assembleRelease
./gradlew publish
cd maven/io/hyperswitch || exit 1
export GPG_TTY=$(tty)
echo "RELOADAGENT" | gpg-connect-agent
# Function to sign files and create a bundle
process_version_directory() {
local base_dir="$1"
local version_dir="$2"
cd "$version_dir" || return
for file in *.{aar,pom,jar,module}; do
[ -e "$file" ] || continue
echo "Signing $file..."
# gpg --armor --output "${file}.asc" --detach-sign "$file"
gpg --batch --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" --armor --output "${file}.asc" --detach-sign "$file"
done
cd ..
}
upload_to_sonatype() {
local zip_file="$1"
local sonatype_url="https://central.sonatype.com/api/v1/publisher/upload"
local authorization_token="Bearer $SONATYPE_TOKEN"
echo "Uploading $zip_file to Sonatype Central..."
curl --request POST \
--verbose \
--header "Authorization: $authorization_token" \
--form bundle=@"$zip_file" \
$sonatype_url
}
# Get list of available libraries
echo "Discovering available libraries..."
available_libraries=()
index=1
echo "Available libraries:"
for library_dir in */; do
if [ -d "$library_dir" ]; then
library_name=${library_dir%/}
available_libraries+=("$library_name")
echo "$index) $library_name"
((index++))
fi
done
# Get user selection
selected_libraries=()
# Check if SELECTED_LIBRARIES environment variable is set (for CI)
if [ ! -z "$SELECTED_LIBRARIES" ]; then
echo "Using libraries from SELECTED_LIBRARIES environment variable"
IFS=',' read -ra selected_libraries <<< "$SELECTED_LIBRARIES"
else
# Interactive mode
echo "Interactive Mode, Available libraries:"
index=1
for library in "${available_libraries[@]}"; do
echo "$index) $library"
((index++))
done
echo "Enter the numbers of the libraries you want to include (space-separated)"
echo "Example: 1 3 4"
read -r selections
# Convert selections to array
read -ra selection_array <<< "$selections"
# Validate and process selections
for selection in "${selection_array[@]}"; do
if [[ "$selection" =~ ^[0-9]+$ ]] && ((selection > 0 && selection <= ${#available_libraries[@]})); then
selected_libraries+=("${available_libraries[$selection-1]}")
echo "Selected: ${available_libraries[$selection-1]}"
else
echo "Invalid selection: $selection"
fi
done
fi
# Validate selected libraries
valid_libraries=()
for library in "${selected_libraries[@]}"; do
if [[ " ${available_libraries[@]} " =~ " ${library} " ]]; then
valid_libraries+=("$library")
else
echo "Warning: Library '$library' not found, skipping"
fi
done
if [ ${#valid_libraries[@]} -eq 0 ]; then
echo "No valid libraries selected. Exiting."
exit 1
fi
echo "Processing selected libraries: ${selected_libraries[*]}"
for library in "${selected_libraries[@]}"; do
echo "Processing library: $library"
cd "$library" || continue
# Process each version directory
for version_dir in */; do
[ -d "$version_dir" ] || continue
process_version_directory "$library" "$version_dir"
done
cd ..
done
# Create temporary directory for selected libraries
temp_dir=$(mktemp -d)
mkdir -p "$temp_dir/io/hyperswitch"
# Copy only selected libraries
for library in "${selected_libraries[@]}"; do
echo "Copying library: $library"
cp -r "$library" "$temp_dir/io/hyperswitch/"
done
# Create the ZIP bundle
cd "$temp_dir"
zip_name="hyperswitch-sdk-bundle.zip"
echo "Creating ZIP bundle for $zip_name..."
zip -r "$zip_name" io/hyperswitch
upload_to_sonatype "hyperswitch-sdk-bundle.zip"
# cp "$zip_name" ../../
cd ../../
rm -rf "$temp_dir"
echo "Processing completed."