Skip to content

Commit

Permalink
Merge branch 'master' into 25w04a
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Jan 22, 2025
2 parents 7f673da + 906c836 commit 39fcdbb
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,48 @@ task uploadBackups {
def shortVersion = getGhVersion().substring(1)
def backupUrl = "https://api.wurstclient.net/artifact-backups/Mo-Glass/${shortVersion}"

def connection = new URL(backupUrl).openConnection() as HttpURLConnection
def boundary = UUID.randomUUID().toString()
connection.setRequestMethod("POST")
connection.setRequestProperty("X-API-Key", ENV.WI_BACKUPS_API_KEY)
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
connection.doOutput = true
def maxRetries = 3
def retryCount = 0
def success = false

def output = connection.outputStream
[remapJar, remapSourcesJar].each { jarTask ->
def file = jarTask.archiveFile.get().asFile
output << "--${boundary}\r\n"
output << "Content-Disposition: form-data; name=\"files\"; filename=\"${file.name}\"\r\n"
output << "Content-Type: application/java-archive\r\n\r\n"
file.withInputStream { input ->
output << input
while (!success && retryCount < maxRetries) {
try {
def connection = new URL(backupUrl).openConnection() as HttpURLConnection
def boundary = UUID.randomUUID().toString()
connection.setRequestMethod("POST")
connection.setRequestProperty("X-API-Key", ENV.WI_BACKUPS_API_KEY)
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
connection.doOutput = true

def output = connection.outputStream
[remapJar, remapSourcesJar].each { jarTask ->
def file = jarTask.archiveFile.get().asFile
output << "--${boundary}\r\n"
output << "Content-Disposition: form-data; name=\"files\"; filename=\"${file.name}\"\r\n"
output << "Content-Type: application/java-archive\r\n\r\n"
file.withInputStream { input ->
output << input
}
output << "\r\n"
}
output << "--${boundary}--\r\n"
output.flush()

if(connection.responseCode != 200) {
throw new IOException("HTTP ${connection.responseCode}: ${connection.responseMessage}")
}

success = true

} catch (Exception e) {
retryCount++
if (retryCount >= maxRetries) {
throw new GradleException("Failed to upload backups after ${maxRetries} attempts: ${e.message}")
}
println "Upload attempt ${retryCount} failed: ${e.message}. Retrying in 5 seconds..."
Thread.sleep(5000)
}
output << "\r\n"
}
output << "--${boundary}--\r\n"
output.flush()

if(connection.responseCode != 200)
throw new GradleException("Failed to upload backups: ${connection.responseCode} ${connection.responseMessage}")
}
}

0 comments on commit 39fcdbb

Please sign in to comment.