Skip to content

Commit 9ad936c

Browse files
authored
create inital mapping file (#1260)
Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent a210187 commit 9ad936c

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

.github/publish-utils.sh

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,22 @@ update_commit_mapping_for_project() {
158158
# Define the URL for the mapping file in the artifact directory
159159
MAPPING_URL="${snapshot_repo_url}org/opensearch/${project}/${commit_map_filename}"
160160

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
164175
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"
166177
echo '{"mappings":[]}' > "${MAPPING_FILE}"
167178
fi
168179

@@ -210,11 +221,24 @@ update_commit_mapping_for_project() {
210221

211222
# Upload the mapping file
212223
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
215232
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
218242
fi
219243

220244
# Clean up
@@ -239,7 +263,7 @@ publish_snapshots_and_update_metadata() {
239263

240264
# Continue with the original flow
241265
cd build/resources/publish/
242-
cp -a $HOME/.m2/repository/* ./
266+
cp -a "$HOME"/.m2/repository/* ./
243267
./publish-snapshot.sh ./
244268

245269
echo "Snapshot publishing completed. Now uploading commit ID metadata..."

0 commit comments

Comments
 (0)