Advanced-Portals/discord.gradle

55 lines
1.9 KiB
Groovy

import org.apache.http.HttpEntity
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.apache.httpcomponents:httpmime:4.5.13"
}
}
apply from: 'env-variables.gradle'
/** For pre-releases and testers to be able to try the latest commits if they want.
* If the builds start exceeding 8MB then we may want to upload to s3 instead and periodically clear.
* TODO possibly add a task that announces when builds are made?
* Though add a note that it may take a while for Curse to approve the files.
*/
task discordupload {
dependsOn(jar)
doLast {
String discordWebhook = System.getenv("DISCORD_WEBHOOK")
if(discordWebhook != null) {
println("Logging Into Discord")
CloseableHttpClient httpClient = HttpClients.createDefault()
HttpPost uploadFile = new HttpPost(discordWebhook)
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
builder.addTextBody("content", "New automated dev build\n\n" +
"Current Features: <${project.github}/blob/${ext.githubSha}/docs/changelogs/SNAPSHOT_CHANGELOG.md>")
builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName)
HttpEntity multipart = builder.build()
uploadFile.setEntity(multipart)
CloseableHttpResponse response = httpClient.execute(uploadFile)
response.getEntity()
println("Posted build")
} else {
println("Discord webhook unspecified ${sha}")
}
}
}