Skip to content

Commit cafb1c0

Browse files
Replace uploadBackups Gradle task with GitHub Action
1 parent e6db182 commit cafb1c0

2 files changed

Lines changed: 14 additions & 68 deletions

File tree

.github/workflows/publish.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,22 @@ jobs:
8787
GITHUB_TOKEN: ${{ github.token }}
8888
run: ./gradlew closeMilestone --stacktrace --no-configuration-cache --warning-mode all
8989

90+
- name: Build website update inputs
91+
id: website_inputs
92+
if: ${{ inputs.update_website }}
93+
run: |
94+
echo "mod_version=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r' | sed 's/-MC.*$//')" >> "$GITHUB_OUTPUT"
95+
echo "mc_version=$(grep '^minecraft_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
96+
echo "fapi_version=$(grep '^fabric_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
97+
9098
- name: Upload backups
9199
if: ${{ inputs.upload_backups }}
92-
env:
93-
WI_BACKUPS_API_KEY: ${{ secrets.WI_BACKUPS_API_KEY }}
94-
run: ./gradlew uploadBackups --stacktrace --no-configuration-cache --warning-mode all
100+
uses: Wurst-Imperium/upload-backups@v1
101+
with:
102+
api_key: ${{ secrets.WI_BACKUPS_API_KEY }}
103+
project: ChestESP
104+
version: ${{ steps.website_inputs.outputs.mod_version }}
105+
path: build/libs/*.jar
95106

96107
- name: Publish to GitHub
97108
if: ${{ inputs.publish_github }}
@@ -113,14 +124,6 @@ jobs:
113124
echo "file_id=$file_id" >> "$GITHUB_OUTPUT"
114125
echo "CurseForge file ID: \`$file_id\`" >> $GITHUB_STEP_SUMMARY
115126
116-
- name: Build website update inputs
117-
id: website_inputs
118-
if: ${{ inputs.update_website }}
119-
run: |
120-
echo "mod_version=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r' | sed 's/-MC.*$//')" >> "$GITHUB_OUTPUT"
121-
echo "mc_version=$(grep '^minecraft_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
122-
echo "fapi_version=$(grep '^fabric_version=' gradle.properties | cut -d'=' -f2 | tr -d ' \r')" >> "$GITHUB_OUTPUT"
123-
124127
- name: Trigger website update
125128
if: ${{ inputs.update_website }}
126129
uses: Wurst-Imperium/dispatch-and-wait@v1

build.gradle

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -315,60 +315,3 @@ task closeMilestone {
315315
}
316316
}
317317
}
318-
319-
task uploadBackups {
320-
dependsOn build
321-
322-
onlyIf {
323-
ENV.WI_BACKUPS_API_KEY
324-
}
325-
326-
doLast {
327-
def shortVersion = getGhVersion().substring(1)
328-
def backupUrl = "https://api.wurstclient.net/artifact-backups/ChestESP/${shortVersion}"
329-
330-
def maxRetries = 3
331-
def retryCount = 0
332-
def success = false
333-
334-
while (!success && retryCount < maxRetries) {
335-
try {
336-
def connection = new URL(backupUrl).openConnection() as HttpURLConnection
337-
def boundary = UUID.randomUUID().toString()
338-
connection.setRequestMethod("POST")
339-
connection.setRequestProperty("X-API-Key", ENV.WI_BACKUPS_API_KEY)
340-
connection.setRequestProperty("Accept", "application/json")
341-
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
342-
connection.doOutput = true
343-
344-
def output = connection.outputStream
345-
[remapJar, remapSourcesJar].each { jarTask ->
346-
def file = jarTask.archiveFile.get().asFile
347-
output << "--${boundary}\r\n"
348-
output << "Content-Disposition: form-data; name=\"files\"; filename=\"${file.name}\"\r\n"
349-
output << "Content-Type: application/java-archive\r\n\r\n"
350-
file.withInputStream { input ->
351-
output << input
352-
}
353-
output << "\r\n"
354-
}
355-
output << "--${boundary}--\r\n"
356-
output.flush()
357-
358-
if(connection.responseCode != 200) {
359-
throw new IOException("HTTP ${connection.responseCode}: ${connection.responseMessage}")
360-
}
361-
362-
success = true
363-
364-
} catch (Exception e) {
365-
retryCount++
366-
if (retryCount >= maxRetries) {
367-
throw new GradleException("Failed to upload backups after ${maxRetries} attempts: ${e.message}")
368-
}
369-
println "Upload attempt ${retryCount} failed: ${e.message}. Retrying in 5 seconds..."
370-
Thread.sleep(5000)
371-
}
372-
}
373-
}
374-
}

0 commit comments

Comments
 (0)