@@ -158,11 +158,22 @@ update_commit_mapping_for_project() {
158
158
# Define the URL for the mapping file in the artifact directory
159
159
MAPPING_URL=" ${snapshot_repo_url} org/opensearch/${project} /${commit_map_filename} "
160
160
161
- # Try to download existing mapping file if it exists
162
- if execute_curl_with_retry " $MAPPING_URL " " GET" " $MAPPING_FILE " ; then
163
- echo " Downloaded existing commit history file for ${project} "
161
+ # Check if the mapping file exists first
162
+ local file_exists=false
163
+ echo " Checking if commit history file exists at ${MAPPING_URL} "
164
+ local http_code=$( curl -s -o /dev/null -w " %{http_code}" -u " ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} " " $MAPPING_URL " )
165
+
166
+ if [[ " $http_code " == " 200" ]]; then
167
+ file_exists=true
168
+ echo " Commit history file exists, downloading..."
169
+ if execute_curl_with_retry " $MAPPING_URL " " GET" " $MAPPING_FILE " ; then
170
+ echo " Downloaded existing commit history file for ${project} "
171
+ else
172
+ echo " Failed to download existing file, creating new one"
173
+ echo ' {"mappings":[]}' > " ${MAPPING_FILE} "
174
+ fi
164
175
else
165
- echo " No existing commit history file found for ${project} , creating new one"
176
+ echo " Commit history file does not exist (HTTP ${http_code} ) , creating new one"
166
177
echo ' {"mappings":[]}' > " ${MAPPING_FILE} "
167
178
fi
168
179
@@ -210,11 +221,24 @@ update_commit_mapping_for_project() {
210
221
211
222
# Upload the mapping file
212
223
echo " Uploading commit history file to ${MAPPING_URL} "
213
- if execute_curl_with_retry " $MAPPING_URL " " PUT" " " " $MAPPING_FILE " ; then
214
- echo " Successfully uploaded commit history file for ${project} "
224
+ if [ " $file_exists " = true ]; then
225
+ echo " Updating existing commit history file..."
226
+ if execute_curl_with_retry " $MAPPING_URL " " PUT" " " " $MAPPING_FILE " ; then
227
+ echo " Successfully uploaded commit history file for ${project} "
228
+ else
229
+ echo " Failed to upload commit history file for ${project} "
230
+ exit 1
231
+ fi
215
232
else
216
- echo " Failed to upload commit history file for ${project} "
217
- exit 1
233
+ echo " Creating new commit history file..."
234
+ # Try to upload as a new file - this will work if we have the right permissions
235
+ # or if Maven Central allows file creation in this context
236
+ if execute_curl_with_retry " $MAPPING_URL " " PUT" " " " $MAPPING_FILE " ; then
237
+ echo " Successfully created and uploaded commit history file for ${project} "
238
+ else
239
+ echo " Failed to create commit history file for ${project} - continuing anyway"
240
+ echo " The file will be created in the next successful run"
241
+ fi
218
242
fi
219
243
220
244
# Clean up
@@ -239,7 +263,7 @@ publish_snapshots_and_update_metadata() {
239
263
240
264
# Continue with the original flow
241
265
cd build/resources/publish/
242
- cp -a $HOME /.m2/repository/* ./
266
+ cp -a " $HOME " /.m2/repository/* ./
243
267
./publish-snapshot.sh ./
244
268
245
269
echo " Snapshot publishing completed. Now uploading commit ID metadata..."
0 commit comments