Skip to content

Commit d74f30c

Browse files
Replace uploadBackups Gradle task with GitHub Action
1 parent ac7e8f0 commit d74f30c

File tree

2 files changed

+14
-68
lines changed

2 files changed

+14
-68
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,29 @@ jobs:
8282
GITHUB_TOKEN: ${{ github.token }}
8383
run: ./gradlew closeMilestone --stacktrace --no-configuration-cache
8484

85+
- name: Build website update inputs
86+
id: website_inputs
87+
if: ${{ inputs.update_website }}
88+
run: |
89+
echo "wurst_version=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r' | sed 's/^v//' | sed 's/-MC.*$//')" >> "$GITHUB_OUTPUT"
90+
echo "mc_version=$(grep '^minecraft_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
91+
echo "fapi_version=$(grep '^fabric_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
92+
8593
- name: Upload backups
8694
if: ${{ inputs.upload_backups }}
87-
env:
88-
WI_BACKUPS_API_KEY: ${{ secrets.WI_BACKUPS_API_KEY }}
89-
run: ./gradlew uploadBackups --stacktrace --no-configuration-cache
95+
uses: Wurst-Imperium/upload-backups@v1
96+
with:
97+
api_key: ${{ secrets.WI_BACKUPS_API_KEY }}
98+
project: Wurst
99+
version: ${{ steps.website_inputs.outputs.wurst_version }}
100+
path: build/libs/*.jar
90101

91102
- name: Publish to GitHub
92103
if: ${{ inputs.publish_github }}
93104
env:
94105
GITHUB_TOKEN: ${{ secrets.OLD_MCX_PUBLISH_TOKEN }}
95106
run: ./gradlew github --stacktrace --no-configuration-cache
96107

97-
- name: Build website update inputs
98-
id: website_inputs
99-
if: ${{ inputs.update_website }}
100-
run: |
101-
echo "wurst_version=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r' | sed 's/^v//' | sed 's/-MC.*$//')" >> "$GITHUB_OUTPUT"
102-
echo "mc_version=$(grep '^minecraft_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
103-
echo "fapi_version=$(grep '^fabric_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
104-
105108
- name: Trigger website update
106109
if: ${{ inputs.update_website }}
107110
uses: Wurst-Imperium/dispatch-and-wait@v1

build.gradle

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -247,60 +247,3 @@ task closeMilestone {
247247
}
248248
}
249249
}
250-
251-
task uploadBackups {
252-
dependsOn build
253-
254-
onlyIf {
255-
ENV.WI_BACKUPS_API_KEY
256-
}
257-
258-
doLast {
259-
def shortVersion = getGhVersion().substring(1)
260-
def backupUrl = "https://api.wurstclient.net/artifact-backups/Wurst/${shortVersion}"
261-
262-
def maxRetries = 3
263-
def retryCount = 0
264-
def success = false
265-
266-
while (!success && retryCount < maxRetries) {
267-
try {
268-
def connection = new URL(backupUrl).openConnection() as HttpURLConnection
269-
def boundary = UUID.randomUUID().toString()
270-
connection.setRequestMethod("POST")
271-
connection.setRequestProperty("X-API-Key", ENV.WI_BACKUPS_API_KEY)
272-
connection.setRequestProperty("Accept", "application/json")
273-
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
274-
connection.doOutput = true
275-
276-
def output = connection.outputStream
277-
[remapJar, remapSourcesJar].each { jarTask ->
278-
def file = jarTask.archiveFile.get().asFile
279-
output << "--${boundary}\r\n"
280-
output << "Content-Disposition: form-data; name=\"files\"; filename=\"${file.name}\"\r\n"
281-
output << "Content-Type: application/java-archive\r\n\r\n"
282-
file.withInputStream { input ->
283-
output << input
284-
}
285-
output << "\r\n"
286-
}
287-
output << "--${boundary}--\r\n"
288-
output.flush()
289-
290-
if(connection.responseCode != 200) {
291-
throw new IOException("HTTP ${connection.responseCode}: ${connection.responseMessage}")
292-
}
293-
294-
success = true
295-
296-
} catch (Exception e) {
297-
retryCount++
298-
if (retryCount >= maxRetries) {
299-
throw new GradleException("Failed to upload backups after ${maxRetries} attempts: ${e.message}")
300-
}
301-
println "Upload attempt ${retryCount} failed: ${e.message}. Retrying in 5 seconds..."
302-
Thread.sleep(5000)
303-
}
304-
}
305-
}
306-
}

0 commit comments

Comments
 (0)