@@ -29,22 +29,49 @@ execute_curl_with_retry() {
29
29
" PUT" )
30
30
curl_cmd=" $curl_cmd --upload-file \" $upload_file \" \" $url \" "
31
31
;;
32
+ " POST" )
33
+ curl_cmd=" $curl_cmd --data-binary @\" $upload_file \" \" $url \" "
34
+ ;;
32
35
" HEAD" )
33
36
curl_cmd=" $curl_cmd -I \" $url \" "
34
37
;;
35
38
esac
36
39
37
40
echo " Executing: $curl_cmd "
38
- if eval $curl_cmd ; then
39
- local http_code=$( curl -s -o /dev/null -w " %{http_code}" -u " ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} " " $url " )
41
+ # For PUT/POST requests, modify the command to capture HTTP code
42
+ if [ " $method " = " PUT" ]; then
43
+ local put_cmd=" curl -s -u \" ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} \" --upload-file \" $upload_file \" -w '%{http_code}' -o /dev/null \" $url \" "
44
+ echo " PUT command: $put_cmd "
45
+ local http_code=$( eval " $put_cmd " )
46
+ if [[ " $http_code " =~ ^[23] ]]; then
47
+ echo " Request successful (HTTP $http_code )"
48
+ return 0
49
+ else
50
+ echo " Request failed with HTTP code: $http_code "
51
+ fi
52
+ elif [ " $method " = " POST" ]; then
53
+ local post_cmd=" curl -s -u \" ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} \" --data-binary @\" $upload_file \" -w '%{http_code}' -o /dev/null \" $url \" "
54
+ echo " POST command: $post_cmd "
55
+ local http_code=$( eval " $post_cmd " )
40
56
if [[ " $http_code " =~ ^[23] ]]; then
41
57
echo " Request successful (HTTP $http_code )"
42
58
return 0
43
59
else
44
60
echo " Request failed with HTTP code: $http_code "
45
61
fi
46
62
else
47
- echo " Curl command failed"
63
+ # For GET/HEAD requests, use the original logic
64
+ if eval " $curl_cmd " ; then
65
+ local http_code=$( curl -s -o /dev/null -w " %{http_code}" -u " ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} " " $url " )
66
+ if [[ " $http_code " =~ ^[23] ]]; then
67
+ echo " Request successful (HTTP $http_code )"
68
+ return 0
69
+ else
70
+ echo " Request failed with HTTP code: $http_code "
71
+ fi
72
+ else
73
+ echo " Curl command failed"
74
+ fi
48
75
fi
49
76
50
77
retry_count=$(( retry_count + 1 ))
@@ -155,14 +182,36 @@ update_commit_mapping_for_project() {
155
182
local commit_map_filename=" commit-history-${project} .json"
156
183
MAPPING_FILE=" ${MAPPING_DIR} /${commit_map_filename} "
157
184
158
- # Define the URL for the mapping file in the artifact directory
159
- MAPPING_URL=" ${snapshot_repo_url} org/opensearch/${project} /${commit_map_filename} "
185
+ # Define the URL for the mapping file in the version directory where it was deployed
186
+ # First try to find the actual version that was deployed
187
+ local deployed_version=" ${ACTUAL_VERSIONS[$project]} "
188
+ if [ -n " $deployed_version " ]; then
189
+ # Extract just the version part (e.g., "1.0.0-SNAPSHOT" from "1.0.0-20250819.224915-2")
190
+ local base_version=$( echo " $deployed_version " | sed ' s/-[0-9]*\.[0-9]*-[0-9]*$//' )
191
+ MAPPING_URL=" ${snapshot_repo_url} org/opensearch/${project} /${base_version} /${commit_map_filename} "
192
+ echo " Using version-specific URL: ${MAPPING_URL} "
193
+ else
194
+ # Fallback to current version
195
+ MAPPING_URL=" ${snapshot_repo_url} org/opensearch/${project} /${current_version} /${commit_map_filename} "
196
+ echo " Using fallback URL with current version: ${MAPPING_URL} "
197
+ fi
160
198
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} "
199
+ # Check if the mapping file exists first
200
+ local file_exists=false
201
+ echo " Checking if commit history file exists at ${MAPPING_URL} "
202
+ local http_code=$( curl -s -o /dev/null -w " %{http_code}" -u " ${SONATYPE_USERNAME} :${SONATYPE_PASSWORD} " " $MAPPING_URL " )
203
+
204
+ if [[ " $http_code " == " 200" ]]; then
205
+ file_exists=true
206
+ echo " Commit history file exists, downloading..."
207
+ if execute_curl_with_retry " $MAPPING_URL " " GET" " $MAPPING_FILE " ; then
208
+ echo " Downloaded existing commit history file for ${project} "
209
+ else
210
+ echo " Failed to download existing file, creating new one"
211
+ echo ' {"mappings":[]}' > " ${MAPPING_FILE} "
212
+ fi
164
213
else
165
- echo " No existing commit history file found for ${project} , creating new one"
214
+ echo " Commit history file does not exist (HTTP ${http_code} ) , creating new one"
166
215
echo ' {"mappings":[]}' > " ${MAPPING_FILE} "
167
216
fi
168
217
@@ -210,11 +259,24 @@ update_commit_mapping_for_project() {
210
259
211
260
# Upload the mapping file
212
261
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} "
262
+ if [ " $file_exists " = true ]; then
263
+ echo " Updating existing commit history file..."
264
+ if execute_curl_with_retry " $MAPPING_URL " " PUT" " " " $MAPPING_FILE " ; then
265
+ echo " Successfully uploaded commit history file for ${project} "
266
+ else
267
+ echo " Failed to upload commit history file for ${project} "
268
+ exit 1
269
+ fi
215
270
else
216
- echo " Failed to upload commit history file for ${project} "
217
- exit 1
271
+ echo " Creating new commit history file..."
272
+ # Try to upload as a new file - this will work if we have the right permissions
273
+ # or if Maven Central allows file creation in this context
274
+ if execute_curl_with_retry " $MAPPING_URL " " POST" " " " $MAPPING_FILE " ; then
275
+ echo " Successfully created and uploaded commit history file for ${project} "
276
+ else
277
+ echo " Failed to create commit history file for ${project} - continuing anyway"
278
+ echo " The file will be created in the next successful run"
279
+ fi
218
280
fi
219
281
220
282
# Clean up
@@ -226,12 +288,14 @@ publish_snapshots_and_update_metadata() {
226
288
local current_version=" $1 "
227
289
local commit_id=" $2 "
228
290
229
- # Get credentials to upload files directly
230
- export SONATYPE_USERNAME=$( aws secretsmanager get-secret-value --secret-id maven-snapshots-username --query SecretString --output text)
231
- export SONATYPE_PASSWORD=$( aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text)
291
+ # Flag to control commit history file creation (disabled due to Maven Central restrictions)
292
+ local ENABLE_COMMIT_HISTORY=false
293
+
294
+ # Credentials are already loaded from 1Password via environment variables
295
+ # SONATYPE_USERNAME and SONATYPE_PASSWORD are set by the GitHub Actions workflow
232
296
echo " ::add-mask::$SONATYPE_USERNAME "
233
297
echo " ::add-mask::$SONATYPE_PASSWORD "
234
- export SNAPSHOT_REPO_URL=" https://aws.oss. sonatype.org/content/repositories/ snapshots/"
298
+ export SNAPSHOT_REPO_URL=" https://central. sonatype.com/repository/maven- snapshots/"
235
299
236
300
# Make a temp directory for publish-snapshot.sh
237
301
mkdir -p build/resources/publish/
@@ -240,7 +304,57 @@ publish_snapshots_and_update_metadata() {
240
304
241
305
# Continue with the original flow
242
306
cd build/resources/publish/
243
- cp -a $HOME /.m2/repository/* ./
307
+ cp -a " $HOME " /.m2/repository/* ./
308
+
309
+ if [ " $ENABLE_COMMIT_HISTORY " = true ]; then
310
+ # Pre-create commit history files in the artifact structure for initial upload
311
+ # These files need to be at the project root level, not in version directories
312
+ echo " Looking for project directories to create commit history files..."
313
+ ls -la org/opensearch/ || echo " org/opensearch directory not found"
314
+
315
+ for PROJECT in " opensearch-spark-standalone_2.12" " opensearch-spark-ppl_2.12" " opensearch-spark-sql-application_2.12" ; do
316
+ PROJECT_DIR=" org/opensearch/${PROJECT} "
317
+ echo " Checking for project directory: ${PROJECT_DIR} "
318
+
319
+ if [ -d " ${PROJECT_DIR} " ]; then
320
+ echo " Found project directory: ${PROJECT_DIR} "
321
+ ls -la " ${PROJECT_DIR} "
322
+
323
+ # Find the version directory that already exists and will be uploaded
324
+ VERSION_DIR=$( find " ${PROJECT_DIR} " -type d -name " *SNAPSHOT*" | head -1)
325
+ if [ -n " ${VERSION_DIR} " ]; then
326
+ COMMIT_HISTORY_FILE=" ${VERSION_DIR} /commit-history-${PROJECT} .json"
327
+ if [ ! -f " ${COMMIT_HISTORY_FILE} " ]; then
328
+ echo " Creating initial commit history file for ${PROJECT} in existing version directory: ${VERSION_DIR} "
329
+ echo ' {"mappings":[],"initialized":"' " $( date -u +" %Y-%m-%dT%H:%M:%SZ" ) " ' ","project":"' " ${PROJECT} " ' "}' > " ${COMMIT_HISTORY_FILE} "
330
+ echo " Created: ${COMMIT_HISTORY_FILE} "
331
+
332
+ # Create checksums for Maven compliance
333
+ sha1sum " ${COMMIT_HISTORY_FILE} " | cut -d" " -f1 > " ${COMMIT_HISTORY_FILE} .sha1"
334
+ md5sum " ${COMMIT_HISTORY_FILE} " | cut -d" " -f1 > " ${COMMIT_HISTORY_FILE} .md5"
335
+ echo " Created checksums for ${COMMIT_HISTORY_FILE} "
336
+
337
+ # Verify the files were created
338
+ ls -la " ${COMMIT_HISTORY_FILE} " *
339
+ else
340
+ echo " Commit history file already exists: ${COMMIT_HISTORY_FILE} "
341
+ fi
342
+ else
343
+ echo " No SNAPSHOT version directory found for ${PROJECT} "
344
+ fi
345
+ else
346
+ echo " Project directory not found: ${PROJECT_DIR} "
347
+ echo " Available directories in org/opensearch/:"
348
+ ls -la org/opensearch/ 2> /dev/null || echo " No org/opensearch directory"
349
+ fi
350
+ done
351
+
352
+ echo " Commit history file creation complete. Contents of org/opensearch/:"
353
+ find org/opensearch/ -name " *.json" 2> /dev/null || echo " No JSON files found"
354
+ else
355
+ echo " Skipping commit history file creation (disabled)"
356
+ fi
357
+
244
358
./publish-snapshot.sh ./
245
359
246
360
echo " Snapshot publishing completed. Now uploading commit ID metadata..."
@@ -263,9 +377,12 @@ publish_snapshots_and_update_metadata() {
263
377
done
264
378
265
379
# Create/update commit ID to version mapping for each project
266
- for PROJECT in " ${PROJECTS[@]} " ; do
267
- update_commit_mapping_for_project " $PROJECT " " $current_version " " $commit_id " " $SNAPSHOT_REPO_URL "
268
- done
269
-
270
- echo " All commit mapping files updated successfully"
380
+ if [ " $ENABLE_COMMIT_HISTORY " = true ]; then
381
+ for PROJECT in " ${PROJECTS[@]} " ; do
382
+ update_commit_mapping_for_project " $PROJECT " " $current_version " " $commit_id " " $SNAPSHOT_REPO_URL "
383
+ done
384
+ echo " All commit mapping files updated successfully"
385
+ else
386
+ echo " Skipping commit mapping file updates (disabled)"
387
+ fi
271
388
}
0 commit comments